Files
Davids048andClaude Fable 5.1 a5aa64ab6b [refactor]: decide every config value before the config freezes, and drop the from_pretrained keywords
VideoGenerator.from_pretrained(model_path, config) takes the same nested
settings as from_config; the 24 flat keywords, from_pretrained_kwargs_to_config,
FROM_PRETRAINED_KWARGS, and every flat_field in the schema are deleted.
nvfp4_fa4 is the typed field engine.attention.nvfp4_fa4, applied by a
resolution step. 65 call sites and the docs use the nested form; the three
kwargs golden cases are config cases with byte-identical results.

Every value is decided during resolution; no runtime code calls
with_override. The device offload policy (unified memory, MPS, layerwise
conflicts, lazy module load) runs as resolution steps in the main process
(fastvideo/api/device_policy.py), and the worker runs on the config it
receives. The LTX-2 refine defaults from model_index.json and the MiniMax-H3
schedule from fastvideo_inference.json are resolution steps
(fastvideo/api/checkpoint_defaults.py) that read local checkpoints or download
only those files; the H3 pipeline validates the schedule against the loaded
schedulers but no longer writes it. The preprocessing entry point passes the
downloaded local path as run state instead of a config override. Teacher and
critic models load with override_transformer_cls_name as a load argument.
The test isolation turns the device policy off, as it blocks downloads, so
that the goldens do not depend on the machine.

Against the 3f6893a0 goldens, every field still matches except boundary_ratio
and ltx2_vae_tiling (DESIGN section 9) and the fields that no longer exist.
The launcher and trainer YAML verifications report 0 unexplained differences.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-04 07:14:31 +00:00

88 lines
2.7 KiB
Python

"""torch.compile A/B example for FastVideo.
`engine.compile.enabled: true` compiles the DiT submodules that declare
`_compile_conditions` for a substantial end-to-end speedup (e.g.
Wan2.1-T2V-1.3B on A100: ~-24% e2e). It is off by default.
The first compiled generation pays a one-time graph-build cost; it
amortizes over later generations with the same input shapes. This
script does one un-measured warmup then a measured run so the reported
number is steady-state, not graph-build — measuring the warmup is the
most common way to wrongly conclude compile is slower.
Usage:
# baseline (eager)
python torch_compile_example.py
# compiled
python torch_compile_example.py --compile
"""
import argparse
import os
import time
from fastvideo import VideoGenerator
PROMPT = ("A high-definition video of a robotic arm welding a metal structure, "
"bright sparks and smoke, industrial setting.")
def main() -> None:
parser = argparse.ArgumentParser(description="torch.compile A/B")
parser.add_argument("--model", default="Wan-AI/Wan2.1-T2V-1.3B-Diffusers")
parser.add_argument("--compile", action="store_true", help="Enable torch.compile for the DiT")
parser.add_argument("--num_gpus", type=int, default=1)
args = parser.parse_args()
mode = "COMPILE" if args.compile else "BASELINE"
print(f"Mode: {mode} (engine.compile.enabled={args.compile})")
os.makedirs("video_samples", exist_ok=True)
generator = VideoGenerator.from_pretrained(
args.model,
{
"engine": {
"num_gpus": args.num_gpus,
"compile": {
"enabled": args.compile,
},
},
},
)
def _run(tag: str) -> float:
save = tag == "measured"
# Typed request API. Same prompt/seed/shapes both runs so the
# compiled graph is reused.
request: dict = {
"prompt": PROMPT,
"sampling": {
"seed": 1024
},
"output": {
"save_video": save
},
}
if save:
request["output"]["output_path"] = (f"video_samples/torch_compile_{tag}.mp4")
t0 = time.perf_counter()
generator.generate(request)
return time.perf_counter() - t0
try:
# Warmup: pays the one-time graph build when --compile. Discarded.
w = _run("warmup")
print(f"warmup: {w:.2f}s "
f"({'incl. graph build' if args.compile else 'cold start'})")
# Measured: steady state, compiled graph reused (same shapes/seed).
m = _run("measured")
print(f"=== {mode} steady-state e2e: {m:.2f}s ===")
finally:
generator.shutdown()
if __name__ == "__main__":
main()