|
1 | 1 | # Wan2.2 |
2 | 2 |
|
3 | | -[Wan2.2](https://github.com/Wan-Video/Wan2.2) is an open-source SOTA foundational video model. This example shows how to run the T2V-A14B model variant via `dstack` for text-to-video generation. |
| 3 | +[Wan2.2 :material-arrow-top-right-thin:{ .external }](https://github.com/Wan-Video/Wan2.2){:target="_blank"} is an open-source SOTA foundational video model. This example shows how to run the T2V-A14B model variant via `dstack` for text-to-video generation. |
4 | 4 |
|
5 | 5 | ??? info "Prerequisites" |
6 | 6 | Once `dstack` is [installed](https://dstack.ai/docs/installation), clone the repo with examples. |
|
14 | 14 |
|
15 | 15 | </div> |
16 | 16 |
|
17 | | -Apply the [configuration](https://github.com/dstackai/dstack/blob/master/examples/models/wan22/dev-env.dstack.yml) to provision a GPU instance and run a dev environment with all the Wan2.2 dependencies installed: |
| 17 | +## Define a configuration |
| 18 | + |
| 19 | +Below is a task configuration that generates a video using Wan2.2, uploads it, and provides the download link. |
| 20 | + |
| 21 | +<div editor-title="examples/models/wan22/.dstack.yml"> |
| 22 | + |
| 23 | +```yaml |
| 24 | +type: task |
| 25 | +name: wan22 |
| 26 | + |
| 27 | +repos: |
| 28 | + # Clones it to `/workflow` (the default working directory) |
| 29 | + - https://github.com/Wan-Video/Wan2.2.git |
| 30 | + |
| 31 | +python: 3.12 |
| 32 | +nvcc: true |
| 33 | + |
| 34 | +env: |
| 35 | + - PROMPT="Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." |
| 36 | + # Required for storing cache on a volume |
| 37 | + - UV_LINK_MODE=copy |
| 38 | +commands: |
| 39 | + # Install flash-attn |
| 40 | + - | |
| 41 | + uv pip install torch |
| 42 | + uv pip install flash-attn --no-build-isolation |
| 43 | + # Install dependencies |
| 44 | + - | |
| 45 | + uv pip install . decord librosa |
| 46 | + uv pip install "huggingface_hub[cli]" |
| 47 | + hf download Wan-AI/Wan2.2-T2V-A14B --local-dir /root/.cache/Wan2.2-T2V-A14B |
| 48 | + # Generate video |
| 49 | + - | |
| 50 | + if [ ${DSTACK_GPUS_NUM} -gt 1 ]; then |
| 51 | + torchrun \ |
| 52 | + --nproc_per_node=${DSTACK_GPUS_NUM} \ |
| 53 | + generate.py \ |
| 54 | + --task t2v-A14B \ |
| 55 | + --size 1280*720 \ |
| 56 | + --ckpt_dir /root/.cache/Wan2.2-T2V-A14B \ |
| 57 | + --dit_fsdp --t5_fsdp --ulysses_size ${DSTACK_GPUS_NUM} \ |
| 58 | + --save_file ${DSTACK_RUN_NAME}.mp4 \ |
| 59 | + --prompt "${PROMPT}" |
| 60 | + else |
| 61 | + python generate.py \ |
| 62 | + --task t2v-A14B \ |
| 63 | + --size 1280*720 \ |
| 64 | + --ckpt_dir /root/.cache/Wan2.2-T2V-A14B \ |
| 65 | + --offload_model True \ |
| 66 | + --convert_model_dtype \ |
| 67 | + --save_file ${DSTACK_RUN_NAME}.mp4 \ |
| 68 | + --prompt "${PROMPT}" |
| 69 | + fi |
| 70 | + # Upload video |
| 71 | + - curl https://bashupload.com/ -T ./${DSTACK_RUN_NAME}.mp4 |
| 72 | + |
| 73 | +resources: |
| 74 | + gpu: |
| 75 | + name: [H100, H200] |
| 76 | + count: 1..8 |
| 77 | + disk: 300GB |
| 78 | + |
| 79 | +# Change to on-demand for disabling spot |
| 80 | +spot_policy: auto |
| 81 | + |
| 82 | +volumes: |
| 83 | + # Cache pip packages and HF models |
| 84 | + - instance_path: /root/dstack-cache |
| 85 | + path: /root/.cache/ |
| 86 | + optional: true |
| 87 | +``` |
| 88 | +
|
| 89 | +</div> |
| 90 | +
|
| 91 | +You can customize the |
| 92 | +
|
| 93 | +## Run the configuration |
| 94 | +
|
| 95 | +Once the configuration is ready, run `dstack apply -f <configuration file>`, and `dstack` will automatically provision the |
| 96 | +cloud resources and run the configuration. |
18 | 97 |
|
19 | 98 | <div class="termy"> |
20 | 99 |
|
21 | 100 | ```shell |
22 | | -$ dstack apply -f examples/models/wan22/dev-env.dstack.yml |
23 | | -Provisioning... |
| 101 | +$ dstack apply -f examples/models/wan22/.dstack.yml |
| 102 | +
|
| 103 | + # BACKEND RESOURCES INSTANCE TYPE PRICE |
| 104 | + 1 datacrunch (FIN-01) cpu=30 mem=120GB disk=200GB H100:80GB:1 (spot) 1H100.80S.30V $0.99 |
| 105 | + 2 datacrunch (FIN-01) cpu=30 mem=120GB disk=200GB H100:80GB:1 (spot) 1H100.80S.30V $0.99 |
| 106 | + 3 datacrunch (FIN-02) cpu=44 mem=182GB disk=200GB H200:141GB:1 (spot) 1H200.141S.44V $0.99 |
| 107 | +
|
24 | 108 | ---> 100% |
| 109 | +
|
| 110 | +Uploaded 1 file, 8 375 523 bytes |
| 111 | +
|
| 112 | +wget https://bashupload.com/fIo7l/wan22.mp4 |
25 | 113 | ``` |
26 | 114 |
|
27 | 115 | </div> |
28 | 116 |
|
29 | | -Then you can attach to the dev environment and generate videos: |
| 117 | +If you want you can override the default GPU, spot policy, and even the prompt via the CLI. |
30 | 118 |
|
31 | 119 | <div class="termy"> |
32 | 120 |
|
33 | 121 | ```shell |
34 | | -$ torchrun --nproc_per_node=8 generate.py --task t2v-A14B --size 1280*720 --ckpt_dir ./Wan2.2-T2V-A14B --dit_fsdp --t5_fsdp --ulysses_size 8 --prompt "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." |
| 122 | +$ PROMPT=... |
| 123 | +$ dstack apply -f examples/models/wan22/.dstack.yml --spot --gpu H100,H200:8 |
35 | 124 |
|
36 | | -[2025-08-26 05:41:54,911] INFO: Input prompt: Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage. |
37 | | -[2025-08-26 05:41:54,912] INFO: Creating WanT2V pipeline. |
38 | | -[2025-08-26 05:42:50,296] INFO: loading ./Wan2.2-T2V-A14B/models_t5_umt5-xxl-enc-bf16.pth |
| 125 | + # BACKEND RESOURCES INSTANCE TYPE PRICE |
| 126 | + 1 aws (us-east-2) cpu=192 mem=2048GB disk=300GB H100:80GB:8 (spot) p5.48xlarge $6.963 |
| 127 | + 2 datacrunch (FIN-02) cpu=176 mem=1480GB disk=300GB H100:80GB:8 (spot) 8H100.80S.176V $7.93 |
| 128 | + 3 datacrunch (ICE-01) cpu=176 mem=1450GB disk=300GB H200:141GB:8 (spot) 8H200.141S.176V $7.96 |
| 129 | + |
| 130 | +---> 100% |
| 131 | +
|
| 132 | +Uploaded 1 file, 8 375 523 bytes |
| 133 | +
|
| 134 | +wget https://bashupload.com/fIo7l/wan22.mp4 |
39 | 135 | ``` |
40 | 136 |
|
41 | 137 | </div> |
| 138 | + |
| 139 | +## Source code |
| 140 | + |
| 141 | +The source-code of this example can be found in |
| 142 | +[`examples/models/wan22` :material-arrow-top-right-thin:{ .external }](https://github.com/dstackai/dstack/blob/master/examples/models/wan22){:target="_blank"}. |
0 commit comments