import torch from diffusers import HunyuanVideoFramepackPipeline, HunyuanVideoFramepackTransformer3DModel from diffusers.hooks import apply_group_offloading from diffusers.utils import export_to_video, load_image from transformers import SiglipImageProcessor, SiglipVisionModel transformer = HunyuanVideoFramepackTransformer3DModel.from_pretrained( "/mnt/workspace/checkpoints/lllyasviel/FramePack_F1_I2V_HY_20250503", torch_dtype=torch.bfloat16 ) feature_extractor = SiglipImageProcessor.from_pretrained( "/mnt/workspace/checkpoints/lllyasviel/flux_redux_bfl", subfolder="feature_extractor" ) image_encoder = SiglipVisionModel.from_pretrained( "/mnt/workspace/checkpoints/lllyasviel/flux_redux_bfl", subfolder="image_encoder", torch_dtype=torch.float16 ) pipe = HunyuanVideoFramepackPipeline.from_pretrained( "/mnt/workspace/checkpoints/hunyuanvideo-community/HunyuanVideo", transformer=transformer, feature_extractor=feature_extractor, image_encoder=image_encoder, torch_dtype=torch.float16, ) onload_device = torch.device("cuda") offload_device = torch.device("cpu") list(map( lambda x: apply_group_offloading(x, onload_device, offload_device, offload_type="leaf_level", use_stream=True, low_cpu_mem_usage=True), [pipe.text_encoder, pipe.text_encoder_2, pipe.transformer] )) pipe.image_encoder.to(onload_device) pipe.vae.to(onload_device) pipe.vae.enable_tiling() image = load_image("penguin.png") output = pipe( image=image, prompt="A penguin dancing in the snow", height=832, width=480, num_frames=91, num_inference_steps=30, guidance_scale=9.0, generator=torch.Generator().manual_seed(0), sampling_type="vanilla", ).frames[0] print(f"Max memory: {torch.cuda.max_memory_allocated() / 1024**3:.3f} GB") export_to_video(output, "output.mp4", fps=30)