|
| 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() |
0 commit comments