243 lines
6.8 KiB
Plaintext
243 lines
6.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b2c580f4",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Wan 2.2 (TI2V-5B) — Test Notebook (Kaggle)\n",
|
|
"\n",
|
|
"This notebook assumes you have **already installed dependencies and attached your dataset** on Kaggle.\n",
|
|
"It only covers **testing** the model: loading it, running a text-to-video generation, and an image-to-video generation.\n",
|
|
"\n",
|
|
"**Before running:** in the right-hand panel, make sure your dataset is attached and Accelerator is set to **GPU (T4 x2 or P100)**."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "aa60ba24",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 1. Check GPU"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "da64aff1",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"!nvidia-smi"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "af741a96",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 2. Set your paths\n",
|
|
"\n",
|
|
"Edit the variables below to match where your model files live.\n",
|
|
"- If you uploaded the Wan 2.2 model as a Kaggle **Dataset**, it will be mounted under `/kaggle/input/<your-dataset-name>/`.\n",
|
|
"- 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."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "569b64e8",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# --- EDIT THIS ---\n",
|
|
"# Set to the folder path of your attached Kaggle dataset if you pre-downloaded the model,\n",
|
|
"# e.g. \"/kaggle/input/wan22-ti2v-5b/Wan2.2-TI2V-5B-Diffusers\"\n",
|
|
"# Leave as None to auto-download from Hugging Face instead.\n",
|
|
"LOCAL_MODEL_PATH = None\n",
|
|
"\n",
|
|
"# Where to save generated test videos\n",
|
|
"OUTPUT_DIR = \"/kaggle/working/outputs\"\n",
|
|
"\n",
|
|
"import os\n",
|
|
"os.makedirs(OUTPUT_DIR, exist_ok=True)\n",
|
|
"\n",
|
|
"# Quick sanity check of what's available under /kaggle/input\n",
|
|
"for root, dirs, files in os.walk(\"/kaggle/input\"):\n",
|
|
" print(root)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "818966ea",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 3. Imports"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "25cbb788",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import torch\n",
|
|
"from diffusers import WanPipeline\n",
|
|
"from diffusers.utils import export_to_video, load_image\n",
|
|
"from IPython.display import Video, display\n",
|
|
"\n",
|
|
"print(\"Torch version:\", torch.__version__)\n",
|
|
"print(\"CUDA available:\", torch.cuda.is_available())\n",
|
|
"if torch.cuda.is_available():\n",
|
|
" print(\"GPU:\", torch.cuda.get_device_name(0))\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "7ae9448b",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 4. Load the Wan 2.2 model"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2fa2c921",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"model_source = LOCAL_MODEL_PATH if LOCAL_MODEL_PATH else \"Wan-AI/Wan2.2-TI2V-5B-Diffusers\"\n",
|
|
"print(\"Loading model from:\", model_source)\n",
|
|
"\n",
|
|
"pipe = WanPipeline.from_pretrained(\n",
|
|
" model_source,\n",
|
|
" torch_dtype=torch.bfloat16\n",
|
|
")\n",
|
|
"pipe.to(\"cuda\")\n",
|
|
"\n",
|
|
"# Keeps VRAM usage safe on Kaggle's T4/P100 GPUs\n",
|
|
"pipe.enable_model_cpu_offload()\n",
|
|
"\n",
|
|
"print(\"Model loaded successfully.\")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ebabef47",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 5. Test — Text-to-Video\n",
|
|
"\n",
|
|
"Edit `prompt` below to whatever you want to test."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0ab5a843",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"prompt = \"A golden retriever running on a beach at sunset, cinematic lighting\"\n",
|
|
"\n",
|
|
"t2v_output = pipe(\n",
|
|
" prompt=prompt,\n",
|
|
" num_frames=49,\n",
|
|
" guidance_scale=5.0\n",
|
|
").frames[0]\n",
|
|
"\n",
|
|
"t2v_path = os.path.join(OUTPUT_DIR, \"test_t2v_output.mp4\")\n",
|
|
"export_to_video(t2v_output, t2v_path, fps=24)\n",
|
|
"print(\"Saved:\", t2v_path)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "290a6a8f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"display(Video(t2v_path, embed=True))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e6490183",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 6. Test — Image-to-Video\n",
|
|
"\n",
|
|
"Set `input_image_path` to an image in your attached dataset, or use a URL."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "d4c48abb",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# --- EDIT THIS ---\n",
|
|
"# Local path to an image from your dataset, e.g. \"/kaggle/input/my-images/sample.jpg\"\n",
|
|
"# Or leave as a URL to test with a sample image instead.\n",
|
|
"input_image_path = \"https://images.unsplash.com/photo-1519681393784-d120267933ba\"\n",
|
|
"\n",
|
|
"input_image = load_image(input_image_path)\n",
|
|
"\n",
|
|
"i2v_prompt = \"the scene comes to life with gentle, natural motion\"\n",
|
|
"\n",
|
|
"i2v_output = pipe(\n",
|
|
" image=input_image,\n",
|
|
" prompt=i2v_prompt,\n",
|
|
" num_frames=49,\n",
|
|
" guidance_scale=5.0\n",
|
|
").frames[0]\n",
|
|
"\n",
|
|
"i2v_path = os.path.join(OUTPUT_DIR, \"test_i2v_output.mp4\")\n",
|
|
"export_to_video(i2v_output, i2v_path, fps=24)\n",
|
|
"print(\"Saved:\", i2v_path)\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7f19884f",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"display(Video(i2v_path, embed=True))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "04f8b687",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 7. Notes\n",
|
|
"\n",
|
|
"- 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).\n",
|
|
"- If you hit a CUDA out-of-memory error, lower `num_frames` from 49 to 25, or reduce `guidance_scale`.\n",
|
|
"- 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.\n",
|
|
"- This notebook only *tests* the base model. Fine-tuning (LoRA) requires a separate training script and dataset preprocessing step, not covered here."
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"accelerator": "GPU",
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|