Download code/verify_advdmd.py from yang29/afd-causal-forcing-baselines-vbench: direct link, hf CLI and curl.
- Browser
- Download file 2.69 kB
-
https://huggingface.co/datasets/yang29/afd-causal-forcing-baselines-vbench/resolve/main/code/verify_advdmd.py
- Command line
-
hf download hf://datasets/yang29/afd-causal-forcing-baselines-vbench/code/verify_advdmd.py
-
curl -L -o verify_advdmd.py https://huggingface.co/datasets/yang29/afd-causal-forcing-baselines-vbench/resolve/main/code/verify_advdmd.py
2.69 kB
| """Verify a real two-B200 AdvDMD optimizer update and its saved LoRA.""" | |
| import argparse | |
| import json | |
| import math | |
| from pathlib import Path | |
| import torch | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("run_dir", type=Path) | |
| parser.add_argument("--job-id") | |
| args = parser.parse_args() | |
| metrics = [json.loads(line) for line in (args.run_dir / "metrics.jsonl").read_text().splitlines()] | |
| if len(metrics) != 1 or metrics[0]["step"] != 1 or metrics[0]["world_size"] != 2: | |
| raise RuntimeError("Expected one completed two-rank training round") | |
| if not metrics[0]["grpo_active"] or metrics[0]["student_grad_norm"] <= 0: | |
| raise RuntimeError("GRPO must be active and student gradients must be nonzero") | |
| if not all(math.isfinite(value) for value in metrics[0].values() if isinstance(value, (int, float))): | |
| raise RuntimeError("Non-finite training metrics") | |
| checkpoint = args.run_dir / "checkpoints/step-1.pt" | |
| state = torch.load(checkpoint, map_location="cpu", weights_only=True) | |
| weights = state["generator_lora"] | |
| if state["step"] != 1 or state["config"]["student_family"] != "causal_forcing": | |
| raise RuntimeError("Checkpoint step or generator does not match") | |
| all_weights = {**weights, **state["discriminator_heads"]} | |
| if not all(torch.isfinite(value).all().item() for value in all_weights.values()): | |
| raise RuntimeError("Checkpoint has non-finite weights") | |
| if not any(torch.count_nonzero(value).item() for name, value in weights.items() if "lora_B" in name): | |
| raise RuntimeError("No LoRA-B tensors changed from initialization") | |
| compiler = json.loads((args.run_dir / "compiler.json").read_text()) | |
| cfg = state["config"] | |
| if "gradient_accumulation_steps" in cfg: | |
| expected = cfg["train_batch_size"] * cfg["gradient_accumulation_steps"] | |
| if metrics[0]["generator_samples_per_rank"] != expected or metrics[0]["training_videos"] != expected * 2: | |
| raise RuntimeError("Smoke did not apply the configured effective batch") | |
| if compiler.get("recompile_limit", compiler.get("cache_size_limit", 0)) < 64: | |
| raise RuntimeError("The AR compilation budget was not applied") | |
| result = {"passed": True, "job_id": args.job_id, "generator_family": "causal_forcing", "world_size": 2, | |
| "checkpoint": str(checkpoint), "grpo_active": True, "all_saved_tensors_finite": True, | |
| "lora_B_changed": True, "metrics": metrics[0], "compiler": compiler} | |
| (args.run_dir / "smoke_verified.json").write_text(json.dumps(result, indent=2) + "\n") | |
| print(json.dumps(result, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |