[Core] Expose HWR payload validation in diffusion startup

Signed-off-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
Hongsheng Liu committed 2026-09-06 16:54:01 +08:00
1 parent 039808e0d9
commit d989aa6fe2
11 files changed
+158 -1

No files matched your search

+31
View File
@@ -193,6 +193,37 @@ def test_resolve_execution_mode_rejects_unknown_execution_type():
omni_config_module._resolve_execution_mode("unknown_execution_type")
@pytest.mark.parametrize("validation", ["manifest_and_metadata", "full_checksum"])
def test_hwr_validation_survives_config_projection(validation: str):
from vllm_omni.diffusion.data import OmniDiffusionConfig
override = StageDeployConfig(stage_id=0, host_weight_runtime_validation=validation)
config = _from_pipeline_key(
"dreamzero",
deploy_config_path="dreamzero_tp1_cfg2",
cli_overrides={"host_weight_runtime_validation": validation},
)
stage = config.stage_by_id(0)
assert isinstance(stage, VllmOmniDiffusionStageConfig)
assert stage.diffusion_config.host_weight_runtime_validation == validation
projection = omni_config_module._DiffusionConfigProjection.from_kwargs(
host_weight_runtime_validation=override.host_weight_runtime_validation
)
assert projection.host_weight_runtime_validation == validation
assert OmniDiffusionConfig(host_weight_runtime_validation=validation).host_weight_runtime_validation == validation
assert omni_config_module._DiffusionConfigProjection().host_weight_runtime_validation == "manifest_and_metadata"
assert OmniDiffusionConfig().host_weight_runtime_validation == "manifest_and_metadata"
@pytest.mark.parametrize("validation", ["fs_verity", "unknown", None])
def test_hwr_validation_rejects_unsupported_values(validation):
from vllm_omni.diffusion.data import OmniDiffusionConfig
for config_class in (OmniDiffusionConfig, omni_config_module._DiffusionConfigProjection):
with pytest.raises(ValueError, match="host_weight_runtime_validation"):
config_class(host_weight_runtime_validation=validation)
def test_from_pipeline_config_preserves_current_pipeline_config_object():
omni_config = _from_pipeline_key("minicpmo_4_5")
pipeline = _resolve_pipeline_or_skip("minicpmo_4_5")
@@ -260,6 +260,78 @@ def test_hwr_cold_publication_and_warm_restore_skip_ordinary_dit_loading(
assert len(tuple((store_root / "source-digests-v1" / "entries").glob("*.json"))) == 1
@pytest.mark.parametrize("validation", ["manifest_and_metadata", "full_checksum"])
@pytest.mark.parametrize("mode", ["preferred", "required"])
def test_hwr_loader_payload_integrity_policy(tmp_path: Path, monkeypatch, validation: str, mode: str):
from vllm_omni.diffusion.offloader.startup import take_offload_startup_state
canonical = tmp_path / "canonical"
canonical.mkdir()
expected = torch.arange(4, dtype=torch.float32).to(torch.bfloat16).reshape(2, 2)
save_file({"weight": expected}, str(canonical / "model.safetensors"))
root = tmp_path / "store"
def make_loader(runtime_mode: str):
config = _hwr_config(canonical, root, mode=runtime_mode)
config.host_weight_runtime_validation = validation
loader = DiffusersPipelineLoader(LoadConfig(), config)
pipeline = _HWRPipeline(canonical)
monkeypatch.setattr(loader, "_init_from_load_format", lambda *args, **kwargs: pipeline)
return loader, pipeline
def close_plan(pipeline):
state = take_offload_startup_state(pipeline)
if state is not None and state.host_weight_plan is not None:
carrier = state.host_weight_plan.lease_carrier
if carrier is not None:
carrier.close()
cold_loader, cold = make_loader("preferred")
cold_loader.load_model(load_device="cpu", device=torch.device("cpu"))
assert cold.load_count == 1
close_plan(cold)
payloads = list((root / "artifacts").glob("*/*.safetensors"))
assert len(payloads) == 1
payload = payloads[0]
data = bytearray(payload.read_bytes())
data[-1] ^= 1 # Keep the header and file length valid; change only a BF16 payload byte.
original_mode = payload.stat().st_mode
payload.chmod(0o600)
payload.write_bytes(data)
payload.chmod(original_mode)
loader, pipeline = make_loader(mode)
try:
if validation == "full_checksum" and mode == "required":
with pytest.raises(RuntimeError, match="Host Weight Runtime resolution failed"):
loader.load_model(load_device="cpu", device=torch.device("cpu"))
assert pipeline.load_count == 0
assert loader.take_host_weight_plan() is None
else:
loader.load_model(load_device="cpu", device=torch.device("cpu"))
if validation == "manifest_and_metadata":
assert pipeline.load_count == 0
assert not torch.equal(pipeline.transformer.weight, expected)
else:
assert pipeline.load_count == 1
assert torch.equal(pipeline.transformer.weight, expected)
finally:
close_plan(pipeline)
if validation == "full_checksum":
if mode == "required":
assert list((root / "deny").iterdir())
else:
assert list((root / "quarantine").iterdir())
warm_loader, warm = make_loader(mode)
try:
warm_loader.load_model(load_device="cpu", device=torch.device("cpu"))
assert warm.load_count == 0
assert torch.equal(warm.transformer.weight, expected)
finally:
close_plan(warm)
def test_maybe_fuse_distilled_lora_skips_when_hwr_warm_snapshot_present():
cfg = SimpleNamespace(
lora_backend="distill",
@@ -503,6 +503,8 @@ def test_serve_cli_forwards_hwr_policy_for_no_allgather_dlo():
"--omni",
"--enable-distributed-layerwise-offload",
"--dlo-no-use-allgather",
"--host-weight-runtime-validation",
"full_checksum",
"--host-weight-runtime-mode",
"preferred",
"--host-weight-runtime-root",
@@ -519,6 +521,8 @@ def test_serve_cli_forwards_hwr_policy_for_no_allgather_dlo():
assert explicit_kwargs["host_weight_runtime_mode"] == "preferred"
assert explicit_kwargs["host_weight_runtime_root"] == "/var/cache/vllm-omni/hwr"
assert explicit_kwargs["dlo_host_registration_limit_gib"] == 80
assert explicit_kwargs["host_weight_runtime_validation"] == "full_checksum"
assert engine_args["host_weight_runtime_validation"] == "full_checksum"
assert engine_args["host_weight_runtime_mode"] == "preferred"
assert engine_args["host_weight_runtime_root"] == "/var/cache/vllm-omni/hwr"
assert engine_args["dlo_host_registration_limit_gib"] == 80