mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-06 11:04:06 +01:00
Integrate bounded admission, UI ownership and controls, opt-in durable MCP execution, rank-local TP2 groundwork, regression hardening and operator guides. Physical larger-memory and two-host qualification remain separate.
173 lines
6.4 KiB
Python
173 lines
6.4 KiB
Python
"""CPU-only mocked stage contracts for the experimental two-host TP2 shape."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import replace
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
import torch
|
|
|
|
import obliteratus.distributed.probe as probe
|
|
from obliteratus.distributed.contracts import ContractError, RuntimeContractError
|
|
from obliteratus.distributed.launcher import TorchrunEnvironment
|
|
from obliteratus.distributed.model_evidence import LOAD_EVIDENCE_BINDING_FIELDS
|
|
from obliteratus.distributed.model_registry import LLAMA_BF16_TP2_PROFILE
|
|
from obliteratus.distributed.model_session import DataPlane, LiveModelSession
|
|
from obliteratus.distributed.probe_contracts import ProbeDistillConfig
|
|
|
|
|
|
RUN_ID = "a" * 32
|
|
DIGEST = "b" * 64
|
|
|
|
|
|
def _session(rank: int, *, device_index: int = 0) -> LiveModelSession:
|
|
# Device descriptors and parameter mocks never allocate a CUDA tensor.
|
|
embedding = SimpleNamespace(
|
|
parameters=lambda: iter((SimpleNamespace(device=torch.device("cuda", device_index)),))
|
|
)
|
|
manifest = SimpleNamespace(rank=rank, world_size=2, digest=DIGEST)
|
|
return LiveModelSession(
|
|
preflight=SimpleNamespace(
|
|
identity=SimpleNamespace(run_id=RUN_ID),
|
|
identity_digest=DIGEST,
|
|
attestations=(
|
|
SimpleNamespace(rank=1, free_host_memory_bytes=16_384),
|
|
SimpleNamespace(rank=0, free_host_memory_bytes=32_768),
|
|
),
|
|
),
|
|
config=SimpleNamespace(local_world_size=1),
|
|
launch=SimpleNamespace(rank=rank, local_rank=0, local_world_size=1, group_rank=rank),
|
|
handle=SimpleNamespace(
|
|
model=SimpleNamespace(get_input_embeddings=lambda: embedding),
|
|
manifest=manifest,
|
|
manifest_digest=DIGEST,
|
|
profile=LLAMA_BF16_TP2_PROFILE,
|
|
plan_digest=DIGEST,
|
|
config=SimpleNamespace(hidden_size=8),
|
|
),
|
|
control_group=object(),
|
|
data_plane=DataPlane(group=object(), device_mesh=object(), digest=DIGEST),
|
|
bindings={name: DIGEST for name in LOAD_EVIDENCE_BINDING_FIELDS},
|
|
summary_set_digest=DIGEST,
|
|
summaries=(),
|
|
loaded_messages=(),
|
|
)
|
|
|
|
|
|
def test_two_host_probe_uses_local_device_and_each_ranks_host_inventory():
|
|
coordinator = probe.runtime_from_live_session(_session(0))
|
|
worker = probe.runtime_from_live_session(_session(1))
|
|
|
|
assert (coordinator.rank, worker.rank) == (0, 1)
|
|
assert coordinator.tensor_device == worker.tensor_device == torch.device("cuda", 0)
|
|
assert coordinator.available_host_bytes == 32_768
|
|
assert worker.available_host_bytes == 16_384
|
|
assert coordinator.loaded_identity_digest == worker.loaded_identity_digest
|
|
|
|
|
|
def test_two_host_probe_rejects_a_device_chosen_from_global_rank():
|
|
with pytest.raises(RuntimeContractError) as failure:
|
|
probe.runtime_from_live_session(_session(1, device_index=1))
|
|
|
|
assert failure.value.code == "LMS_PROBE_PROFILE_MISMATCH"
|
|
|
|
|
|
def test_probe_identity_keeps_the_attested_preflight_topology_binding():
|
|
session = _session(1)
|
|
changed = replace(
|
|
session,
|
|
preflight=SimpleNamespace(
|
|
identity=session.preflight.identity,
|
|
identity_digest="c" * 64,
|
|
attestations=session.preflight.attestations,
|
|
),
|
|
)
|
|
|
|
assert (
|
|
probe.runtime_from_live_session(session).loaded_identity_digest
|
|
!= probe.runtime_from_live_session(changed).loaded_identity_digest
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("rank", (0, 1))
|
|
@pytest.mark.parametrize("enough_memory", (False, True))
|
|
def test_probe_admission_votes_each_hosts_full_bounded_budget(monkeypatch, rank, enough_memory):
|
|
runtime = probe.runtime_from_live_session(_session(rank))
|
|
required = probe._probe_peak_host_bytes(
|
|
runtime, ProbeDistillConfig(), sample_count=4, site_count=2,
|
|
)
|
|
runtime = replace(runtime, available_host_bytes=required * 2 if enough_memory else required * 2 - 1)
|
|
monkeypatch.setattr(probe, "_host_memory", lambda: (1 << 30, 1 << 30))
|
|
votes = []
|
|
|
|
def vote(sequence, accepted, *, group):
|
|
votes.append((sequence, accepted, group))
|
|
return accepted
|
|
|
|
monkeypatch.setattr(probe, "unanimous_vote", vote)
|
|
if enough_memory:
|
|
probe._resource_admission(runtime, ProbeDistillConfig(), sample_count=4, site_count=2)
|
|
else:
|
|
with pytest.raises(RuntimeContractError) as failure:
|
|
probe._resource_admission(runtime, ProbeDistillConfig(), sample_count=4, site_count=2)
|
|
assert failure.value.code == "LMS_PROBE_RESOURCE_DENIED"
|
|
|
|
assert votes == [(61_001, enough_memory, runtime.control_group)]
|
|
|
|
|
|
def test_a_worker_memory_veto_refuses_on_the_coordinator_too(monkeypatch):
|
|
runtime = probe.runtime_from_live_session(_session(0))
|
|
votes = []
|
|
|
|
def worker_veto(sequence, accepted, *, group):
|
|
votes.append((sequence, accepted, group))
|
|
return False
|
|
|
|
monkeypatch.setattr(probe, "unanimous_vote", worker_veto)
|
|
with pytest.raises(RuntimeContractError) as failure:
|
|
probe._resource_admission(runtime, ProbeDistillConfig(), sample_count=4, site_count=2)
|
|
|
|
assert failure.value.code == "LMS_PROBE_RESOURCE_DENIED"
|
|
assert votes == [(61_001, True, runtime.control_group)]
|
|
|
|
|
|
@pytest.mark.parametrize("rank", (0, 1))
|
|
def test_torchrun_two_host_identity_keeps_local_rank_zero(rank):
|
|
config = SimpleNamespace(
|
|
world_size=2,
|
|
local_world_size=1,
|
|
run_id=RUN_ID,
|
|
rendezvous_id="c" * 32,
|
|
master_addr="10.10.0.10",
|
|
master_port=29500,
|
|
allowed_master_cidrs=("10.10.0.0/24",),
|
|
network_interface="eth0",
|
|
allowed_environment_keys=(),
|
|
)
|
|
environment = {
|
|
"RANK": str(rank),
|
|
"LOCAL_RANK": "0",
|
|
"WORLD_SIZE": "2",
|
|
"LOCAL_WORLD_SIZE": "1",
|
|
"GROUP_RANK": str(rank),
|
|
"ROLE_RANK": str(rank),
|
|
"ROLE_WORLD_SIZE": "2",
|
|
"MASTER_ADDR": config.master_addr,
|
|
"MASTER_PORT": str(config.master_port),
|
|
"TORCHELASTIC_RUN_ID": config.rendezvous_id,
|
|
"TORCHELASTIC_RESTART_COUNT": "0",
|
|
"TORCHELASTIC_MAX_RESTARTS": "0",
|
|
"OBLITERATUS_RUN_ID": RUN_ID,
|
|
"GLOO_SOCKET_IFNAME": "eth0",
|
|
"NCCL_SOCKET_IFNAME": "eth0",
|
|
}
|
|
|
|
launch = TorchrunEnvironment.from_environ(environment, config)
|
|
|
|
assert (launch.rank, launch.group_rank, launch.local_rank) == (rank, rank, 0)
|
|
assert launch.local_world_size == 1
|
|
if rank == 1:
|
|
with pytest.raises(ContractError):
|
|
TorchrunEnvironment.from_environ({**environment, "GROUP_RANK": "0"}, config)
|