[refactor]: move examples to generate(request) and from_config
Every example calls VideoGenerator.generate with a nested request instead of generate_video keywords, and passes settings outside the from_pretrained convenience keywords through VideoGenerator.from_config at their typed paths. Each request and generator config equals what the keyword call built. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012M91wnVFmPEvJ9h39r5BH7
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
96b7c0d223
commit
f571621ae7
@@ -57,34 +57,39 @@ def basic_generation():
|
||||
raise FileNotFoundError(f"Video not found at {VIDEO_PATH}. "
|
||||
"Please provide a valid video path.")
|
||||
|
||||
generator = VideoGenerator.from_pretrained(
|
||||
"FastVideo/LongCat-Video-VC-Diffusers",
|
||||
num_gpus=1,
|
||||
use_fsdp_inference=False, # set to True if GPU is out of memory
|
||||
dit_cpu_offload=False,
|
||||
vae_cpu_offload=True,
|
||||
text_encoder_cpu_offload=True,
|
||||
pin_cpu_memory=False,
|
||||
enable_bsa=False,
|
||||
)
|
||||
generator = VideoGenerator.from_config({
|
||||
"model_path": "FastVideo/LongCat-Video-VC-Diffusers",
|
||||
"engine": {
|
||||
"num_gpus": 1,
|
||||
"use_fsdp_inference": False, # set to True if GPU is out of memory
|
||||
"offload": {
|
||||
"dit": False,
|
||||
"vae": True,
|
||||
"text_encoder": True,
|
||||
"pin_cpu_memory": False,
|
||||
},
|
||||
},
|
||||
"pipeline": {"longcat": {"enable_bsa": False}},
|
||||
})
|
||||
|
||||
output_path = "outputs_video/longcat_vc_basic"
|
||||
|
||||
generator.generate_video(
|
||||
prompt=PROMPT,
|
||||
negative_prompt=NEGATIVE_PROMPT,
|
||||
video_path=VIDEO_PATH,
|
||||
num_cond_frames=NUM_COND_FRAMES,
|
||||
output_path=output_path,
|
||||
save_video=True,
|
||||
height=480,
|
||||
width=832,
|
||||
num_frames=93,
|
||||
num_inference_steps=50,
|
||||
fps=15,
|
||||
guidance_scale=4.0,
|
||||
seed=SEED,
|
||||
)
|
||||
generator.generate({
|
||||
"prompt": PROMPT,
|
||||
"negative_prompt": NEGATIVE_PROMPT,
|
||||
"inputs": {"video_path": VIDEO_PATH},
|
||||
"sampling": {
|
||||
"height": 480,
|
||||
"width": 832,
|
||||
"num_frames": 93,
|
||||
"num_inference_steps": 50,
|
||||
"fps": 15,
|
||||
"guidance_scale": 4.0,
|
||||
"seed": SEED,
|
||||
},
|
||||
"output": {"output_path": output_path, "save_video": True},
|
||||
"extensions": {"num_cond_frames": NUM_COND_FRAMES},
|
||||
})
|
||||
|
||||
print(f"\nBasic generation complete! Video saved to: {output_path}")
|
||||
generator.shutdown()
|
||||
@@ -110,36 +115,45 @@ def distill_refine_generation():
|
||||
print("\n[Stage 1] Distilled generation (16 steps, 480p)")
|
||||
print("-" * 40)
|
||||
|
||||
generator = VideoGenerator.from_pretrained(
|
||||
"FastVideo/LongCat-Video-VC-Diffusers",
|
||||
num_gpus=1,
|
||||
use_fsdp_inference=True,
|
||||
dit_cpu_offload=False,
|
||||
vae_cpu_offload=True,
|
||||
text_encoder_cpu_offload=True,
|
||||
pin_cpu_memory=False,
|
||||
enable_bsa=False,
|
||||
lora_path="FastVideo/LongCat-Video-T2V-Distilled-LoRA",
|
||||
lora_nickname="distilled",
|
||||
)
|
||||
generator = VideoGenerator.from_config({
|
||||
"model_path": "FastVideo/LongCat-Video-VC-Diffusers",
|
||||
"engine": {
|
||||
"num_gpus": 1,
|
||||
"use_fsdp_inference": True,
|
||||
"offload": {
|
||||
"dit": False,
|
||||
"vae": True,
|
||||
"text_encoder": True,
|
||||
"pin_cpu_memory": False,
|
||||
},
|
||||
},
|
||||
"pipeline": {
|
||||
"longcat": {"enable_bsa": False},
|
||||
"components": {
|
||||
"lora_path": "FastVideo/LongCat-Video-T2V-Distilled-LoRA",
|
||||
"lora_nickname": "distilled",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
distill_output_path = "outputs_video/longcat_vc_distill"
|
||||
|
||||
generator.generate_video(
|
||||
prompt=PROMPT,
|
||||
negative_prompt=NEGATIVE_PROMPT,
|
||||
video_path=VIDEO_PATH,
|
||||
num_cond_frames=NUM_COND_FRAMES,
|
||||
output_path=distill_output_path,
|
||||
save_video=True,
|
||||
height=480,
|
||||
width=832,
|
||||
num_frames=93,
|
||||
num_inference_steps=16,
|
||||
fps=15,
|
||||
guidance_scale=1.0,
|
||||
seed=SEED,
|
||||
)
|
||||
generator.generate({
|
||||
"prompt": PROMPT,
|
||||
"negative_prompt": NEGATIVE_PROMPT,
|
||||
"inputs": {"video_path": VIDEO_PATH},
|
||||
"sampling": {
|
||||
"height": 480,
|
||||
"width": 832,
|
||||
"num_frames": 93,
|
||||
"num_inference_steps": 16,
|
||||
"fps": 15,
|
||||
"guidance_scale": 1.0,
|
||||
"seed": SEED,
|
||||
},
|
||||
"output": {"output_path": distill_output_path, "save_video": True},
|
||||
"extensions": {"num_cond_frames": NUM_COND_FRAMES},
|
||||
})
|
||||
|
||||
print(f"Distilled generation complete! Video saved to: {distill_output_path}")
|
||||
generator.shutdown()
|
||||
@@ -158,40 +172,53 @@ def distill_refine_generation():
|
||||
|
||||
# Create a new generator with refinement LoRA and BSA enabled
|
||||
# Note: Refinement uses the T2V model (not VC) since it's upscaling the generated video
|
||||
refine_generator = VideoGenerator.from_pretrained(
|
||||
"FastVideo/LongCat-Video-T2V-Diffusers",
|
||||
num_gpus=1,
|
||||
use_fsdp_inference=True,
|
||||
dit_cpu_offload=True,
|
||||
vae_cpu_offload=True,
|
||||
text_encoder_cpu_offload=True,
|
||||
pin_cpu_memory=False,
|
||||
enable_bsa=True,
|
||||
bsa_sparsity=0.875,
|
||||
bsa_chunk_q=[4, 4, 8],
|
||||
bsa_chunk_k=[4, 4, 8],
|
||||
lora_path="FastVideo/LongCat-Video-T2V-Refinement-LoRA",
|
||||
lora_nickname="refinement",
|
||||
)
|
||||
refine_generator = VideoGenerator.from_config({
|
||||
"model_path": "FastVideo/LongCat-Video-T2V-Diffusers",
|
||||
"engine": {
|
||||
"num_gpus": 1,
|
||||
"use_fsdp_inference": True,
|
||||
"offload": {
|
||||
"dit": True,
|
||||
"vae": True,
|
||||
"text_encoder": True,
|
||||
"pin_cpu_memory": False,
|
||||
},
|
||||
},
|
||||
"pipeline": {
|
||||
"longcat": {
|
||||
"enable_bsa": True,
|
||||
"bsa_sparsity": 0.875,
|
||||
"bsa_chunk_q": [4, 4, 8],
|
||||
"bsa_chunk_k": [4, 4, 8],
|
||||
},
|
||||
"components": {
|
||||
"lora_path": "FastVideo/LongCat-Video-T2V-Refinement-LoRA",
|
||||
"lora_nickname": "refinement",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
refine_output_path = "outputs_video/longcat_vc_refine_720p"
|
||||
|
||||
refine_generator.generate_video(
|
||||
prompt=PROMPT,
|
||||
negative_prompt=NEGATIVE_PROMPT,
|
||||
output_path=refine_output_path,
|
||||
save_video=True,
|
||||
refine_from=distill_video_path,
|
||||
t_thresh=0.5,
|
||||
spatial_refine_only=False,
|
||||
num_cond_frames=0, # For refinement, no conditioning frames
|
||||
height=720,
|
||||
width=1280,
|
||||
num_inference_steps=50,
|
||||
fps=30,
|
||||
guidance_scale=1.0,
|
||||
seed=SEED,
|
||||
)
|
||||
refine_generator.generate({
|
||||
"prompt": PROMPT,
|
||||
"negative_prompt": NEGATIVE_PROMPT,
|
||||
"inputs": {"refine_from": distill_video_path},
|
||||
"sampling": {
|
||||
"height": 720,
|
||||
"width": 1280,
|
||||
"num_inference_steps": 50,
|
||||
"fps": 30,
|
||||
"guidance_scale": 1.0,
|
||||
"seed": SEED,
|
||||
},
|
||||
"output": {"output_path": refine_output_path, "save_video": True},
|
||||
"extensions": {
|
||||
"t_thresh": 0.5,
|
||||
"spatial_refine_only": False,
|
||||
"num_cond_frames": 0, # For refinement, no conditioning frames
|
||||
},
|
||||
})
|
||||
|
||||
print(f"Refinement complete! Video saved to: {refine_output_path}")
|
||||
refine_generator.shutdown()
|
||||
|
||||
Reference in New Issue
Block a user