#!/usr/bin/env python3 """Lightweight contracts for the exact Phase-6 source-input verifier.""" from __future__ import annotations import importlib.util import tempfile from pathlib import Path from types import SimpleNamespace ROOT = Path(__file__).resolve().parents[2] SPEC = importlib.util.spec_from_file_location( "phase6_source_inputs", ROOT / "scripts/verify_phase6_source_inputs.py" ) assert SPEC is not None and SPEC.loader is not None MODULE = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(MODULE) def main() -> None: with tempfile.TemporaryDirectory() as directory: root = Path(directory) (root / "one").write_bytes(b"123") (root / "two").write_bytes(b"45") MODULE.exact_file_layout(root, {"one": 3, "two": 2}) try: MODULE.exact_file_layout(root, {"one": 3}) except ValueError as error: assert "unexpected=['two']" in str(error) else: raise AssertionError("unexpected source file was accepted") hf_init = root / "hf-init" hf_init.mkdir() selected = SimpleNamespace( model=str(hf_init), model_type="dsv4_vl", torch_dtype="bfloat16", expert_model_parallel_size=8, tensor_model_parallel_size=1, pipeline_model_parallel_size=1, mtp_num_layers=0, bf16=True, fp16=False, ) MODULE.require_selected_args(selected, hf_init) selected.expert_model_parallel_size = 1 try: MODULE.require_selected_args(selected, hf_init) except ValueError as error: assert "expert_model_parallel_size" in str(error) else: raise AssertionError("wrong MCore EP topology was accepted") launcher = (ROOT / "scripts/phase6_merge_export.sh").read_text() followup = (ROOT / "scripts/phase6_post_stage2_followup.sh").read_text() for source in (launcher, followup): assert "verify_phase6_source_inputs.py" in source assert "PHASE6_SOURCE_INPUTS.json" in source print("DSV4VL_PHASE6_SOURCE_INPUTS_UNIT=PASS") if __name__ == "__main__": main()