mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 02:24:12 +01:00
Review r2: "stage budgets + one stalled collective" only holds where a cooperative deadline is checked. PROBE's DISTILL tail, surgery's post-EXCISE restoration and VERIFY's rollback run unchecked. Restore the pre-PR process-group timeouts (VERIFY 4 s; PROBE, surgery and model 5 s). The observed flake was the 5 s EXCISE stage budget, and the original collective limits held under the same load. Each reaper is now checked stage budgets + (collectives outside stage clocks + each unchecked interval + each stage's longest overshoot interval) x collective timeout + one stalled collective + exit. Counts are named constants with production source pointers: model 45 s, PROBE 520 s, surgery 695 s, VERIFY 914 s, VERIFY rank-exit setup 638 s. The short oracles are unchanged from r2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
633 lines
26 KiB
Python
633 lines
26 KiB
Python
"""Two-rank CPU/Gloo semantic and failure oracle for the experimental TP2 stack (#244)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import multiprocessing as mp
|
|
import os
|
|
import time
|
|
from contextlib import contextmanager
|
|
from dataclasses import replace
|
|
from datetime import timedelta
|
|
from pathlib import Path
|
|
from queue import Empty
|
|
from types import SimpleNamespace
|
|
from typing import Any
|
|
|
|
import pytest
|
|
import torch
|
|
import torch.distributed as dist
|
|
import torch.nn as nn
|
|
|
|
import obliteratus.distributed.probe as probe_module
|
|
from obliteratus.distributed.contracts import contract_digest
|
|
from obliteratus.distributed.probe import ProbeRuntime, run_distributed_probe_distill
|
|
from obliteratus.distributed.probe_contracts import (
|
|
CoordinatorProbeCorpus,
|
|
DirectionMethod,
|
|
ProbeDistillConfig,
|
|
ProbeDistillSummary,
|
|
ProbeSample,
|
|
compute_layer_artifacts,
|
|
prepare_probe_corpus,
|
|
tensor_digest,
|
|
)
|
|
|
|
|
|
pytestmark = pytest.mark.gloo
|
|
|
|
WORLD_SIZE = 2
|
|
DIGEST = "a" * 64
|
|
|
|
# Budget policy: keep the original short collective failure detectors; the
|
|
# observed load flake was the EXCISE stage budget, so stage budgets get headroom.
|
|
# Reaper = checked stage budgets + (unchecked-interval collectives + longest
|
|
# collective interval between cooperative checks per stage) * group timeout
|
|
# + one stalled collective + exit margin. Collectives can pace just below their
|
|
# timeout: this is a hang-guard envelope, not an expected duration. Explicit
|
|
# timeout/rank-loss/hang oracles keep their own short limits.
|
|
_STAGE_TIMEOUT_SECONDS = 60.0
|
|
_COLLECTIVE_TIMEOUT_SECONDS = 5
|
|
_RANK_EXIT_COLLECTIVE_TIMEOUT_SECONDS = 5
|
|
_COLD_START_TIMEOUT_SECONDS = 60.0 # readiness wait; outside the operation reaper
|
|
_WORKER_EXIT_TIMEOUT_SECONDS = 30.0
|
|
# probe.py:run_live_probe_distill — runtime preparation and corpus acceptance.
|
|
_OUTSIDE_STAGE_COLLECTIVES = 2
|
|
# probe.py:run_distributed_probe_distill — two-site batch: 3 + 8 + 2*10 + 3.
|
|
_STAGE_OVERSHOOT_COLLECTIVES = 34 # setup and final PROBE intervals need only 16
|
|
# probe.py:run_distributed_probe_distill — last check through DISTILL return.
|
|
_DISTILL_TAIL_COLLECTIVES = 3 + 1 + 5 + 2 * 17 + 6 # two layer transfers: 49
|
|
# 60 + (2 outside + 34 overshoot + 49 unchecked tail + 1 stalled) * 5 + 30 = 520.
|
|
_WORKER_TIMEOUT_SECONDS = (
|
|
_STAGE_TIMEOUT_SECONDS
|
|
+ (
|
|
_OUTSIDE_STAGE_COLLECTIVES
|
|
+ _STAGE_OVERSHOOT_COLLECTIVES
|
|
+ _DISTILL_TAIL_COLLECTIVES
|
|
+ 1
|
|
) * _COLLECTIVE_TIMEOUT_SECONDS
|
|
+ _WORKER_EXIT_TIMEOUT_SECONDS
|
|
)
|
|
|
|
|
|
class _Tokenizer:
|
|
vocab_size = 32
|
|
pad_token_id = 0
|
|
bos_token_id = 1
|
|
eos_token_id = 2
|
|
unk_token_id = 3
|
|
padding_side = "right"
|
|
truncation_side = "right"
|
|
chat_template = None
|
|
|
|
def encode(self, text: str, *, add_special_tokens: bool) -> list[int]:
|
|
values = [4 + (ord(value) % 20) for value in text]
|
|
return ([1] if add_special_tokens else []) + values
|
|
|
|
|
|
class _TinyBlock(nn.Module):
|
|
def __init__(self, hidden_size: int) -> None:
|
|
super().__init__()
|
|
self.projection = nn.Linear(hidden_size, hidden_size, bias=False)
|
|
|
|
def forward(self, hidden: torch.Tensor) -> tuple[torch.Tensor]:
|
|
positions = torch.arange(
|
|
1, hidden.shape[1] + 1, dtype=hidden.dtype, device=hidden.device
|
|
).view(1, -1, 1)
|
|
context = hidden.cumsum(dim=1) / positions
|
|
return (torch.tanh(self.projection(context) + hidden),)
|
|
|
|
|
|
class _TinyLlamaShapedModel(nn.Module):
|
|
def __init__(self, *, rank: int, mode: str) -> None:
|
|
super().__init__()
|
|
torch.manual_seed(6107)
|
|
self.embed_tokens = nn.Embedding(32, 4)
|
|
self.model = nn.Module()
|
|
self.model.layers = nn.ModuleList([_TinyBlock(4), _TinyBlock(4)])
|
|
self.rank = rank
|
|
self.mode = mode
|
|
if rank == 1 and mode in {"activation_drift", "nonfinite"}:
|
|
with torch.no_grad():
|
|
if mode == "activation_drift":
|
|
self.model.layers[1].projection.weight.add_(0.25)
|
|
else:
|
|
self.model.layers[1].projection.weight[0, 0] = float("nan")
|
|
|
|
def get_input_embeddings(self) -> nn.Module:
|
|
return self.embed_tokens
|
|
|
|
def forward(
|
|
self,
|
|
*,
|
|
input_ids: torch.Tensor,
|
|
attention_mask: torch.Tensor,
|
|
use_cache: bool,
|
|
) -> SimpleNamespace:
|
|
assert use_cache is False
|
|
assert attention_mask.shape == input_ids.shape
|
|
hidden = self.embed_tokens(input_ids)
|
|
for layer in self.model.layers:
|
|
hidden = layer(hidden)[0]
|
|
return SimpleNamespace(logits=hidden)
|
|
|
|
|
|
def _samples(prefix: str) -> tuple[ProbeSample, ...]:
|
|
return (
|
|
ProbeSample(f"{prefix}-0", f"{prefix}alpha"),
|
|
ProbeSample(f"{prefix}-1", f"{prefix}beta"),
|
|
)
|
|
|
|
|
|
def _config(mode: str) -> ProbeDistillConfig:
|
|
method = DirectionMethod.SVD if mode == "svd" else DirectionMethod.DIFFERENCE_OF_MEANS
|
|
config = ProbeDistillConfig(
|
|
direction_method=method,
|
|
n_directions=2 if method is DirectionMethod.SVD else 1,
|
|
selected_layer_count=2,
|
|
max_samples_per_class=4,
|
|
max_tokens=32,
|
|
batch_size=2,
|
|
max_activation_bytes=1024 * 1024,
|
|
activation_atol=1e-5,
|
|
activation_rtol=1e-4,
|
|
stage_timeout_seconds=_STAGE_TIMEOUT_SECONDS,
|
|
)
|
|
if mode == "timeout":
|
|
return replace(config, stage_timeout_seconds=1e-9)
|
|
if mode == "resource_overlap":
|
|
return replace(config, max_activation_bytes=1024)
|
|
return config
|
|
|
|
|
|
def _parameter_digest(model: nn.Module) -> str:
|
|
digest = hashlib.sha256()
|
|
for name, parameter in model.named_parameters():
|
|
digest.update(name.encode("ascii"))
|
|
digest.update(bytes.fromhex(tensor_digest(parameter)))
|
|
return digest.hexdigest()
|
|
|
|
|
|
def _worker(
|
|
rank: int,
|
|
rendezvous: str,
|
|
mode: str,
|
|
queue: mp.Queue,
|
|
ready: Any,
|
|
) -> None:
|
|
rejected_votes: list[tuple[int, bool]] = []
|
|
resource_activity = {"ram_reads": 0, "hooks": 0, "forwards": 0}
|
|
try:
|
|
dist.init_process_group(
|
|
"gloo",
|
|
init_method=f"file://{rendezvous}",
|
|
rank=rank,
|
|
world_size=WORLD_SIZE,
|
|
timeout=timedelta(
|
|
seconds=(
|
|
_RANK_EXIT_COLLECTIVE_TIMEOUT_SECONDS
|
|
if mode == "rank_exit" else _COLLECTIVE_TIMEOUT_SECONDS
|
|
)
|
|
),
|
|
)
|
|
ready.set()
|
|
if mode == "rank_exit" and rank == 1:
|
|
os._exit(17)
|
|
model = _TinyLlamaShapedModel(rank=rank, mode=mode).eval()
|
|
sites: tuple[str, ...] = ("model.layers.0", "model.layers.1")
|
|
if mode == "partial_manifest" and rank == 1:
|
|
sites = ("model.layers.0",)
|
|
manifest = SimpleNamespace(
|
|
activation_sites=sites,
|
|
digest=contract_digest({"sites": sites}),
|
|
)
|
|
config = _config(mode)
|
|
if mode == "config_drift" and rank == 1:
|
|
config = replace(config, batch_size=1)
|
|
runtime = ProbeRuntime(
|
|
run_id="1" * 32,
|
|
loaded_identity_digest=DIGEST,
|
|
rank=rank,
|
|
world_size=WORLD_SIZE,
|
|
model=model,
|
|
manifest=manifest,
|
|
control_group=dist.group.WORLD,
|
|
data_group=dist.group.WORLD,
|
|
tensor_device=torch.device("cpu"),
|
|
hidden_size=4,
|
|
available_host_bytes=1024 * 1024 * 1024,
|
|
)
|
|
if mode.startswith("resource_"):
|
|
original_hooks = probe_module._install_hooks
|
|
original_forward = model.forward
|
|
|
|
def observe_memory():
|
|
resource_activity["ram_reads"] += 1
|
|
if rank == 1 and mode == "resource_unavailable":
|
|
raise OSError("private live RAM observation failure")
|
|
free = 0 if rank == 1 and mode == "resource_low" else 1 << 30
|
|
return 1 << 30, free
|
|
|
|
def observe_hooks(*args, **kwargs):
|
|
resource_activity["hooks"] += 1
|
|
return original_hooks(*args, **kwargs)
|
|
|
|
def observe_forward(*args, **kwargs):
|
|
resource_activity["forwards"] += 1
|
|
return original_forward(*args, **kwargs)
|
|
|
|
probe_module._host_memory = observe_memory
|
|
probe_module._install_hooks = observe_hooks
|
|
model.forward = observe_forward
|
|
corpus = None
|
|
if (rank == 0 and mode != "missing_samples") or (
|
|
mode == "noncoordinator_corpus" and rank == 1
|
|
):
|
|
corpus = prepare_probe_corpus(
|
|
_Tokenizer(),
|
|
_samples("harm"),
|
|
_samples("safe"),
|
|
source_tokenizer_digest="b" * 64,
|
|
config=config,
|
|
)
|
|
if mode in {"success", "svd"} and rank == 1:
|
|
probe_module.compute_layer_artifacts = lambda *_args, **_kwargs: (_ for _ in ()).throw(
|
|
AssertionError("non-coordinator attempted independent selection")
|
|
)
|
|
if mode == "distill_failure" and rank == 0:
|
|
probe_module.compute_layer_artifacts = lambda *_args, **_kwargs: (_ for _ in ()).throw(
|
|
RuntimeError("private coordinator failure")
|
|
)
|
|
if mode.startswith(("local_", "resource_")) or mode == "live_runtime_failure":
|
|
original_vote = probe_module.unanimous_vote
|
|
|
|
def track_vote(sequence, accepted, *, group):
|
|
agreed = original_vote(sequence, accepted, group=group)
|
|
if not agreed:
|
|
rejected_votes.append((sequence, accepted))
|
|
return agreed
|
|
|
|
probe_module.unanimous_vote = track_vote
|
|
|
|
def preparation_failure(*_args, **_kwargs):
|
|
raise MemoryError("private rank-local preparation failure")
|
|
|
|
if rank == 1:
|
|
if mode == "local_config_digest":
|
|
ProbeDistillConfig.digest = property(preparation_failure)
|
|
elif mode == "local_manifest":
|
|
manifest.activation_sites = ()
|
|
elif mode == "local_site_digest":
|
|
probe_module.contract_digest = preparation_failure
|
|
elif mode == "local_record_decode":
|
|
probe_module.decode_frame = preparation_failure
|
|
elif mode == "local_plan_validation":
|
|
probe_module._validate_plan = preparation_failure
|
|
elif mode == "local_hook_install":
|
|
model.get_submodule = preparation_failure
|
|
elif mode in {"local_hook_cleanup", "local_failed_step_cleanup"}:
|
|
original_hooks = probe_module._install_hooks
|
|
|
|
@contextmanager
|
|
def install_hooks(*args, **kwargs):
|
|
with original_hooks(*args, **kwargs):
|
|
try:
|
|
yield
|
|
finally:
|
|
preparation_failure()
|
|
|
|
probe_module._install_hooks = install_hooks
|
|
if mode == "local_failed_step_cleanup":
|
|
probe_module._update_token_hasher = preparation_failure
|
|
elif mode == "local_resource_preparation":
|
|
probe_module.min = preparation_failure
|
|
elif mode == "local_tensor_allocation":
|
|
original_empty = torch.empty
|
|
|
|
def allocate(shape, *args, **kwargs):
|
|
if kwargs.get("dtype") is torch.int64 and len(shape) == 2:
|
|
preparation_failure()
|
|
return original_empty(shape, *args, **kwargs)
|
|
|
|
torch.empty = allocate
|
|
elif mode == "local_token_hash":
|
|
probe_module._update_token_hasher = preparation_failure
|
|
elif mode == "local_reference_allocation":
|
|
torch.empty_like = preparation_failure
|
|
elif mode == "local_activation_error":
|
|
original_max = torch.Tensor.max
|
|
|
|
def maximum(tensor, *args, **kwargs):
|
|
if tensor.dtype is torch.float64:
|
|
preparation_failure()
|
|
return original_max(tensor, *args, **kwargs)
|
|
|
|
torch.Tensor.max = maximum
|
|
elif mode == "local_activation_hash":
|
|
probe_module._update_activation_hasher = preparation_failure
|
|
elif mode == "local_distill_digest":
|
|
original_tensor_digest = probe_module.tensor_digest
|
|
|
|
def digest(tensor):
|
|
if tensor.dtype is torch.float32 and tensor.ndim == 1:
|
|
preparation_failure()
|
|
return original_tensor_digest(tensor)
|
|
|
|
probe_module.tensor_digest = digest
|
|
elif mode == "local_summary_digest":
|
|
ProbeDistillSummary.digest = property(preparation_failure)
|
|
elif mode == "local_stage_message":
|
|
probe_module.StageMessage = preparation_failure
|
|
elif mode == "local_stage_decode":
|
|
probe_module.StageMessage.from_bytes = preparation_failure
|
|
elif mode == "local_result_constructor":
|
|
probe_module.ProbeDistillResult = preparation_failure
|
|
elif mode == "local_plan_preparation":
|
|
CoordinatorProbeCorpus.plan_record = preparation_failure
|
|
elif mode == "local_record_frame":
|
|
probe_module.encode_frame = preparation_failure
|
|
elif mode == "local_decision_header":
|
|
probe_module.layer_summary_set_digest = preparation_failure
|
|
before = _parameter_digest(model)
|
|
if mode.startswith("live_"):
|
|
probe_module.runtime_from_live_session = (
|
|
preparation_failure
|
|
if mode == "live_runtime_failure" and rank == 1
|
|
else lambda _session: runtime
|
|
)
|
|
session = SimpleNamespace(
|
|
control_group=dist.group.WORLD,
|
|
preflight=SimpleNamespace(
|
|
source_identity=SimpleNamespace(tokenizer_digest="b" * 64)
|
|
)
|
|
)
|
|
harmful = _samples("harm") if rank == 0 or mode == "live_noncoordinator" else None
|
|
harmless = _samples("safe") if rank == 0 or mode == "live_noncoordinator" else None
|
|
result = probe_module.run_live_probe_distill(
|
|
session,
|
|
config,
|
|
harmful=None if mode == "live_missing" and rank == 0 else harmful,
|
|
harmless=harmless,
|
|
tokenizer=_Tokenizer() if rank == 0 else None,
|
|
)
|
|
else:
|
|
result = run_distributed_probe_distill(
|
|
runtime,
|
|
config,
|
|
coordinator_corpus=corpus,
|
|
cancellation_requested=lambda: mode == "cancel" and rank == 1,
|
|
)
|
|
after = _parameter_digest(model)
|
|
queue.put(
|
|
(
|
|
rank,
|
|
"ok",
|
|
{
|
|
"digest": result.digest,
|
|
"selected": result.summary.selected_sites,
|
|
"directions": tuple(layer.directions.tolist() for layer in result.layers),
|
|
"harmful_means": tuple(layer.harmful_mean.tolist() for layer in result.layers),
|
|
"harmless_means": tuple(
|
|
layer.harmless_mean.tolist() for layer in result.layers
|
|
),
|
|
"probed": tuple(message.stage.value for message in result.probed_messages),
|
|
"distilled": tuple(
|
|
message.stage.value for message in result.distilled_messages
|
|
),
|
|
"unchanged": before == after,
|
|
"summary": result.summary,
|
|
},
|
|
)
|
|
)
|
|
except BaseException as exc:
|
|
queue.put((rank, "error", (
|
|
getattr(exc, "code", None), str(exc), rejected_votes, resource_activity,
|
|
)))
|
|
finally:
|
|
if dist.is_available() and dist.is_initialized():
|
|
try:
|
|
dist.destroy_process_group()
|
|
except BaseException:
|
|
pass
|
|
|
|
|
|
def _run(tmp_path: Path, mode: str, *, timeout: float = _WORKER_TIMEOUT_SECONDS):
|
|
context = mp.get_context("spawn")
|
|
queue = context.Queue()
|
|
ready = [context.Event() for _rank in range(WORLD_SIZE)]
|
|
rendezvous = tmp_path / f"{mode}.rendezvous"
|
|
processes = [
|
|
context.Process(
|
|
target=_worker,
|
|
args=(rank, str(rendezvous), mode, queue, ready[rank]),
|
|
)
|
|
for rank in range(WORLD_SIZE)
|
|
]
|
|
for process in processes:
|
|
process.start()
|
|
cold_deadline = time.monotonic() + _COLD_START_TIMEOUT_SECONDS
|
|
for event in ready:
|
|
if not event.wait(max(0.0, cold_deadline - time.monotonic())):
|
|
for process in processes:
|
|
if process.is_alive():
|
|
process.terminate()
|
|
process.join(3)
|
|
pytest.fail(f"{mode} workers did not initialize within the cold-start bound")
|
|
deadline = time.monotonic() + timeout
|
|
for process in processes:
|
|
process.join(max(0.0, deadline - time.monotonic()))
|
|
if process.is_alive():
|
|
process.terminate()
|
|
process.join(3)
|
|
pytest.fail(f"{mode} worker did not terminate within the operation bound")
|
|
results: list[Any] = []
|
|
while len(results) < WORLD_SIZE:
|
|
try:
|
|
results.append(queue.get(timeout=2))
|
|
except Empty:
|
|
break
|
|
queue.close()
|
|
queue.join_thread()
|
|
return sorted(results), tuple(process.exitcode for process in processes)
|
|
|
|
|
|
def _single_process_reference(config: ProbeDistillConfig):
|
|
model = _TinyLlamaShapedModel(rank=0, mode="success").eval()
|
|
corpus = prepare_probe_corpus(
|
|
_Tokenizer(),
|
|
_samples("harm"),
|
|
_samples("safe"),
|
|
source_tokenizer_digest="b" * 64,
|
|
config=config,
|
|
)
|
|
ids = torch.tensor(corpus.input_ids, dtype=torch.int64)
|
|
mask = torch.tensor(corpus.attention_mask, dtype=torch.int64)
|
|
captured: dict[str, torch.Tensor] = {}
|
|
handles = []
|
|
for site in ("model.layers.0", "model.layers.1"):
|
|
|
|
def capture(_module, _inputs, output, *, name=site):
|
|
hidden = output[0] if isinstance(output, tuple) else output
|
|
positions = mask.sum(dim=1) - 1
|
|
rows = torch.arange(hidden.shape[0])
|
|
captured[name] = hidden[rows, positions].detach().float()
|
|
|
|
handles.append(model.get_submodule(site).register_forward_hook(capture))
|
|
with torch.inference_mode():
|
|
model(input_ids=ids, attention_mask=mask, use_cache=False)
|
|
for handle in handles:
|
|
handle.remove()
|
|
return compute_layer_artifacts(
|
|
captured,
|
|
harmful_count=2,
|
|
harmless_count=2,
|
|
config=config,
|
|
activation_digests={name: "c" * 64 for name in captured},
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("mode", ["success", "svd", "live_success"])
|
|
def test_two_rank_probe_distill_matches_single_process_without_mutation(tmp_path, mode):
|
|
results, exits = _run(tmp_path, mode)
|
|
assert exits == (0, 0)
|
|
assert [status for _rank, status, _payload in results] == ["ok", "ok"], results
|
|
payloads = [payload for _rank, _status, payload in results]
|
|
assert len({payload["digest"] for payload in payloads}) == 1
|
|
assert all(payload["unchanged"] for payload in payloads)
|
|
assert all(payload["probed"] == ("probed", "probed") for payload in payloads)
|
|
assert all(payload["distilled"] == ("distilled", "distilled") for payload in payloads)
|
|
assert payloads[0]["directions"] == payloads[1]["directions"]
|
|
assert payloads[0]["harmful_means"] == payloads[1]["harmful_means"]
|
|
assert payloads[0]["harmless_means"] == payloads[1]["harmless_means"]
|
|
|
|
config = _config(mode)
|
|
reference, selected = _single_process_reference(config)
|
|
assert payloads[0]["selected"] == selected
|
|
for index, layer in enumerate(reference):
|
|
assert torch.allclose(
|
|
torch.tensor(payloads[0]["directions"][index]),
|
|
layer.directions,
|
|
atol=config.activation_atol,
|
|
rtol=config.activation_rtol,
|
|
)
|
|
assert torch.allclose(
|
|
torch.tensor(payloads[0]["harmful_means"][index]),
|
|
layer.harmful_mean,
|
|
atol=config.activation_atol,
|
|
rtol=config.activation_rtol,
|
|
)
|
|
assert torch.allclose(
|
|
torch.tensor(payloads[0]["harmless_means"][index]),
|
|
layer.harmless_mean,
|
|
atol=config.activation_atol,
|
|
rtol=config.activation_rtol,
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("mode", "code"),
|
|
[
|
|
("noncoordinator_corpus", "LMS_PROBE_INPUT_INVALID"),
|
|
("missing_samples", "LMS_PROBE_INPUT_INVALID"),
|
|
("config_drift", "LMS_PROBE_PROFILE_MISMATCH"),
|
|
("partial_manifest", "LMS_PROBE_HOOK_UNSUPPORTED"),
|
|
("activation_drift", "LMS_PROBE_ACTIVATION_DIVERGED"),
|
|
("nonfinite", "LMS_PROBE_HOOK_UNSUPPORTED"),
|
|
("cancel", "LMS_PROBE_CANCELLED"),
|
|
("timeout", "LMS_PROBE_TIMEOUT"),
|
|
("distill_failure", "LMS_DISTILL_INVALID"),
|
|
("live_missing", "LMS_PROBE_INPUT_INVALID"),
|
|
("live_noncoordinator", "LMS_PROBE_INPUT_INVALID"),
|
|
],
|
|
)
|
|
def test_every_rank_refuses_divergence_partial_hooks_cancellation_and_timeout(tmp_path, mode, code):
|
|
results, exits = _run(tmp_path, mode)
|
|
assert exits == (0, 0)
|
|
assert len(results) == 2
|
|
assert [status for _rank, status, _payload in results] == ["error", "error"]
|
|
assert {payload[0] for _rank, _status, payload in results} == {code}
|
|
assert all("harmalpha" not in payload[1] for _rank, _status, payload in results)
|
|
|
|
|
|
def test_rank_exit_is_bounded_and_cannot_produce_distilled_state(tmp_path):
|
|
started = time.monotonic()
|
|
results, exits = _run(tmp_path, "rank_exit", timeout=15)
|
|
assert time.monotonic() - started < 15
|
|
assert exits[1] == 17
|
|
assert len(results) == 1
|
|
assert results[0][1] == "error"
|
|
assert results[0][2][0] in {
|
|
"LMS_PROBE_PROFILE_MISMATCH",
|
|
"LMS_PROBE_COLLECTIVE_FAILED",
|
|
"LMS_PROBE_HOOK_UNSUPPORTED",
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize("mode", ["resource_low", "resource_unavailable", "resource_overlap"])
|
|
def test_fresh_ram_and_overlap_denial_are_unanimous_before_hooks_or_forward(tmp_path, mode):
|
|
results, exits = _run(tmp_path, mode)
|
|
assert exits == (0, 0)
|
|
assert len(results) == WORLD_SIZE
|
|
assert [status for _rank, status, _payload in results] == ["error", "error"]
|
|
assert {payload[0] for _rank, _status, payload in results} == {"LMS_PROBE_RESOURCE_DENIED"}
|
|
for _rank, _status, payload in results:
|
|
assert payload[3] == {"ram_reads": 1, "hooks": 0, "forwards": 0}
|
|
assert len(payload[2]) == 1
|
|
assert payload[2][0][0] == 61_001
|
|
assert "private live RAM" not in payload[1]
|
|
local_votes = {rank: payload[2][0][1] for rank, _status, payload in results}
|
|
assert local_votes == ({0: False, 1: False} if mode == "resource_overlap" else {0: True, 1: False})
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("mode", "sequence", "code"),
|
|
[
|
|
("local_config_digest", 6_300_100, "LMS_PROBE_PROFILE_MISMATCH"),
|
|
("local_manifest", 6_300_010, "LMS_PROBE_HOOK_UNSUPPORTED"),
|
|
("local_site_digest", 6_300_010, "LMS_PROBE_HOOK_UNSUPPORTED"),
|
|
("local_plan_preparation", 6_300_101, "LMS_PROBE_INPUT_INVALID"),
|
|
("local_record_frame", 6_300_000, "LMS_PROBE_COLLECTIVE_FAILED"),
|
|
("local_record_decode", 6_300_001, "LMS_PROBE_COLLECTIVE_FAILED"),
|
|
("local_plan_validation", 6_300_102, "LMS_PROBE_INPUT_INVALID"),
|
|
("local_resource_preparation", 61_001, "LMS_PROBE_RESOURCE_DENIED"),
|
|
("local_hook_install", 6_300_103, "LMS_PROBE_HOOK_UNSUPPORTED"),
|
|
("local_hook_cleanup", 6_300_116, "LMS_PROBE_HOOK_UNSUPPORTED"),
|
|
("local_failed_step_cleanup", 6_300_105, "LMS_PROBE_INPUT_INVALID"),
|
|
("local_tensor_allocation", 6_300_020, "LMS_PROBE_COLLECTIVE_FAILED"),
|
|
("local_token_hash", 6_300_105, "LMS_PROBE_INPUT_INVALID"),
|
|
("local_reference_allocation", 6_300_106, "LMS_PROBE_ACTIVATION_DIVERGED"),
|
|
("local_activation_error", 6_300_030, "LMS_PROBE_ACTIVATION_DIVERGED"),
|
|
("local_activation_hash", 6_300_108, "LMS_PROBE_ACTIVATION_DIVERGED"),
|
|
("local_decision_header", 6_300_112, "LMS_DISTILL_INVALID"),
|
|
("local_distill_digest", 6_300_124, "LMS_DISTILL_DIVERGED"),
|
|
("local_summary_digest", 6_300_126, "LMS_DISTILL_DIVERGED"),
|
|
("local_stage_message", 6_300_040, "LMS_PROBE_COLLECTIVE_FAILED"),
|
|
("local_stage_decode", 6_300_041, "LMS_PROBE_COLLECTIVE_FAILED"),
|
|
("local_result_constructor", 6_300_128, "LMS_DISTILL_INVALID"),
|
|
("live_runtime_failure", 6_300_200, "LMS_PROBE_PROFILE_MISMATCH"),
|
|
],
|
|
)
|
|
def test_local_preparation_failure_is_voted_before_the_next_collective(
|
|
tmp_path, mode, sequence, code
|
|
):
|
|
results, exits = _run(tmp_path, mode)
|
|
assert exits == (0, 0)
|
|
assert len(results) == WORLD_SIZE
|
|
assert [status for _rank, status, _payload in results] == ["error", "error"]
|
|
assert {payload[0] for _rank, _status, payload in results} == {code}
|
|
votes = [payload[2] for _rank, _status, payload in results]
|
|
assert all(len(items) == 1 and items[0][0] == sequence for items in votes)
|
|
assert {items[0][1] for items in votes} == {False, True}
|
|
assert all("private rank-local" not in payload[1] for _rank, _status, payload in results)
|
|
|
|
|
|
def test_retained_summary_is_redaction_safe(tmp_path):
|
|
results, _exits = _run(tmp_path, "success")
|
|
summary = results[0][2]["summary"]
|
|
payload = str(summary)
|
|
assert "harmalpha" not in payload
|
|
assert "safealpha" not in payload
|
|
assert "input_ids" not in payload
|
|
assert "attention_mask" not in payload
|
|
assert payload == str(results[1][2]["summary"])
|