Repository navigation
Add a tiny Qwen4 MoE model - #8774
Open
albertvillanova wants to merge 2 commits into
Open
albertvillanova wants to merge 2 commits into
albertvillanova wants to merge 2 commits into
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds a generation script for
trl-internal-testing/tiny-Qwen4MoeForConditionalGeneration, based onQwen/Qwen4-35B-A3B, and pins its revision.Motivation
Qwen4 (
qwen4_moe) has no tiny model, so no test runs it. It adds sparse attention with a QSA indexer, a per-layer embedding with a dilated short conv, and an n-gram embedding table to the Qwen3.5 MoE layout. The stacked PR runs the trainer tests on it.Changes
qwen4_moe_for_conditional_generation.py, which generatestiny-Qwen4MoeForConditionalGenerationwith the processor and generation config ofQwen/Qwen4-35B-A3B. Qwen4 was added in transformers 5.26.0, which the script pins.Qwen/Qwen4-35B-A3Bis remote code, so the script loads the transformers tokenizer and its chat template from thetokenizer-compatsubfolder, and drops theauto_mapof the image and video processors.tiny-Qwen4MoeForConditionalGenerationinMODEL_REVISIONS.Alignment with the reference
The config diff against
Qwen/Qwen4-35B-A3Bhas 24 keys, all size reductions:num_hidden_layers40 → 4, so the reference pattern (3 linear attention layers, then a sparse attention one) appears once;hidden_size, attention and linear attention heads, experts,hc_lowrank,ple_embed_dimandngram_vocab_size_basereducedsplit_ngram_parts128 → 2, which keeps the n-gram table split into shardsindexer_head_dim128 → 64, the smallest that holds the attention's rotary dims;indexer_budget8, smaller than the test sequences, so the sparse path drops tokensEvery other key is the same as the reference. All tensors have the reference dtype, and the chat template and generation config are the reference's.
The tiny model was generated with this script at transformers 5.26.0:
Note
Low Risk
Test-only fixture generation and a new pinned Hub revision entry; no production training or runtime logic changes.
Overview
Adds a tiny Qwen4 MoE VLM test fixture by introducing
scripts/generate_tiny_models/for_conditional_generation/qwen4_moe_for_conditional_generation.py, which buildstrl-internal-testing/tiny-Qwen4MoeForConditionalGenerationfromQwen/Qwen4-35B-A3Bwith heavily shrunk text/vision configs while preserving Qwen4-specific structure (4 layers with 3 linear + 1 sparse attention, MoE experts, n-gram shards, indexer budget small enough to exercise sparse token dropping). The script requires transformers 5.26.0, loads tokenizer/chat template fromtokenizer-compat(avoids remote-code root tokenizer), stripsauto_mapfrom image/video processors before assemblingQwen3VLProcessor, then runs the usual smoke/dtype/config checks and Hub push.Registers the generated Hub artifact in
MODEL_REVISIONSintests/testing_utils.pyso CI loads a pinned commit.Reviewed by Cursor Bugbot for commit dec6999. Bugbot is set up for automated code reviews on this repo. Configure here.