Skip to content

[Qwen3] StateDictAdapter support for MoE model - #1766

Merged
shuhuayu merged 8 commits into
pytorch:mainfrom
shuhuayu:modeldev
Oct 3, 2025
Merged

shuhuayu merged 8 commits into
pytorch:mainfrom
shuhuayu:modeldev

Conversation

@shuhuayu

Copy link
Copy Markdown
Contributor

Reused StateDictAdapter support for DeepSeek V3 model to implement Qwen3 StateDictAdapter. Updated a checkpoint loading api to support distributed huggingface checkpoint loading when unpicklable objects exist.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 27, 2025
@shuhuayu
shuhuayu marked this pull request as draft September 27, 2025 06:02
Comment thread torchtitan/components/checkpoint.py Resolved
@wwwjn

wwwjn commented Sep 27, 2025

Copy link
Copy Markdown
Contributor

Thanks for working on this again! Can you attach a screenshot of your local run after loading HF weights?

@shuhuayu

Copy link
Copy Markdown
Contributor Author

Thanks for working on this again! Can you attach a screenshot of your local run after loading HF weights?

Sure, here is a local run after loading weights from huggingface Qwen/Qwen3-30B-A3B-Instruct-2507 model:

image

@shuhuayu
shuhuayu marked this pull request as ready for review September 28, 2025 07:37
@shuhuayu
shuhuayu marked this pull request as draft September 28, 2025 22:58
Comment thread torchtitan/components/checkpoint.py Resolved
Comment thread torchtitan/models/utils.py Resolved
Comment thread torchtitan/models/utils.py Resolved
@vwxyzjn

vwxyzjn commented Oct 1, 2025

Copy link
Copy Markdown

@shuhuayu nice PR! The loss and grad norms looks a bit high though -- any idea why?

Another good way to validate the implementation is to run inference to check if you can get the same output tokens as the HF implementaiton.

@shuhuayu
shuhuayu marked this pull request as ready for review October 1, 2025 23:23
@shuhuayu

shuhuayu commented Oct 1, 2025 •

Copy link
Copy Markdown
Contributor Author

@shuhuayu nice PR! The loss and grad norms looks a bit high though -- any idea why?

Another good way to validate the implementation is to run inference to check if you can get the same output tokens as the HF implementaiton.

@vwxyzjn Thanks for the suggestion! I guess the large losses and gradient norms may be due to the suboptimal training configs we set for debug. We have verified the KL Divergence between a huggingface model and a converted torchtitan model on Qwen3 30B-A3B.

test

@tianyu-l tianyu-l left a comment

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.

LGTM
In the future, we should consider adding unit tests for MoEStateDictAdapter.

Comment thread torchtitan/models/utils.py Resolved
Comment thread torchtitan/models/utils.py Resolved
@shuhuayu
shuhuayu merged commit 4409c13 into pytorch:main Oct 3, 2025
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
Reuse StateDictAdapter support for DeepSeek V3 model to implement Qwen3 StateDictAdapter. Move the common features of MoE state dict adapter to the subclass MoEStateDictAdapter in torchtitan/models/utils.py.
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
Reuse StateDictAdapter support for DeepSeek V3 model to implement Qwen3 StateDictAdapter. Move the common features of MoE state dict adapter to the subclass MoEStateDictAdapter in torchtitan/models/utils.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants