Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ hide:
</a>
</div>

## Models

<div class="tx-landing__highlights_grid">
<a href="/examples/models/wan22"
class="feature-cell sky">
<h3>
Wan2.2
</h3>

<p>
Use Wan2.2 to generate videos from text
</p>
</a>
</div>


<!-- ## Misc

<div class="tx-landing__highlights_grid">
Expand Down
Empty file.
1 change: 1 addition & 0 deletions docs/overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<a href="/examples#distributed-training" class="tx-footer__section-link">Distributed training</a>
<a href="/examples#clusters" class="tx-footer__section-link">Clusters</a>
<a href="/examples#inference" class="tx-footer__section-link">Inference</a>
<a href="/examples#models" class="tx-footer__section-link">Models</a>
</div>

<div class="tx-footer__section">
Expand Down
63 changes: 63 additions & 0 deletions examples/models/wan22/.dstack.yml
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
142 changes: 142 additions & 0 deletions examples/models/wan22/README.md
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
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator Author

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?

Copy link
Copy Markdown
Contributor

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?

$ 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"}.
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ nav:
- TPU: examples/accelerators/tpu/index.md
- Intel Gaudi: examples/accelerators/intel/index.md
- Tenstorrent: examples/accelerators/tenstorrent/index.md
- Models:
- Wan2.2: examples/models/wan22/index.md
- Changelog: blog/changelog.md
- Case studies: blog/case-studies.md
- Benchmarks: blog/benchmarks.md
Expand Down
Loading