Skip to content

Add HunYuan VL-MoT (hunyuan_vl_mot) VLM model support - #291

Merged
justinchuby merged 11 commits into
mainfrom
add-hunyuan-vl-mot
May 9, 2026
Merged

justinchuby merged 11 commits into
mainfrom
add-hunyuan-vl-mot

Conversation

@justinchuby

@justinchuby justinchuby commented May 8, 2026 •

Copy link
Copy Markdown
Member

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):

  • MoT dual-pathway: separate Q/K/V/O for text vs vision tokens, merged before attention
  • Shared QK norms, YaRN RoPE with alpha/beta scaling, input_ids for modality mask

Vision Encoder (27-block ViT, 1152 hidden, 16 heads):

  • Fused QKV + bias, LayerNorm + bias, patch_size=16, spatial merger (2x2 -> MLP)
  • 16384 position embeddings (128x128 grid)

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

4 passed (decoder prefill, decoder decode, vision_encoder, embedding)

L2 - YAML test case: PASS

testdata/cases/vision-language/hy-embodied-0_5-x.yaml
222 schema tests passed

CLI build with real weights: PASS

mobius build --model tencent/HY-Embodied-0.5-X /tmp/out
Saved decoder to decoder/model.onnx
Saved vision_encoder to vision_encoder/model.onnx
Saved embedding to embedding/model.onnx

Multi-dtype: PASS

float32: 3 models built
float16: 3 models built
bfloat16: 3 models built

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

File Change
src/mobius/models/hunyuan_vl_mot.py New model (~550 lines)
src/mobius/tasks/_hunyuan_vl_mot.py Custom task (adds input_ids for MoT routing)
src/mobius/models/init.py Export HunYuanVLMoTModel
src/mobius/_registry.py Register hunyuan_vl_mot
src/mobius/_configs.py Hardcoded vision config + QKV bias fallback
tests/_test_configs.py Tiny config for L1 tests
testdata/cases/vision-language/hy-embodied-0_5-x.yaml L4/L5 test case (skipped)

@github-actions

github-actions Bot commented May 8, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing f42a4dd → bcc6851

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

github-actions Bot commented May 8, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing f42a4dd → bcc6851

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 107 107 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 53 53 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 61 61 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 58 58 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 98 98 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 59 59 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 61 61 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 58 58 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 408 408 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

@codecov

codecov Bot commented May 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.60618% with 58 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mobius/models/hunyuan_vl_mot.py 73.58% 54 Missing and 2 partials ⚠️
src/mobius/_configs.py 0.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI 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.

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 HunYuanVLMoTModel with separate vision-encoder, embedding, and decoder submodules.
  • Registers hunyuan_vl_mot in the model registry and exports it from mobius.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.

Comment thread src/mobius/models/hunyuan_vl_mot.py Resolved
Comment thread src/mobius/models/hunyuan_vl_mot.py Resolved
Comment thread src/mobius/models/hunyuan_vl_mot.py Resolved
Comment thread src/mobius/models/hunyuan_vl_mot.py Resolved
@justinchuby
justinchuby force-pushed the add-hunyuan-vl-mot branch from d3b6a1f to 84900c0 Compare May 8, 2026 17:50
justinchuby and others added 6 commits May 8, 2026 22:23
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
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
justinchuby force-pushed the add-hunyuan-vl-mot branch from 1265fc5 to 178c9c1 Compare May 8, 2026 22:44
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
justinchuby marked this pull request as ready for review May 9, 2026 01:45
justinchuby and others added 3 commits 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]>
@justinchuby
justinchuby enabled auto-merge (squash) May 9, 2026 01:58
@justinchuby
justinchuby merged commit 970cd41 into main May 9, 2026
18 of 21 checks passed
@justinchuby
justinchuby deleted the add-hunyuan-vl-mot branch May 9, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants