Mirrors fastvideo.entrypoints.VideoGenerator (from_config(GeneratorConfig) -> generate( GenerationRequest) -> GenerationResult.video_path), reusing the OFFICIAL fastvideo.api config classes so a basic_dmd_new_api.py-style script differs only by importing VideoGenerator from v2. - model_path -> v2 card registry (Wan2.1 / FastWan -> wan21; SFWan -> wan_causal; LTX2 -> ltx2); snapshot_download + stamp_wan21_checkpoints + Engine(cuda) + program; generate maps SamplingConfig -> DiffusionParams -> make_request -> eng.run, saves the [C,T,H,W] decode as an mp4. - Lazy v2.__getattr__ keeps 'import v2' torch-free (verified) so the CPU mini stays green (202+2). - examples/inference/basic/v2_basic_new_api.py runs all three GPU models through this API. - Single-GPU, resident, TORCH_SDPA (EngineConfig offload/num_gpus>1/VSA accepted for parity, not applied). verified: wan21 from_config->generate->mp4 (frames (5,256,256,3) uint8, video_path written).
88 lines
3.0 KiB
Python
88 lines
3.0 KiB
Python
"""v2 typed-API inference example — mirrors ``basic_dmd_new_api.py`` but drives the **v2
|
|
(recipe, runtime) substrate + real torch backend** for the three models brought up on GPU
|
|
(Wan2.1, SF-causal Wan, LTX-2).
|
|
|
|
The ONLY delta from the upstream example is importing ``VideoGenerator`` from ``v2`` instead of
|
|
``fastvideo`` — the typed config classes are the SAME ``fastvideo.api`` dataclasses.
|
|
|
|
Run (on a GPU box, with the v2 venv active):
|
|
python examples/inference/basic/v2_basic_new_api.py
|
|
|
|
Notes vs upstream: the v2 bring-up runs single-GPU, resident, on the TORCH_SDPA backend (no
|
|
fastvideo-kernel / VSA), so resolutions/steps are modest here for a quick runnable demo. LTX-2 loads
|
|
an 18.88B DiT (slow first load).
|
|
"""
|
|
import os
|
|
import time
|
|
|
|
from v2 import VideoGenerator
|
|
from fastvideo.api import (
|
|
EngineConfig,
|
|
GenerationRequest,
|
|
GeneratorConfig,
|
|
OffloadConfig,
|
|
OutputConfig,
|
|
SamplingConfig,
|
|
)
|
|
|
|
OUTPUT_PATH = "v2_video_samples"
|
|
|
|
MODELS = [
|
|
{
|
|
"family": "wan21",
|
|
"model_path": "Wan-AI/Wan2.1-T2V-1.3B-Diffusers",
|
|
"prompt": "a red panda surfing on ocean waves at sunset, cinematic, highly detailed",
|
|
"sampling": SamplingConfig(num_frames=25, height=480, width=832,
|
|
num_inference_steps=30, guidance_scale=5.0, seed=1, fps=16),
|
|
},
|
|
{
|
|
"family": "wan_causal",
|
|
"model_path": "wlsaidhi/SFWan2.1-T2V-1.3B-Diffusers",
|
|
"prompt": "a cat walking through a sunlit garden, cinematic",
|
|
"sampling": SamplingConfig(num_frames=25, height=480, width=832,
|
|
num_inference_steps=4, guidance_scale=5.0, seed=1, fps=16),
|
|
},
|
|
{
|
|
"family": "ltx2",
|
|
"model_path": "FastVideo/LTX2-Distilled-Diffusers",
|
|
"prompt": "surfers riding ocean waves at sunset, cinematic, highly detailed",
|
|
"sampling": SamplingConfig(num_frames=9, height=512, width=768,
|
|
num_inference_steps=8, guidance_scale=1.0, seed=1, fps=16),
|
|
},
|
|
]
|
|
|
|
|
|
def run_one(m: dict) -> None:
|
|
generator_config = GeneratorConfig(
|
|
model_path=m["model_path"],
|
|
engine=EngineConfig(
|
|
num_gpus=1,
|
|
use_fsdp_inference=False,
|
|
offload=OffloadConfig(text_encoder=False, dit=False, vae=False, pin_cpu_memory=False),
|
|
),
|
|
)
|
|
load_start = time.perf_counter()
|
|
generator = VideoGenerator.from_config(generator_config)
|
|
load_time = time.perf_counter() - load_start
|
|
|
|
request = GenerationRequest(
|
|
prompt=m["prompt"],
|
|
sampling=m["sampling"],
|
|
output=OutputConfig(output_path=OUTPUT_PATH, output_video_name=f"v2_{m['family']}",
|
|
save_video=True, return_frames=False),
|
|
)
|
|
gen_start = time.perf_counter()
|
|
result = generator.generate(request)
|
|
gen_time = time.perf_counter() - gen_start
|
|
|
|
print(f"[{m['family']:10s}] load={load_time:6.1f}s gen={gen_time:6.1f}s -> {result.video_path}")
|
|
|
|
|
|
def main() -> None:
|
|
for m in MODELS:
|
|
run_one(m)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|