Skip to content

Commit c591d6d

Browse files
[feat] [2/n] Improve API: add initial support in video_generator (#1220)
1 parent 65dff80 commit c591d6d

7 files changed

Lines changed: 1288 additions & 14 deletions

File tree

examples/inference/basic/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ For an example running DMD+VSA inference:
2828
python examples/inference/basic/basic_dmd.py
2929
```
3030

31+
For the typed config/request path added during the inference API refactor:
32+
```
33+
python examples/inference/basic/basic_dmd_new_api.py
34+
```
35+
3136
## Basic Walkthrough
3237

3338
All you need to generate videos using multi-gpus from state-of-the-art diffusion pipelines is the following few lines!
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import os
2+
import time
3+
4+
from fastvideo import VideoGenerator
5+
from fastvideo.api import (
6+
EngineConfig,
7+
GenerationRequest,
8+
GeneratorConfig,
9+
OffloadConfig,
10+
OutputConfig,
11+
PipelineSelection,
12+
)
13+
14+
OUTPUT_PATH = "video_samples_dmd2_typed"
15+
16+
17+
def main():
18+
os.environ["FASTVIDEO_ATTENTION_BACKEND"] = "VIDEO_SPARSE_ATTN"
19+
20+
model_name = "FastVideo/FastWan2.1-T2V-1.3B-Diffusers"
21+
generator_config = GeneratorConfig(
22+
model_path=model_name,
23+
engine=EngineConfig(
24+
num_gpus=1,
25+
use_fsdp_inference=False,
26+
offload=OffloadConfig(
27+
text_encoder=True,
28+
pin_cpu_memory=True,
29+
dit=False,
30+
vae=False,
31+
),
32+
),
33+
# PR 2 still routes a few advanced inference knobs through the
34+
# compatibility bridge until they get first-class typed fields.
35+
pipeline=PipelineSelection(
36+
experimental={
37+
"VSA_sparsity": 0.8,
38+
},
39+
),
40+
)
41+
42+
load_start_time = time.perf_counter()
43+
generator = VideoGenerator.from_config(generator_config)
44+
load_end_time = time.perf_counter()
45+
load_time = load_end_time - load_start_time
46+
47+
prompt = (
48+
"A neon-lit alley in futuristic Tokyo during a heavy rainstorm at night. "
49+
"The puddles reflect glowing signs in kanji, advertising ramen, karaoke, "
50+
"and VR arcades. A woman in a translucent raincoat walks briskly with an "
51+
"LED umbrella. Steam rises from a street food cart, and a cat darts "
52+
"across the screen. Raindrops are visible on the camera lens, creating "
53+
"a cinematic bokeh effect."
54+
)
55+
request = GenerationRequest(
56+
prompt=prompt,
57+
output=OutputConfig(
58+
output_path=OUTPUT_PATH,
59+
save_video=True,
60+
return_frames=False,
61+
),
62+
)
63+
64+
start_time = time.perf_counter()
65+
result = generator.generate(request)
66+
end_time = time.perf_counter()
67+
gen_time = end_time - start_time
68+
69+
prompt2 = (
70+
"A majestic lion strides across the golden savanna, its powerful frame "
71+
"glistening under the warm afternoon sun. The tall grass ripples gently "
72+
"in the breeze, enhancing the lion's commanding presence. The tone is "
73+
"vibrant, embodying the raw energy of the wild. Low angle, steady "
74+
"tracking shot, cinematic."
75+
)
76+
request2 = GenerationRequest(
77+
prompt=prompt2,
78+
output=OutputConfig(
79+
output_path=OUTPUT_PATH,
80+
save_video=True,
81+
return_frames=False,
82+
),
83+
)
84+
85+
start_time = time.perf_counter()
86+
result2 = generator.generate(request2)
87+
end_time = time.perf_counter()
88+
gen_time2 = end_time - start_time
89+
90+
print(f"Time taken to load model: {load_time} seconds")
91+
print(f"Time taken to generate video: {gen_time} seconds")
92+
print(f"First output written to: {result.video_path}")
93+
print(f"Time taken to generate video2: {gen_time2} seconds")
94+
print(f"Second output written to: {result2.video_path}")
95+
96+
97+
if __name__ == "__main__":
98+
main()

fastvideo/api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
load_serve_config,
3131
parse_config,
3232
)
33+
from fastvideo.api.results import GenerationResult
3334

3435
__all__ = [
3536
"CompileConfig",
3637
"ComponentConfig",
3738
"ContinuationState",
3839
"ConfigValidationError",
3940
"EngineConfig",
41+
"GenerationResult",
4042
"GenerationPlan",
4143
"GenerationRequest",
4244
"GeneratorConfig",

0 commit comments

Comments
 (0)