You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[perf]: opt-in batched classifier-free guidance for Wan/Cosmos
Run cond + uncond as a single batch=2 DiT forward per denoise step
instead of two sequential batch=1 forwards. Default OFF so this PR
has zero behaviour change for any user who doesn't opt in via
`use_batched_cfg=True`. Composes with hao-ai-lab#1372 Adaptive Guidance —
mutually exclusive at the gate level (AG selectively skips uncond,
batched-CFG forces both; running them together defeats AG's win).
Bit-equivalent to sequential CFG on H100 FA3 eager (SSIM=1.000000,
Wan 14B 720x1280x49f/30steps, 5 prompts). On other configs (compile,
FA2, smaller models) bf16 numerics drift slightly (~0.04 SSIM mean,
visually imperceptible per frame-by-frame inspection) due to
Inductor kernel selection and batched flash-attn numerics. Perf
delta is run-to-run variable.
Changes:
- fastvideo_args.py: new use_batched_cfg: bool = False field +
--use-batched-cfg CLI. Auto-fallback to sequential when V2V/I2V/
TI2V/action/camera conditioning is present (those carry batch=1
conditioning tensors out of scope for this PR) OR when AG is
active.
- entrypoints/video_generator.py: add use_batched_cfg to
_FROM_PRETRAINED_CONVENIENCE_KWARGS.
- pipelines/stages/denoising.py: gated batched branch in main
DenoisingStage.forward. Cats [neg, pos] along batch dim with
shape-match defensive fallback, single forward, chunk(2),
existing CFG-combine + guidance_rescale math reused. Other
DenoisingStage subclasses (Cosmos25, Dmd, ...) unchanged.
- api/schema.py + api/compat.py: EngineConfig.use_batched_cfg
field + legacy<->typed mappings (mirrors disable_autocast).
- docs/design/inference_schema_parity_inventory.yaml: inventory
entry under fastvideo_args.moved.
- tests/api/test_parser.py: YAML-roundtrip expected dict updated.
Sequential CFG path preserved bit-for-bit for non-batched callers.
Other DiTs (HunyuanVideo, LongCat, ...) unaffected.
0 commit comments