-
Notifications
You must be signed in to change notification settings - Fork 3
Add docs for Megatron Wan #38
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
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| ## Megatron WAN 2.1 | ||
|
|
||
| ### Overview | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| WAN 2.1 is an open, large-scale video generative model series focused on high-quality text-to-video and text-to-image generation. This recipe re-implements WAN using [Megatron-Core](https://github.com/NVIDIA/Megatron-LM) to improve training efficiency and scalability via advanced parallelism schemes and throughput optimizations, including data/tensor/sequence/context parallelism and fused kernels (e.g., NVTE fused attention). | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ### Dataset Preparation | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - This recipe uses NVIDIA's [Megatron-Energon](https://github.com/NVIDIA/Megatron-Energon) as an efficient multi-modal data loader. | ||
| - Datasets should be in the WebDataset-compatible format (typically sharded `.tar` archives). Energon efficiently supports large-scale distributed loading, sharding, and sampling for multi-modal pairs (e.g., text-image, text-video). | ||
| - Point `dataset.path` to your WebDataset location or shard pattern (e.g., a directory containing shards). See the Megatron-Energon documentation for format details and advanced options. | ||
|
|
||
|
|
||
| ### Training and Finetuning | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Use `--training-mode` to select the correct flow-matching hyper-parameters: | ||
| - `pretrain`: default pretraining configuration | ||
| - `finetune`: finetuning configuration (uses different flow-matching hyper-parameters) | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Set environment variables like `EXP_NAME` and `CHECKPOINT_DIR` as desired before running. | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### Example: Pretrain WAN 1.3B | ||
| ```bash | ||
| NVTE_FUSED_ATTN=1 torchrun --nproc_per_node=8 examples/megatron/recipes/wan/pretrain_wan.py \ | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --training-mode pretrain \ | ||
| model.tensor_model_parallel_size=1 \ | ||
| model.pipeline_model_parallel_size=1 \ | ||
| model.context_parallel_size=4 \ | ||
| model.crossattn_emb_size=1536 \ | ||
| model.hidden_size=1536 \ | ||
| model.ffn_hidden_size=8960 \ | ||
| model.num_attention_heads=12 \ | ||
| model.num_layers=30 \ | ||
| model.qkv_format=thd \ | ||
| dataset.path=/path/to/dataset \ | ||
| checkpoint.save=/path/to/checkpoint_dir \ | ||
| checkpoint.load=/path/to/checkpoint_dir \ | ||
| checkpoint.load_optim=true \ | ||
| checkpoint.save_interval=200 \ | ||
| optimizer.lr=5e-6 \ | ||
| optimizer.min_lr=5e-6 \ | ||
| train.eval_iters=0 \ | ||
| scheduler.lr_decay_style=constant \ | ||
| scheduler.lr_warmup_iters=0 \ | ||
| model.seq_length=2048 \ | ||
| dataset.seq_length=2048 \ | ||
| train.global_batch_size=2 \ | ||
| train.micro_batch_size=1 \ | ||
| dataset.global_batch_size=2 \ | ||
| dataset.micro_batch_size=1 \ | ||
| logger.log_interval=1 \ | ||
| logger.wandb_project="wan" \ | ||
| logger.wandb_exp_name="${EXP_NAME}" \ | ||
| logger.wandb_save_dir="${CHECKPOINT_DIR}" | ||
| ``` | ||
|
|
||
| #### Finetuning | ||
| - Switch `--training-mode finetune` to enable the finetuning flow-matching setup. Adjust dataset and optimization parameters (learning rate, warmup steps, etc.) as needed for your task and hardware. | ||
|
|
||
| ### Inference | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```bash | ||
| NVTE_FUSED_ATTN=1 torchrun --nproc_per_node=1 examples/megatron/recipes/wan/inference_wan.py \ | ||
| --task t2v-1.3B \ | ||
| --sizes 480*832 \ | ||
| --checkpoint_dir /path/to/checkpoint \ | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --checkpoint_step 0 \ | ||
| --frame_nums 81 \ | ||
| --prompts "Two anthropomorphic cats in comfy boxing gear and bright gloves fight intensely on a spotlighted stage." \ | ||
| --tensor_parallel_size 1 \ | ||
| --context_parallel_size 1 \ | ||
| --pipeline_parallel_size 1 \ | ||
| --sequence_parallel False \ | ||
| --base_seed 42 \ | ||
| --sample_steps 50 | ||
| ``` | ||
|
|
||
| ### Parallelism Support | ||
| The table below shows current parallelisms support for corresponding Wan model size. | ||
|
|
||
| | Model | Data Parallel | Tensor Parallel | Sequence Parallel | Pipeline Parallel | Context Parallel | FSDP | | ||
| |---|---|---|---|---|---|---| | ||
| | **1.3B** | ✅ | ✅ | ✅ | | ✅ | | | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| | **14B** | ✅ | ✅ | ✅ | | ✅ | | | ||
|
|
||
|
|
||
| ### Performance | ||
| The table below shows performances of corresponding Wan model size on a variety of Nvidia hardware (measured by TFLOPs/GPU). | ||
huvunvidia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| | Model | H100 | GB200 | GB300 | | ||
| |---|---|---|---| | ||
| | **1.3B** | | | | | ||
| | **14B** | 308 | 790 | 1000 | | ||
|
|
||
|
|
||
| ### Citation | ||
| ```bibtex | ||
| @article{wan2.1, | ||
| title = {Wan: Open and Advanced Large‐Scale Video Generative Models}, | ||
| author = {Wan Team}, | ||
| year = {2025}, | ||
| note = {Opensource video foundation model series (Wan 2.1), https://github.com/Wan-Video/Wan2.1/} | ||
| } | ||
| ``` | ||
|
|
||
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.
Move this to docs please