Repository navigation
Add HunYuan VL-MoT (hunyuan_vl_mot) VLM model support - #291
Merged
Merged
Conversation
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
Performance Comparison
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds initial support for the hunyuan_vl_mot (HunYuan VL-MoT) vision-language model as a 3-model split package (vision encoder, embedding, decoder) integrated into the model registry and test config matrix.
Changes:
- Introduces
HunYuanVLMoTModelwith separate vision-encoder, embedding, and decoder submodules. - Registers
hunyuan_vl_motin the model registry and exports it frommobius.models. - Adds a tiny config entry to the test config set for graph-build coverage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/_test_configs.py |
Adds hunyuan_vl_mot to the test config matrix (tiny vision + VL settings). |
src/mobius/models/hunyuan_vl_mot.py |
Implements the new 3-part VLM model and HF→ONNX weight preprocessing logic. |
src/mobius/models/__init__.py |
Exports HunYuanVLMoTModel from the models package. |
src/mobius/_registry.py |
Registers hunyuan_vl_mot to map to HunYuanVLMoTModel under the vision-language task. |
rui-ren
approved these changes
May 8, 2026
justinchuby
force-pushed
the
add-hunyuan-vl-mot
branch
from
May 8, 2026 17:50
d3b6a1f to
84900c0
Compare
Add support for tencent/HY-Embodied-0.5-X (HunYuanVLMoTForConditionalGeneration) as a 3-model split VLM (decoder + vision_encoder + embedding). Architecture: - Vision encoder: SigLIP-style ViT (27 blocks with fused QKV, LayerNorm) + MLP merger projector - Embedding: token lookup + image feature scatter at placeholder positions - Decoder: 32-layer GQA (16Q/4KV heads, head_dim=128) with QK-norm, reusing TextModel with attn_qk_norm=True Weight handling: - Split fused vision QKV into separate Q/K/V in preprocess_weights - Rename vision fc1/fc2 -> up_proj/down_proj, norm1/norm2 -> layer_norm1/2 - Rename decoder query_layernorm/key_layernorm -> q_norm/k_norm - Strip model.language_model./model.visual. prefixes and route to sub-models - Skip MoT _v pathway weights (text-only decoder for now) Note: The HF model contains Mixture-of-Tokens (MoT) _v-suffixed weights for a visual pathway that routes vision tokens through separate projections per decoder layer. This is not yet implemented — the ONNX decoder uses the standard text pathway only. Full MoT support is future work. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
All weight renames now happen in the top-level preprocess_weights
(sub-model preprocess_weights are not called by the standard flow).
Fixes:
- Strip language_model. prefix before adding decoder. prefix
- Map vision attn.proj → self_attn.out_proj (not attention.out_proj)
- Map pos_embed → position_embedding.weight (add .weight suffix)
- Split fused QKV to self_attn.{q,k,v}_proj
- Skip MoT _v pathway weights at top level
- Handle QK norm renames at top level
Weight matching: 795 preprocessed → 1 unmatched (embed_tokens dup),
4 missing init (rotary caches + unused post_layernorm).
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
HF pos_embed is [1, num_patches, hidden_size] but PatchEmbedding expects [num_patches, hidden_size]. Squeeze dim 0 during preprocess. Verified: ORT inference on decoder produces correct logits shape (1, seq, 120818) with real weights from tencent/HY-Embodied-0.5-X. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
- Remove sub-model preprocess_weights methods from vision encoder, embedding, and decoder classes — these are never called in the standard build flow (top-level preprocess_weights handles all renames) - Remove dead pos_embed replace after early-return block - Remove unused vlm_decoder_weights/vlm_embedding_weights imports - Add docstring notes clarifying weight handling is in top-level class Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Implement the full Mixture-of-Tokens architecture where every decoder layer has parallel text and vision projections: MoT components: - _MoTAttention: Dual Q/K/V/O projections (text + _v), shared QK norms. Q/K/V are merged per-token via Where BEFORE the attention operation so all tokens attend in a shared KV space. O_proj output is routed per-token after attention. - _MoTDecoderLayer: Dual input/post-attention norms, single MoTAttention, dual MLPs with per-token Where routing. - _MoTTextModel: Threads modality_mask through all 32 layers. Custom task (HunYuanVLMoTTask): - Decoder receives input_ids as extra input to derive modality mask (vision tokens identified by image_token_id via Equal op). - Vision encoder and embedding use standard VisionLanguageTask patterns. Weight handling: - _v weights now loaded (no longer skipped): self_attn.q_proj_v, mlp_v.gate_proj, input_layernorm_v, etc. HF names match module names directly. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
…nfig The embedding and decoder models read image_token_id from config.vision.image_token_id, but this field is None when the token ID is set at the top-level ArchitectureConfig (which is the standard pattern in test configs and from_huggingface). Fall back through config.image_token_id first. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
justinchuby
marked this pull request as draft
May 8, 2026 22:29
- Add YAML test case at testdata/cases/vision-language/hy-embodied-0_5-x.yaml with L4+L5 level and skip_reason (HF repo auto_map references missing .py files, model type not in transformers) - Add hardcoded vision encoder config in _configs.py for hunyuan_vl_mot (hidden=1152, 27 blocks, 16 heads, patch=16, image=2048) since the HF config.json has no vision_config sub-object - Set image_token_id from config mask_init_id (12) - Verified: L1 tests pass (4/4), YAML schema validates (222/222), model builds with real weights (3 sub-models), all weights load (only tied embed_tokens unmatched as expected) Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
justinchuby
force-pushed
the
add-hunyuan-vl-mot
branch
from
May 8, 2026 22:44
1265fc5 to
178c9c1
Compare
The generic VisionModel always creates a post_layernorm but the HF model has no such weights. Provide identity LayerNorm (weight=1, bias=0) so the layer is a no-op and CLI export succeeds. Verified: mobius build exports all 3 ONNX models (decoder, vision_encoder, embedding) with real weights to disk successfully. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
justinchuby
marked this pull request as ready for review
May 9, 2026 01:45
Fixes CI model_coverage_test failure — model type was registered but missing from the test model ID mapping. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
The HF repo auto_map references .py files that do not exist. With trust_remote_code=True transformers raises OSError (missing files); with False it raises ValueError (requires custom code). Model type not in transformers 5.7.0. Golden files cannot be generated until the upstream repo or transformers adds native support. Removed trust_remote_code: true (was making things worse — the golden script hardcodes trust_remote_code=True in load_torch_multimodal_model regardless of the YAML field). Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
HF repo auto_map references .py files that don't exist. Model type not in transformers. Cannot load HF reference for golden generation. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
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.
Summary
Add support for HunYuan VL-MoT (HY-Embodied-0.5-X) vision-language model.
Model: tencent/HY-Embodied-0.5-X (3.8B params BF16, ~7.5GB)
Registry key: hunyuan_vl_mot
Task: Custom HunYuanVLMoTTask (3-model VLM split: decoder + vision_encoder + embedding)
Architecture
Decoder (32 layers, 2048 hidden, 16Q/4KV heads, head_dim=128):
Vision Encoder (27-block ViT, 1152 hidden, 16 heads):
Embedding: Token lookup + CumSum-based image feature scatter (mask_init_id=12)
Config Extraction
HF config.json has no vision_config sub-object (flat config). Vision params hardcoded in _configs.py (like phi4mm).
Test Results
L1 - Graph builds: PASS
L2 - YAML test case: PASS
CLI build with real weights: PASS
Multi-dtype: PASS
Weight loading: PASS
All weights loaded. Only 1 unmatched: decoder.model.embed_tokens.weight (expected - tie_word_embeddings=true).
L4/L5 Golden tests: SKIPPED
Reason: HF repo auto_map references configuration_hunyuan_vl_mot.py / modeling_hunyuan_vl_mot.py but those files do not exist in the repo. The hunyuan_vl_mot model type is not in transformers 5.7.0. AutoModelForImageTextToText cannot load the model for HF reference inference. YAML test case has skip_reason documenting this.
Files Changed