Files
ComfyUI_Kaggle/notebooks/wan2_2_kaggle_test.ipynb

6.8 KiB

Wan 2.2 (TI2V-5B) — Test Notebook (Kaggle)

This notebook assumes you have already installed dependencies and attached your dataset on Kaggle. It only covers testing the model: loading it, running a text-to-video generation, and an image-to-video generation.

Before running: in the right-hand panel, make sure your dataset is attached and Accelerator is set to GPU (T4 x2 or P100).

1. Check GPU

In [ ]:
!nvidia-smi

2. Set your paths

Edit the variables below to match where your model files live.

  • If you uploaded the Wan 2.2 model as a Kaggle Dataset, it will be mounted under /kaggle/input/<your-dataset-name>/.
  • If you haven't pre-downloaded the weights and want to pull them directly from Hugging Face instead, leave LOCAL_MODEL_PATH as None and the notebook will fall back to downloading Wan-AI/Wan2.2-TI2V-5B-Diffusers automatically.
In [ ]:
# --- EDIT THIS ---
# Set to the folder path of your attached Kaggle dataset if you pre-downloaded the model,
# e.g. "/kaggle/input/wan22-ti2v-5b/Wan2.2-TI2V-5B-Diffusers"
# Leave as None to auto-download from Hugging Face instead.
LOCAL_MODEL_PATH = None

# Where to save generated test videos
OUTPUT_DIR = "/kaggle/working/outputs"

import os
os.makedirs(OUTPUT_DIR, exist_ok=True)

# Quick sanity check of what's available under /kaggle/input
for root, dirs, files in os.walk("/kaggle/input"):
    print(root)

3. Imports

In [ ]:
import torch
from diffusers import WanPipeline
from diffusers.utils import export_to_video, load_image
from IPython.display import Video, display

print("Torch version:", torch.__version__)
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
    print("GPU:", torch.cuda.get_device_name(0))

4. Load the Wan 2.2 model

In [ ]:
model_source = LOCAL_MODEL_PATH if LOCAL_MODEL_PATH else "Wan-AI/Wan2.2-TI2V-5B-Diffusers"
print("Loading model from:", model_source)

pipe = WanPipeline.from_pretrained(
    model_source,
    torch_dtype=torch.bfloat16
)
pipe.to("cuda")

# Keeps VRAM usage safe on Kaggle's T4/P100 GPUs
pipe.enable_model_cpu_offload()

print("Model loaded successfully.")

5. Test — Text-to-Video

Edit prompt below to whatever you want to test.

In [ ]:
prompt = "A golden retriever running on a beach at sunset, cinematic lighting"

t2v_output = pipe(
    prompt=prompt,
    num_frames=49,
    guidance_scale=5.0
).frames[0]

t2v_path = os.path.join(OUTPUT_DIR, "test_t2v_output.mp4")
export_to_video(t2v_output, t2v_path, fps=24)
print("Saved:", t2v_path)
In [ ]:
display(Video(t2v_path, embed=True))

6. Test — Image-to-Video

Set input_image_path to an image in your attached dataset, or use a URL.

In [ ]:
# --- EDIT THIS ---
# Local path to an image from your dataset, e.g. "/kaggle/input/my-images/sample.jpg"
# Or leave as a URL to test with a sample image instead.
input_image_path = "https://images.unsplash.com/photo-1519681393784-d120267933ba"

input_image = load_image(input_image_path)

i2v_prompt = "the scene comes to life with gentle, natural motion"

i2v_output = pipe(
    image=input_image,
    prompt=i2v_prompt,
    num_frames=49,
    guidance_scale=5.0
).frames[0]

i2v_path = os.path.join(OUTPUT_DIR, "test_i2v_output.mp4")
export_to_video(i2v_output, i2v_path, fps=24)
print("Saved:", i2v_path)
In [ ]:
display(Video(i2v_path, embed=True))

7. Notes

  • Both test videos are saved in /kaggle/working/outputs/ — you can download them from the notebook's Output panel after the run finishes (Kaggle auto-saves everything in /kaggle/working/ for you to download as an artifact).
  • If you hit a CUDA out-of-memory error, lower num_frames from 49 to 25, or reduce guidance_scale.
  • Kaggle free GPU sessions have a ~9-12 hour limit and 30 hours/week quota — keep that in mind if you plan to chain this into a longer fine-tuning session later.
  • This notebook only tests the base model. Fine-tuning (LoRA) requires a separate training script and dataset preprocessing step, not covered here.