v2 had no per-model defaults — generate_video hardcoded 30 steps/25 frames/480x832/cfg5/16fps for every model, badly wrong for e.g. LTX-2 distilled (wants 8 steps @1024x1536) or Wan2.2-TI2V (704x1280@24fps). - New SamplingDefaults dataclass + ModelCard.sampling_defaults (v2/card/specs.py), exported from v2.card. - Populated all 7 supported cards from fastvideo's InferencePreset defaults (steps/guidance/HxW/frames/fps + per-modality guidance for LTX-2.3 A/V). Negative prompts copied verbatim into v2/recipes/_prompts.py (recipe DATA, not model code -> v2-owned, no fastvideo import). - VideoGenerator stores the resolved card; generate_video applies card defaults with precedence kwargs > SamplingParam > card > generic fallback (pure _resolve_default helper, unit-tested). - test_sampling_defaults.py: per-card values + precedence (incl. empty-neg-prompt edge). CPU mini 210 pass, 2 skip.
63 lines
2.9 KiB
Python
63 lines
2.9 KiB
Python
"""Phase 1a: per-model sampling defaults on the card + the kwargs>SamplingParam>card>generic precedence."""
|
|
from types import SimpleNamespace
|
|
|
|
from v2.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
|
|
from v2.recipes.wan_causal import build_wan_causal_card
|
|
from v2.video_generator import _resolve_default
|
|
|
|
|
|
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) == (50, 6.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="")) == ""
|