Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Commit aa2ecbf

Browse files
author
Huy Vu2
committed
add example
1 parent 057109e commit aa2ecbf

1 file changed

Lines changed: 27 additions & 32 deletions

File tree

examples/megatron/recipes/wan/conversion/convert_checkpoints.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,48 @@
1919
This script demonstrates how to convert models between HuggingFace and Megatron formats
2020
using the AutoBridge import_ckpt and export_ckpt methods.
2121
22-
Features:
23-
- Import HuggingFace models to Megatron checkpoint format
24-
- Export Megatron checkpoints to HuggingFace format
25-
- Support for various model architectures (GPT, Llama, etc.)
26-
- Configurable model and conversion settings
27-
2822
Usage examples:
23+
# Download the HF checkpoint locally
24+
huggingface-cli download Wan-AI/Wan2.1-T2V-1.3B-Diffusers \
25+
--local-dir /root/.cache/huggingface/wan2.1 \
26+
--local-dir-use-symlinks False
27+
2928
# Import a HuggingFace model to Megatron format
30-
python examples/conversion/convert_checkpoints.py import \
31-
--hf-model meta-llama/Llama-3.2-1B \
32-
--megatron-path ./checkpoints/llama3_2_1b
29+
python examples/megatron/recipes/wan/conversion/convert_checkpoints.py import \
30+
--hf-model /root/.cache/huggingface/wan2.1 \
31+
--megatron-path /workspace/checkpoints/megatron_checkpoints/wan_1_3b
3332
3433
# Export a Megatron checkpoint to HuggingFace format
35-
python examples/conversion/convert_checkpoints.py export \
36-
--hf-model meta-llama/Llama-3.2-1B \
37-
--megatron-path ./checkpoints/llama3_2_1b \
38-
--hf-path ./exports/llama3_2_1b_hf
39-
40-
# Import with custom settings
41-
python examples/conversion/convert_checkpoints.py import \
42-
--hf-model ./local_model \
43-
--megatron-path ./checkpoints/custom_model \
44-
--torch-dtype bfloat16 \
45-
--device-map auto
46-
47-
# Export without progress bar (useful for scripting)
48-
python examples/conversion/convert_checkpoints.py export \
49-
--hf-model ./local_model \
50-
--megatron-path ./checkpoints/custom_model \
51-
--hf-path ./exports/custom_model_hf \
52-
--no-progress
34+
python examples/megatron/recipes/wan/conversion/convert_checkpoints.py export \
35+
--hf-model /root/.cache/huggingface/wan2.1 \
36+
--megatron-path /workspace/checkpoints/megatron_checkpoints/wan_1_3b/iter_0000000 \
37+
--hf-path /workspace/checkpoints/hf_checkpoints/wan_1_3b_hf
38+
39+
NOTE: The converted checkpoint /workspace/checkpoints/hf_checkpoints/wan_1_3b_hf
40+
only contains the DiT model transformer weights. You still need other components in
41+
the diffusion pipeline (VAE, text encoders, etc.) to run inference. To do so, you can
42+
duplicate the original HF checkpoint directory /root/.cache/huggingface/wan2.1 (which
43+
contains VAE, text encoders, etc.), and replace ./transformer with
44+
/workspace/checkpoints/hf_checkpoints/wan_1_3b_hf/transformer.
45+
5346
"""
5447

5548
import argparse
49+
import os
50+
import random
5651
import sys
5752
from pathlib import Path
5853
from typing import Optional
5954

6055
import torch
61-
6256
from megatron.bridge import AutoBridge
6357
from megatron.bridge.models.hf_pretrained.wan import PreTrainedWAN
6458
from megatron.bridge.models.wan.wan_bridge import WanBridge
65-
from megatron.bridge.training.model_load_save import save_megatron_model
66-
from megatron.bridge.training.model_load_save import load_megatron_model, temporary_distributed_context
67-
import os
68-
import random
59+
from megatron.bridge.training.model_load_save import (
60+
load_megatron_model,
61+
save_megatron_model,
62+
temporary_distributed_context,
63+
)
6964

7065

7166
def validate_path(path: str, must_exist: bool = False) -> Path:

0 commit comments

Comments
 (0)