-
Notifications
You must be signed in to change notification settings - Fork 222
Add Wan2.2 example #3029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Wan2.2 example #3029
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| type: task | ||
| name: wan22 | ||
|
|
||
| repos: | ||
| # Clones it to `/workflow` (the default working directory) | ||
| - https://github.com/Wan-Video/Wan2.2.git | ||
|
|
||
| python: 3.12 | ||
| nvcc: true | ||
|
|
||
| env: | ||
| - PROMPT="Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." | ||
| # Required for storing cache on a volume | ||
| - UV_LINK_MODE=copy | ||
| commands: | ||
| # Install flash-attn | ||
| - | | ||
| uv pip install torch | ||
| uv pip install flash-attn --no-build-isolation | ||
| # Install dependencies | ||
| - | | ||
| uv pip install . decord librosa | ||
| uv pip install "huggingface_hub[cli]" | ||
| hf download Wan-AI/Wan2.2-T2V-A14B --local-dir /root/.cache/Wan2.2-T2V-A14B | ||
| # Generate video | ||
| - | | ||
| if [ ${DSTACK_GPUS_NUM} -gt 1 ]; then | ||
| torchrun \ | ||
| --nproc_per_node=${DSTACK_GPUS_NUM} \ | ||
| generate.py \ | ||
| --task t2v-A14B \ | ||
| --size 1280*720 \ | ||
| --ckpt_dir /root/.cache/Wan2.2-T2V-A14B \ | ||
| --dit_fsdp --t5_fsdp --ulysses_size ${DSTACK_GPUS_NUM} \ | ||
| --save_file ${DSTACK_RUN_NAME}.mp4 \ | ||
| --prompt "${PROMPT}" | ||
| else | ||
| python generate.py \ | ||
| --task t2v-A14B \ | ||
| --size 1280*720 \ | ||
| --ckpt_dir /root/.cache/Wan2.2-T2V-A14B \ | ||
| --offload_model True \ | ||
| --convert_model_dtype \ | ||
| --save_file ${DSTACK_RUN_NAME}.mp4 \ | ||
| --prompt "${PROMPT}" | ||
| fi | ||
| # Upload video | ||
| - curl https://bashupload.com/ -T ./${DSTACK_RUN_NAME}.mp4 | ||
|
|
||
| resources: | ||
| gpu: | ||
| name: [H100, H200] | ||
| count: 1..8 | ||
| disk: 300GB | ||
|
|
||
| # Change to on-demand for disabling spot | ||
| spot_policy: auto | ||
|
|
||
| volumes: | ||
| # Cache pip packages and HF models | ||
| - instance_path: /root/dstack-cache | ||
| path: /root/.cache/ | ||
| optional: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # Wan2.2 | ||
|
|
||
| [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. | ||
|
|
||
| ??? info "Prerequisites" | ||
| Once `dstack` is [installed](https://dstack.ai/docs/installation), clone the repo with examples. | ||
|
|
||
| <div class="termy"> | ||
|
|
||
| ```shell | ||
| $ git clone https://github.com/dstackai/dstack | ||
| $ cd dstack | ||
| ``` | ||
|
|
||
| </div> | ||
|
|
||
| ## Define a configuration | ||
|
|
||
| Below is a task configuration that generates a video using Wan2.2, uploads it, and provides the download link. | ||
|
|
||
| <div editor-title="examples/models/wan22/.dstack.yml"> | ||
|
|
||
| ```yaml | ||
| type: task | ||
| name: wan22 | ||
|
|
||
| repos: | ||
| # Clones it to `/workflow` (the default working directory) | ||
| - https://github.com/Wan-Video/Wan2.2.git | ||
|
|
||
| python: 3.12 | ||
| nvcc: true | ||
|
|
||
| env: | ||
| - PROMPT="Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." | ||
| # Required for storing cache on a volume | ||
| - UV_LINK_MODE=copy | ||
| commands: | ||
| # Install flash-attn | ||
| - | | ||
| uv pip install torch | ||
| uv pip install flash-attn --no-build-isolation | ||
| # Install dependencies | ||
| - | | ||
| uv pip install . decord librosa | ||
| uv pip install "huggingface_hub[cli]" | ||
| hf download Wan-AI/Wan2.2-T2V-A14B --local-dir /root/.cache/Wan2.2-T2V-A14B | ||
| # Generate video | ||
| - | | ||
| if [ ${DSTACK_GPUS_NUM} -gt 1 ]; then | ||
| torchrun \ | ||
| --nproc_per_node=${DSTACK_GPUS_NUM} \ | ||
| generate.py \ | ||
| --task t2v-A14B \ | ||
| --size 1280*720 \ | ||
| --ckpt_dir /root/.cache/Wan2.2-T2V-A14B \ | ||
| --dit_fsdp --t5_fsdp --ulysses_size ${DSTACK_GPUS_NUM} \ | ||
| --save_file ${DSTACK_RUN_NAME}.mp4 \ | ||
| --prompt "${PROMPT}" | ||
| else | ||
| python generate.py \ | ||
| --task t2v-A14B \ | ||
| --size 1280*720 \ | ||
| --ckpt_dir /root/.cache/Wan2.2-T2V-A14B \ | ||
| --offload_model True \ | ||
| --convert_model_dtype \ | ||
| --save_file ${DSTACK_RUN_NAME}.mp4 \ | ||
| --prompt "${PROMPT}" | ||
| fi | ||
| # Upload video | ||
| - curl https://bashupload.com/ -T ./${DSTACK_RUN_NAME}.mp4 | ||
|
|
||
| resources: | ||
| gpu: | ||
| name: [H100, H200] | ||
| count: 1..8 | ||
| disk: 300GB | ||
|
|
||
| # Change to on-demand for disabling spot | ||
| spot_policy: auto | ||
|
|
||
| volumes: | ||
| # Cache pip packages and HF models | ||
| - instance_path: /root/dstack-cache | ||
| path: /root/.cache/ | ||
| optional: true | ||
| ``` | ||
|
|
||
| </div> | ||
|
|
||
| You can customize the | ||
|
|
||
| ## Run the configuration | ||
|
|
||
| Once the configuration is ready, run `dstack apply -f <configuration file>`, and `dstack` will automatically provision the | ||
| cloud resources and run the configuration. | ||
|
|
||
| <div class="termy"> | ||
|
|
||
| ```shell | ||
| $ dstack apply -f examples/models/wan22/.dstack.yml | ||
|
|
||
| # BACKEND RESOURCES INSTANCE TYPE PRICE | ||
| 1 datacrunch (FIN-01) cpu=30 mem=120GB disk=200GB H100:80GB:1 (spot) 1H100.80S.30V $0.99 | ||
| 2 datacrunch (FIN-01) cpu=30 mem=120GB disk=200GB H100:80GB:1 (spot) 1H100.80S.30V $0.99 | ||
| 3 datacrunch (FIN-02) cpu=44 mem=182GB disk=200GB H200:141GB:1 (spot) 1H200.141S.44V $0.99 | ||
|
|
||
| ---> 100% | ||
|
|
||
| Uploaded 1 file, 8 375 523 bytes | ||
|
|
||
| wget https://bashupload.com/fIo7l/wan22.mp4 | ||
| ``` | ||
|
|
||
| </div> | ||
|
|
||
| If you want you can override the default GPU, spot policy, and even the prompt via the CLI. | ||
|
|
||
| <div class="termy"> | ||
|
|
||
| ```shell | ||
| $ PROMPT=... | ||
| $ dstack apply -f examples/models/wan22/.dstack.yml --spot --gpu H100,H200:8 | ||
|
|
||
| # BACKEND RESOURCES INSTANCE TYPE PRICE | ||
| 1 aws (us-east-2) cpu=192 mem=2048GB disk=300GB H100:80GB:8 (spot) p5.48xlarge $6.963 | ||
| 2 datacrunch (FIN-02) cpu=176 mem=1480GB disk=300GB H100:80GB:8 (spot) 8H100.80S.176V $7.93 | ||
| 3 datacrunch (ICE-01) cpu=176 mem=1450GB disk=300GB H200:141GB:8 (spot) 8H200.141S.176V $7.96 | ||
|
|
||
| ---> 100% | ||
|
|
||
| Uploaded 1 file, 8 375 523 bytes | ||
|
|
||
| wget https://bashupload.com/fIo7l/wan22.mp4 | ||
| ``` | ||
|
|
||
| </div> | ||
|
|
||
| ## Source code | ||
|
|
||
| The source-code of this example can be found in | ||
| [`examples/models/wan22` :material-arrow-top-right-thin:{ .external }](https://github.com/dstackai/dstack/blob/master/examples/models/wan22){:target="_blank"}. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I guess its better to pass $DSTACK_GPUS_NUM instead of hardcoding 8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus we could check the number of GPUs and run single GPU version if its 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean replacing direct torchrun call with an if statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could run it as a task, and yes, have an
if?