Archive 1 checkpoints (1-1)
Browse files
paper-releases/pbisc-diffusion/updates/20261013T124345Z-trunk4x-lora-sepsis-launch/diffusion/dataset/server_1/model8/plans/trunk4x_lora_sepsis_20261013/tools/sample_one_frozen.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run the frozen sampler inside the caller's ml-run unit, preserving separate receipt and error logs."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
from runtime import sha256
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def main() -> int:
|
| 12 |
+
p = argparse.ArgumentParser()
|
| 13 |
+
p.add_argument("--checkpoint", type=Path, required=True)
|
| 14 |
+
p.add_argument("--checkpoint-sha", required=True)
|
| 15 |
+
p.add_argument("--condition", type=Path, required=True)
|
| 16 |
+
p.add_argument("--output", type=Path, required=True)
|
| 17 |
+
p.add_argument("--seed", type=int, default=20260928)
|
| 18 |
+
a = p.parse_args()
|
| 19 |
+
if "ml.slice" not in Path("/proc/self/cgroup").read_text():
|
| 20 |
+
raise SystemExit("sampler wrapper must be started through ml-run")
|
| 21 |
+
if sha256(a.checkpoint) != a.checkpoint_sha:
|
| 22 |
+
raise SystemExit("checkpoint hash mismatch")
|
| 23 |
+
if any(a.output.with_suffix(s).exists() for s in (".npz", ".log", ".err")):
|
| 24 |
+
raise SystemExit("existing sampling output or log: preserve and inspect")
|
| 25 |
+
a.output.parent.mkdir(parents=True, exist_ok=True)
|
| 26 |
+
script = Path(__file__).resolve().parents[3] / "scripts/sample_sdd_standalone.py"
|
| 27 |
+
argv = [sys.executable, "-u", str(script), "--checkpoint", str(a.checkpoint),
|
| 28 |
+
"--condition-npz", str(a.condition), "--output", str(a.output), "--weights", "ema",
|
| 29 |
+
"--batch-size", "256", "--steps", "50", "--seed", str(a.seed), "--device", "cuda",
|
| 30 |
+
"--conditioner-source", "embedded", "--active-logit-threshold", "0.0",
|
| 31 |
+
"--support-readout", "bernoulli"]
|
| 32 |
+
with a.output.with_suffix(".log").open("x") as out, a.output.with_suffix(".err").open("x") as err:
|
| 33 |
+
result = subprocess.run(argv, stdout=out, stderr=err)
|
| 34 |
+
if result.returncode:
|
| 35 |
+
return result.returncode
|
| 36 |
+
receipt = json.loads(a.output.with_suffix(".log").read_text())
|
| 37 |
+
if receipt["output_sha256"] != sha256(a.output):
|
| 38 |
+
raise SystemExit("sampler output differs from its receipt")
|
| 39 |
+
print(json.dumps({"output": str(a.output), "output_sha256": receipt["output_sha256"]}), flush=True)
|
| 40 |
+
return 0
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
raise SystemExit(main())
|