Files
hao-ai-lab-FastVideo/v2/tests/test_sampling_defaults.py
T
Will Lin 1fe50c0092 [refactor] v2: group flat top-level into planes; isolate vendored under _vendor/
The v2 top level had grown to ~27 dirs + 13 loose files — half of them
single-concept abstraction shells (memory/ 86 LOC, transport/ 222, parity/ 178,
extend/ 226) and half vendored fastvideo code sitting as peers to the actual v2
design. Regroup to mirror README section 3 "Planes & dependency order":

  core/     enums+types, card, loop, program, parity, request, parallel
            (the model-native contracts; no kernels)
  runtime/  + folded-in substrate: cache, memory, transport, extend
            (the import graph shows only runtime consumes them; compile/cudagraph
            already lived here)
  serving/  + deploy/ (products / fleet)
  _vendor/  all copied fastvideo: models, layers, attention, configs, distributed,
            platforms, api, hooks, logging_utils, third_party + fastvideo_args/
            utils/logger/envs/forward_context — internal layout unchanged, still
            mirrors upstream for diffing

28 dirs + 13 root files -> 8 dirs + 6 root files. Pure mechanical move: 947
absolute-import paths rewritten (v2.X -> v2.{core,runtime,serving,_vendor}.X),
boundary-anchored so platform/ (native dispatch) and platforms/ (vendored CUDA
detect) no longer collide and neither does hooks/ vs extend/. Deleted the empty
v2/loader/. README section 3 + 16 updated; stale test count corrected
(34 files/216 tests -> 22 files/143 tests).

Validated: `import v2` stays torch-free; `v2/run_tests.py` and `pytest v2/tests/`
-> 143 passed, 2 skipped on the numpy toy backend. (On a GPU box force the toy
backend with CUDA_VISIBLE_DEVICES="" or detect() picks cuda.) No external importer
changed — examples use the re-exported `from v2 import VideoGenerator`.
2026-07-04 17:15:34 +00:00

78 lines
3.4 KiB
Python

"""Phase 1a: per-model sampling defaults on the card + the kwargs>SamplingParam>card>generic precedence."""
from types import SimpleNamespace
from v2.core.card import SamplingDefaults
from v2.recipes.ltx2 import build_ltx2_3_card, build_ltx2_base_card, build_ltx2_card
from v2.recipes.wan21 import (
build_wan21_card,
build_wan22_a14b_card,
build_wan22_ti2v_card,
build_wan_t2v_14b_card,
)
from v2.recipes.wan_causal import build_wan_causal_card
from v2.registry import resolve
from v2.video_generator import _resolve_default
def test_wan_t2v_14b_defaults_and_registry():
# Bucket-B port: reuses the Wan recipe/adapter, only defaults differ (720p, flow_shift 5.0).
sd = build_wan_t2v_14b_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.height, sd.width, sd.fps) == (50, 5.0, 720, 1280, 16)
# the HF id resolves to the 14B card via the shared registry (not the 1.3B fallback defaults)
build_card, _ = resolve("Wan-AI/Wan2.1-T2V-14B-Diffusers")
assert build_card().sampling_defaults.height == 720
def test_wan21_defaults():
sd = build_wan21_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.height, sd.width, sd.num_frames, sd.fps) == (50, 3.0, 480, 832, 81, 16)
assert "overexposed" in sd.negative_prompt
def test_wan22_ti2v_defaults():
sd = build_wan22_ti2v_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.height, sd.width, sd.num_frames, sd.fps) == (50, 5.0, 704, 1280, 121, 24)
def test_wan22_a14b_defaults():
sd = build_wan22_a14b_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.fps) == (40, 4.0, 16)
def test_wan_causal_defaults():
sd = build_wan_causal_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.height, sd.width, sd.num_frames, sd.fps) == (4, 1.0, 480, 832, 81, 16)
def test_ltx2_two_stage_defaults():
sd = build_ltx2_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.height, sd.width, sd.num_frames, sd.fps) == (8, 1.0, 1024, 1536, 121, 24)
assert sd.negative_prompt == "" # distilled: empty negative prompt
def test_ltx2_base_defaults():
sd = build_ltx2_base_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.height, sd.width) == (40, 3.0, 512, 768)
assert "blurry" in sd.negative_prompt
def test_ltx2_3_defaults():
sd = build_ltx2_3_card().sampling_defaults
assert (sd.num_steps, sd.guidance_scale, sd.height, sd.width) == (30, 3.0, 512, 768)
assert sd.guidance_per_modality == {"video": 3.0, "audio": 7.0}
def test_resolve_precedence():
sd = SamplingDefaults(num_steps=8, guidance_scale=1.0, height=1024)
# card default used when neither kwargs nor SamplingParam set it (note the num_steps alias)
assert _resolve_default("num_inference_steps", 30, {}, None, sd, "num_steps") == 8
assert _resolve_default("height", 480, {}, None, sd) == 1024
# kwargs override card
assert _resolve_default("num_inference_steps", 30, {"num_inference_steps": 4}, None, sd, "num_steps") == 4
# SamplingParam override (no kwargs) beats card
assert _resolve_default("height", 480, {}, SimpleNamespace(height=720), sd) == 720
# generic fallback when card has no value and nothing else set
assert _resolve_default("width", 832, {}, None, sd) == 832
# empty-string negative prompt is a real value, not "unset"
assert _resolve_default("negative_prompt", None, {}, None, SamplingDefaults(negative_prompt="")) == ""