Repository navigation
Description
Summary
Add Qwen3-Omni MoE support to mlxcel. Checkpoints ship config.json with top-level model_type: qwen3_omni_moe; mlxcel currently has no arm for it in src/models/detection.rs, so loading fails with "Unsupported model type".
Qwen3-Omni is a two-part omni-modal model:
- Thinker: text generation conditioned on text, image, video, and audio inputs. It is a Qwen3-VL-MoE-style stack (ViT with DeepStack, interleaved MRoPE, MoE text decoder) plus an audio encoder whose output frames are scattered into the token stream, exactly like image features.
- Talker + code2wav: speech synthesis from thinker hidden states (a separate MoE decoder, a code predictor, and a codec vocoder).
Staged scope. Stage 1 (this issue) implements the thinker only: text output, with text, image, and audio inputs working end to end through the CLI and server runtime. Video frames may ride along on the existing Qwen video-frame path where it already applies. The talker and all speech output are explicitly out of scope; file a follow-up issue for them (see "Out of scope"). The loader must skip talker weights without erroring.
Current state in mlxcel
No qwen3_omni_moe references exist under src/. Everything needed is adjacent (all paths verified):
src/models/qwen3_vl_moe.rs: MoE text decoder with interleaved MRoPE, DeepStack injection, and per-sequence MRoPE state. The thinker text backbone is architecturally identical; reusemodels::Qwen3VLMoeModelunchanged.src/models/qwen3_moe.rs: source ofSwitchGLU/SwitchLinearused by the MoE layers.src/models/switch_layers.rs: shared MoE machinery, includingstack_individual_experts(per-expert to stacked layout) and the fused single-token decode kernel.src/vision/encoders/qwen3_vl.rs: the Qwen3-VL vision encoder (patch embed, learned interpolated position embedding, DeepStack mergers). The Qwen3-Omni vision tower has the same module set; only config values differ.src/vision/qwen3_vl_moe.rs: the VLM wrapper pattern to copy (embeddings merge,compute_rope_index,LanguageModelimpl with per-sequence MRoPE plumbing viasrc/models/qwen_mrope_state.rs).src/vision/nemotron_h_nano_omni_vl.rs(+src/vision/nemotron_h_nano_omni_vl_tests.rs) andsrc/audio/nemotron_h_nano_omni/: the in-tree audio+vision omni precedent (optional audio bundle on the VLM struct, audio feature extraction, audio placeholder expansion, loader-side audio weight sanitize).src/audio/whisper_mel.rs:resample_to_16kandlog_mel_spectrogram(audio, n_mels); the omni audio front-end consumes 128-bin log-mel features of this style.src/multimodal/qwen_vl.rs(insert_qwen_vl_image_tokens) andsrc/multimodal/vlm_runtime.rs(server-side audio expanders such asexpand_nemotron_h_nano_omni_audio_tokens_for_server; audio embedding call site nearget_input_embeddings_with_audio_and_cache).src/loading/vlm_qwen.rs(load_qwen3_vl_moeis the template),src/loading/vlm.rs(rewrite_qwen3_vl_weight_key,qwen_vl_token_ids,qwen_vl_processor_with_norm),src/loading/vlm_nemotron_h_nano_omni.rs(filter_out_audio_weightsprefix-drop precedent, conv-layout detection precedent).- Server plumbing for
input_audiocontent blocks already exists insrc/server/chat_request.rs(extract_chat_audio_data); the CLI has--audioinsrc/commands/generate_vlm.rs.
Architecture
config.json layout
Top-level keys (defaults in parentheses are the values assumed when the key is absent):
| Key | Default | Stage-1 use |
|---|---|---|
model_type |
"qwen3_omni_moe" |
detection |
thinker_config |
required | everything below |
talker_config, code2wav_config |
present | ignored |
enable_audio_output |
true |
ignored (talker never constructed) |
eos_token_id |
151645 |
generation stop |
im_start_token_id / im_end_token_id |
151644 / 151645 |
chat template |
tts_bos_token_id / tts_eos_token_id / tts_pad_token_id |
151672 / 151673 / 151671 |
ignored (talker) |
thinker_config keys:
| Key | Default |
|---|---|
text_config, vision_config, audio_config |
required sub-objects |
image_token_id |
151655 |
video_token_id |
151656 |
audio_token_id |
151675 |
audio_start_token_id / audio_end_token_id |
151669 / 151670 |
vision_start_token_id / vision_end_token_id |
151652 / 151653 |
user_token_id |
872 |
position_id_per_seconds |
13 |
seconds_per_chunk |
2 |
Note the nesting difference vs qwen3_vl_moe checkpoints: text_config/vision_config/audio_config live under thinker_config, not at the root, and the multimodal token ids live in thinker_config too. qwen_vl_token_ids in src/loading/vlm.rs reads the config root, so the omni loader must read them from the thinker_config object. Each sub-config carries its own model_type string (qwen3_omni_moe_vision_encoder, qwen3_omni_moe_audio_encoder, and a text variant); detection must key only on the top-level qwen3_omni_moe.
thinker_config.text_config (required keys, no defaults unless noted): num_hidden_layers, hidden_size, intermediate_size, num_attention_heads, num_key_value_heads (falls back to num_attention_heads when null), head_dim, vocab_size, rms_norm_eps, rope_theta, max_position_embeddings, num_experts, num_experts_per_tok, decoder_sparse_step, mlp_only_layers, moe_intermediate_size; optional: norm_topk_prob (true), tie_word_embeddings (false), attention_bias (false), hidden_act ("silu"), rope_scaling (when present, rope_scaling.mrope_section applies; when absent, use [24, 20, 20]). This maps 1:1 onto Qwen3VLMoeConfig in src/models/qwen3_vl_moe.rs, including the [24, 20, 20] mrope_section fallback already implemented there.
thinker_config.vision_config defaults: depth 27, hidden_size 1152, intermediate_size 4304, out_hidden_size 2048, num_heads 16, patch_size 16, spatial_merge_size 2, temporal_patch_size 2, in_channels 3, num_position_embeddings 2304, deepstack_visual_indexes [8, 16, 24], hidden_act "gelu_pytorch_tanh", image_size 768, tokens_per_second 2. These deserialize directly into Qwen3VLVisionConfig in src/vision/encoders/qwen3_vl.rs.
thinker_config.audio_config defaults: d_model 1280, encoder_layers 32, encoder_attention_heads 20, encoder_ffn_dim 5120, num_mel_bins 128, output_dim 2048, downsample_hidden_size 480, activation_function "gelu", scale_embedding false, conv_chunksize 500, n_window 50, n_window_infer 800, max_source_positions 1500.
Text decoder (thinker)
Identical to the in-tree Qwen3-VL-MoE text stack; reuse models::Qwen3VLMoeModel as-is. For completeness, per decoder layer with input x of shape (batch, seq, hidden_size):
- Attention:
q_projproduces(batch, seq, num_attention_heads * head_dim), reshaped to(batch, seq, num_attention_heads, head_dim); per-head RMSNormq_norm/k_normover the last axis (head_dim), epsrms_norm_eps; transpose to(batch, num_attention_heads, seq, head_dim). K/V usenum_key_value_heads(GQA). Scalehead_dim^-0.5. No attention bias. - Interleaved MRoPE: position ids have shape
(3, batch, seq)with components ordered[temporal, height, width]; cos/sin are assembled by the interleavedmrope_sectionlayout (InterleavedMRoPEinsrc/models/qwen3_vl_moe.rsimplements this exactly). - MoE MLP: router
gateweight(num_experts, hidden_size); logits(n_tokens, num_experts); softmax over axis -1 (the expert axis) before top-k; top-k =num_experts_per_tokvia argpartition on the same axis; selected scores renormalized by their sum along axis -1 whennorm_topk_probis true; output is the score-weighted sum over the k experts,(n_tokens, hidden_size). A layer is MoE ifflayer_idx not in mlp_only_layersandnum_experts > 0and(layer_idx + 1) % decoder_sparse_step == 0; otherwise a dense SwiGLU MLP withintermediate_size. - DeepStack: after decoder layer
ifori in 0..3, add deepstack featurei(shape(num_merged_patches, hidden_size)) into the hidden states at visual token positions selected by a(batch, seq)boolean mask. Already implemented (deepstack_process).
Position-id construction for mixed sequences: audio placeholder tokens receive ordinary sequential text positions (all three MRoPE components equal); only image/video blocks receive 3D (t, h, w) positions; after a vision block, the next position is max(block positions) + 1. This is exactly compute_rope_index in src/vision/qwen3_vl_moe.rs, which treats every non-image/video token as text, so it needs no change for audio. Decode continuation uses rope_deltas = max_position + 1 - seq_len (existing per-sequence MRoPE state).
Vision encoder (thinker)
Same module set as src/vision/encoders/qwen3_vl.rs; reuse it unchanged with the omni vision_config values. Summary with concrete shapes (hidden 1152, heads 16, head_dim 72):
- Input pixel rows:
(total_patches, in_channels * temporal_patch_size * patch_size * patch_size)=(total_patches, 1536), each row flattened in(channels, temporal, height, width)order. - Patch embed: 3D conv equivalent to a linear of shape
(hidden_size=1152, 1536). - Learned position embedding: table
(num_position_embeddings=2304, 1152)interpreted as a 48x48 grid, bilinearly interpolated per image to the(grid_h, grid_w)patch grid, reordered to spatial-merge window order, added to patch embeddings. - 27 blocks: LayerNorm (eps 1e-6) -> fused-QKV attention (rotary over half of
head_dim: 36 rotary dims, 18 from the row coordinate + 18 from the column coordinate, cos/sin duplicated once along the last axis to cover all 72 dims with the rotate-half convention) -> residual -> LayerNorm -> MLP (linear_fc1to 4304, GELU,linear_fc2back to 1152) -> residual. Attention is block-diagonal per image/frame via cumulative sequence lengths; softmax over axis -1 (the key axis). - Main merger: LayerNorm(1152) -> reshape to
(total_patches / merge^2, 1152 * merge^2)=(n, 4608)->linear_fc1(4608 -> 4608)-> GELU ->linear_fc2(4608 -> out_hidden_size=2048). - DeepStack: after blocks 8, 16, and 24, a dedicated merger with the post-shuffle norm variant (LayerNorm over 4608, applied after the merge reshape) produces one
(num_merged_patches, 2048)feature per index. Encoder output: main features(num_merged_patches, 2048)plus the 3 deepstack features.
Audio encoder (thinker)
New module. Input is a 16 kHz mono waveform converted to a 128-bin log-mel spectrogram at 100 frames/second (hop 160), shape per clip (num_mel_bins=128, L) where L is the true mel frame count (no fixed 30-second padding; a per-clip length/mask carries L).
Pipeline:
-
Chunking: split the time axis into chunks of
2 * n_window = 100frames (1 second); the final chunk keeps the remainder. Stack chunks into(num_chunks, 128, chunk_len)padded to the longest chunk, then add a trailing channel axis for convolution:(num_chunks, height=128 mel, width=chunk_len time, channels=1). -
Conv front-end: three 2D convolutions, each kernel 3x3, stride 2, padding 1, each followed by GELU; channels
1 -> 480 -> 480 -> 480(downsample_hidden_size). Each conv halves both the mel and time axes without = ceil(in / 2), so mel goes128 -> 64 -> 32 -> 16and a full 100-frame chunk's time axis goes100 -> 50 -> 25 -> 13. Chunks are processed in groups ofconv_chunksize(500) to bound memory. Output(num_chunks, 16, t_out, 480). -
Flatten + project: transpose to
(num_chunks, t_out, 480, 16)(time before channels before mel) and reshape to(num_chunks, t_out, 7680); thenconv_out, a bias-free linear(7680 -> d_model=1280). -
Positional embedding: sinusoidal table
(max_source_positions=1500, 1280), first 640 channels sine, last 640 cosine, max timescale 10000; positions restart at 0 for every chunk (each 1-second chunk gets positions0..t_out). This table is computed at construction, never loaded from the checkpoint. -
Frame gather: concatenate per-chunk outputs along time in chunk order and keep the first
out_len(L)frames per clip, giving(total_audio_frames, 1280)whereout_len(L) = 13 * (L / 100) + ceil((L % 100) / 8) (integer division; second term is 0 when L % 100 == 0)i.e. 13 output frames per full second of audio. This formula also drives placeholder expansion (below); implement it once and unit-test it.
-
Transformer: 32 pre-LN encoder layers,
d_model1280, 20 heads (head_dim 64, scale64^-0.5), FFN 5120 with GELU. Per layer: LayerNorm -> self-attention -> residual -> LayerNorm ->fc1/GELU/fc2-> residual. Attention is block-diagonal over windows oft_out_full_chunk * (n_window_infer / (2 * n_window)) = 13 * 8 = 104post-conv frames (8 seconds of audio); a shorter clip or a clip tail forms one smaller window; windows never cross clip boundaries. Attention layout:(1, num_heads=20, frames, head_dim=64), softmax over axis -1. -
Head:
ln_post(LayerNorm 1280) ->proj1(1280 -> 1280)-> GELU ->proj2(1280 -> output_dim=2048). Output(total_audio_frames, 2048), which matches the texthidden_sizeand is scattered directly into the embedding stream.
Embedding merge
inputs_embeds has shape (batch, seq, hidden_size). Audio features are written, in order, into the positions where input_ids == audio_token_id; image features into image_token_id positions; video features into video_token_id positions. The number of placeholder tokens must equal the number of feature rows for each modality; mismatch is a hard error. This is the same masked-scatter the in-tree Qwen wrappers already perform via src/vision/merge.rs.
Processor and placeholder expansion
- Images/videos: identical to the Qwen3-VL pipeline. Smart-resize to multiples of
patch_size * spatial_merge_size = 32; grid(t, h, w)in patch units; tokens per image =t * (h / 2) * (w / 2); normalization mean/std0.5as used byload_qwen3_vl_moe(qwen_vl_processor_with_norm), to be confirmed against the checkpoint'spreprocessor_config.jsonduring real-checkpoint validation. - Audio: resample to 16 kHz, compute the 128-bin log-mel, and expand each audio placeholder to
out_len(L)copies ofaudio_token_id. The chat template frames audio withaudio_start_token_id/audio_end_token_id; when the server splices an audio block into a prompt that has no placeholder (the OpenAIinput_audiopath), emitaudio_start + audio_token * N + audio_endbefore the end-of-turn marker, following the two-strategy pattern ofexpand_nemotron_h_nano_omni_audio_tokens_for_serverinsrc/multimodal/vlm_runtime.rs. position_id_per_secondsandseconds_per_chunkonly matter for interleaving an audio track inside a video (use_audio_in_video), which is out of scope for stage 1.
Implementation plan
- Detection and registration
src/models/detection.rs: add"qwen3_omni_moe" => Ok(ModelType::Qwen3OmniMoe)next to the existing"qwen3_vl_moe"arm; case insrc/models/detection_tests.rs.src/models/mod.rs:ModelType::Qwen3OmniMoevariant plus all registration points (the VLM-type array, the display-name match, e.g.("Qwen3-Omni MoE", "Qwen VLM"), and the type listing used by metadata).src/loaded_model.rs:LoadedModel::Qwen3OmniMoe(vision::Qwen3OmniMoeModel)variant and theLanguageModeldispatch macro arms.
- Text backbone: none. Reuse
models::Qwen3VLMoeModel(src/models/qwen3_vl_moe.rs). - Vision encoder: none. Reuse
Qwen3VLVisionEncoder(src/vision/encoders/qwen3_vl.rs); the omnivision_configdeserializes intoQwen3VLVisionConfigdirectly. - Audio encoder: new submodule
src/audio/qwen3_omni_moe/(per the guidance insrc/audio/mod.rsthat new families get their own namespace):config.rs(serde struct foraudio_configwith the defaults above),encoder.rs(conv front-end, windowed attention, projection head), reusingsrc/audio/whisper_mel.rsfor resampling and log-mel. Register insrc/audio/mod.rs. - VLM wrapper: new
src/vision/qwen3_omni_moe.rs, structQwen3OmniMoeModel { text_model: models::Qwen3VLMoeModel, vision_encoder, audio_tower, processor, image_token_id, video_token_id, audio_token_id, audio_start_token_id, audio_end_token_id, vision_start_token_id, spatial_merge_size }. Copy theLanguageModelimpl and MRoPE/DeepStack plumbing fromsrc/vision/qwen3_vl_moe.rsverbatim; add the audio feature path modeled onget_input_embeddings_full/extract_audio_featuresinsrc/vision/nemotron_h_nano_omni_vl.rs. Register insrc/vision/mod.rs. - Loader:
load_qwen3_omni_moeinsrc/loading/vlm_qwen.rs(the Qwen-family loader home), dispatched fromsrc/loading/mod.rs(ModelType::Qwen3OmniMoe => Some(load_qwen3_omni_moe(model_path)?)). Parsethinker_configand its three sub-configs (parse_required_vlm_subconfigworks one level at a time; fetch thethinker_configobject first). Read token ids fromthinker_configwith the defaults listed above. Weight remap and talker skip per the next section (src/loading/vlm.rs). - Multimodal runtime integration (this is part of stage-1 completion, not optional):
- CLI: image path via
insert_qwen_vl_image_tokens(src/multimodal/qwen_vl.rs); audio path via a new expander wired wheresrc/commands/generate_vlm.rshandles--audiofor the existing omni model. - Server: audio arrives through
extract_chat_audio_data(src/server/chat_request.rs); add the omni arm insrc/multimodal/vlm_runtime.rsbeside the existing audio-capable models (see theget_input_embeddings_with_audio_and_cachecall site) plus a server-side expander as described above. Image content blocks flow through the existing Qwen VLM runtime path.
- CLI: image path via
- Docs: entry in
docs/supported-models.md(Qwen VLM section plus an omni note describing--audioandinput_audiosupport, patterned on the Nemotron-H Nano Omni entry). - Tests: see "Validation and acceptance criteria".
Weight loading and sanitize
Checkpoint key inventory (safetensors)
All linear weights are stored (out_features, in_features); biases (out_features,).
Loaded in stage 1:
| Checkpoint key | Shape | Maps to |
|---|---|---|
thinker.model.embed_tokens.weight |
(vocab_size, hidden_size) |
model.embed_tokens.weight |
thinker.model.layers.{L}.self_attn.{q,k,v,o}_proj.weight |
q: (n_heads*head_dim, hidden), k/v: (n_kv_heads*head_dim, hidden), o: (hidden, n_heads*head_dim) |
model.layers.{L}.self_attn.* |
thinker.model.layers.{L}.self_attn.{q,k}_norm.weight |
(head_dim,) |
same, model. prefix |
thinker.model.layers.{L}.input_layernorm.weight, .post_attention_layernorm.weight |
(hidden_size,) |
same |
thinker.model.layers.{L}.mlp.gate.weight |
(num_experts, hidden_size) |
MoE router |
thinker.model.layers.{L}.mlp.experts.{E}.gate_proj.weight / .up_proj.weight |
(moe_intermediate_size, hidden_size) |
stacked, see below |
thinker.model.layers.{L}.mlp.experts.{E}.down_proj.weight |
(hidden_size, moe_intermediate_size) |
stacked, see below |
thinker.model.norm.weight |
(hidden_size,) |
model.norm.weight |
thinker.lm_head.weight |
(vocab_size, hidden_size) |
lm_head.weight (absent when tie_word_embeddings) |
thinker.visual.patch_embed.proj.weight |
see permutations | vision_tower.patch_embed.proj.weight |
thinker.visual.pos_embed.weight |
(2304, 1152) |
vision_tower.pos_embed.weight |
thinker.visual.blocks.{B}.attn.qkv.{weight,bias} |
(3456, 1152) / (3456,), q,k,v concatenated along axis 0 |
vision_tower.blocks.{B}.attn.qkv.* |
thinker.visual.blocks.{B}.attn.proj.{weight,bias}, .norm1/.norm2.{weight,bias}, .mlp.linear_fc1/.linear_fc2.{weight,bias} |
fc1 (4304, 1152), fc2 (1152, 4304) |
vision_tower.blocks.{B}.* |
thinker.visual.merger.{norm,linear_fc1,linear_fc2}.{weight,bias} |
norm (1152,), fc1 (4608, 4608), fc2 (2048, 4608) |
vision_tower.merger.* |
thinker.visual.deepstack_merger_list.{0,1,2}.* |
as merger, but norm is (4608,) (post-shuffle variant) |
vision_tower.deepstack_merger_list.{i}.* |
thinker.audio_tower.conv2d1.weight |
(480, 1, 3, 3) |
permuted, see below |
thinker.audio_tower.conv2d{2,3}.weight |
(480, 480, 3, 3) |
permuted, see below |
thinker.audio_tower.conv2d{1,2,3}.bias |
(480,) |
audio_tower.conv2d{n}.bias |
thinker.audio_tower.conv_out.weight |
(1280, 7680), no bias |
audio_tower.conv_out.weight |
thinker.audio_tower.layers.{A}.self_attn.{q,k,v,out}_proj.{weight,bias} |
(1280, 1280) / (1280,); treat every bias as optional (default zero when absent, some exports omit k_proj.bias) |
audio_tower.layers.{A}.* |
thinker.audio_tower.layers.{A}.self_attn_layer_norm.{weight,bias}, .final_layer_norm.{weight,bias} |
(1280,) |
same |
thinker.audio_tower.layers.{A}.fc1.{weight,bias} / .fc2.{weight,bias} |
(5120, 1280) / (1280, 5120) |
same |
thinker.audio_tower.ln_post.{weight,bias}, .proj1.{weight,bias}, .proj2.{weight,bias} |
proj2 (2048, 1280) |
same |
Skipped in stage 1 (drop by key prefix, immediately after load_vlm_weights_common, before remap, so the arrays are freed; follow the filter_out_audio_weights precedent in src/loading/vlm_nemotron_h_nano_omni.rs):
talker.*(talker decoder,talker.text_projection.*,talker.hidden_projection.*,talker.code_predictor.*, codec embeddings)code2wav.*(codec vocoder)
The loader must not error when these prefixes are absent either (thinker-only exports exist), and must ignore an audio_tower.positional_embedding key if an export materializes the sinusoidal table.
Key remap
New rewrite_qwen3_omni_weight_key in src/loading/vlm.rs beside rewrite_qwen3_vl_weight_key:
thinker.model.->model.thinker.lm_head.->lm_head.thinker.visual.->vision_tower.thinker.audio_tower.->audio_tower.- Merger naming variants: some exports ship
merger.ln_q/merger.mlp.0/merger.mlp.2andmerger_listinstead ofmerger.norm/merger.linear_fc1/merger.linear_fc2/deepstack_merger_list; normalize to the latter.
Expert stacking (known MoE-fusion trap)
SwitchLinear consumes one stacked tensor per projection: mlp.switch_mlp.gate_proj.weight with shape (num_experts, moe_intermediate_size, hidden_size) (down: (num_experts, hidden_size, moe_intermediate_size)), plus .scales/.biases for quantized exports. Real checkpoints ship per-expert keys mlp.experts.{E}.{proj}.weight. The existing rewrite_qwen3_vl_weight_key(_, moe_experts=true) only renames pre-stacked exports; it does not stack per-expert tensors, and the local load_switch_linear in src/models/qwen3_vl_moe.rs only reads the stacked layout. The omni loader must handle both layouts: stack per-expert weights along a new leading axis 0 (expert index order 0..num_experts), or route through SwitchLinear::from_weights in src/models/switch_layers.rs, which already has the stack_individual_experts fallback. Cover both layouts in unit tests; this exact class of bug passes synthetic tests and fails on real checkpoints.
Convolution weight permutations
Checkpoints store convolution weights channels-second; MLX convolutions expect channels-last. Every required permutation, with explicit source and target shapes:
- Audio
conv2d1.weight: stored(out_ch=480, in_ch=1, kH=3, kW=3)-> permute axes(0, 2, 3, 1)->(480, 3, 3, 1)as(out_ch, kH, kW, in_ch). Same permutation forconv2d2/conv2d3:(480, 480, 3, 3)->(480, 3, 3, 480). Guard with a shape check so an already-permuted export is not double-transposed (seenemotron_audio_needs_conv_transposeinsrc/loading/vlm_nemotron_h_nano_omni.rsfor the detection pattern; here the layouts are unambiguous forconv2d1sincein_ch=1, andconv2d2/3are square in channels, so key the decision on theconv2d1layout). - Vision
patch_embed.proj.weight: genuine exports store(out_ch=1152, in_ch=3, kT=2, kH=16, kW=16); some converted exports store(out_ch=1152, kT=2, kH=16, kW=16, in_ch=3).PatchEmbed::from_weightsinsrc/vision/encoders/qwen3_vl.rsexpects the latter (it internally permutes(0, 1, 4, 2, 3)and flattens to a(1152, 1536)matrix whose column order matches the(kT, in_ch, kH, kW)input row layout). The omni sanitize must therefore detect the channels-second layout and permute axes(0, 2, 3, 4, 1):(1152, 3, 2, 16, 16)->(1152, 2, 16, 16, 3). Distinguish the layouts by checking whether the last axis equalsin_channels=3. Unit-test both.
Everything else (linears, norms, embeddings) loads without permutation. models::sanitize_tied_embeddings (src/models/sanitize.rs) should still run for robustness, and bf16 handling is already covered by load_vlm_weights_common.
Validation and acceptance criteria
- Co-located unit tests (same-file
#[cfg(test)]or sibling_tests.rs, as insrc/vision/nemotron_h_nano_omni_vl_tests.rs):out_len(L)audio length formula against hand-computed values (e.g.L=100 -> 13,L=500 -> 65,L=163 -> 13 + ceil(63/8) = 21).- Weight-key remap: prefix rewrites, merger naming variants,
talker.*/code2wav.*dropped, absence tolerated. - Expert stacking: per-expert and pre-stacked layouts produce identical
(num_experts, out, in)tensors. - Conv permutations: both stored layouts for
conv2d1andpatch_embed.proj.weightload to the same effective weights. - Audio placeholder expanders (CLI and server): counts, framing tokens, in-place vs spliced strategies.
- Config parsing: nested
thinker_configextraction, all defaults above, token-id fallbacks.
- Synthetic parity test
tests/qwen3_omni_moe_parity.rs, patterned ontests/paddleocr_vl_parity.rs: construct the audio encoder, vision encoder, and text backbone from small syntheticWeightMaps, run the full wrapper end to end (text + image grid + audio features), and assert output shapes, finite values, placeholder-count consistency, and MRoPE position-id construction for a mixed text/image/audio sequence. - Real-checkpoint smoke test on a real
qwen3_omni_moecheckpoint:- Load through the standard loader path (detection ->
load_qwen3_omni_moe), confirming talker weights are skipped without error and memory stays bounded. - CLI:
generatewith--imageand with--audioproduces coherent, non-degenerate text. - Server:
POST /v1/chat/completionswith animage_urlblock and with aninput_audioblock returns sensible completions through the running server worker.
- Load through the standard loader path (detection ->
Known failure mode, and the actual completion bar: synthetic parity can pass while a real checkpoint breaks on weight-key layout (per-expert vs stacked experts, merger key names, conv layouts), config defaults (nested thinker_config, absent optional keys), tokenizer/chat-template details (placeholder and framing tokens), and MoE fusion. Real-checkpoint load + generate through mlxcel's server/CLI runtime is therefore the completion criterion. This issue is done only when qwen3_omni_moe is integrated into the working runtime end to end (detection, loader, multimodal expanders, CLI, server, docs), not when standalone modules exist.
Out of scope
- Talker and speech output (the talker MoE decoder, its code predictor, and the
code2wavcodec vocoder;enable_audio_output, speaker selection,tts_*tokens, streaming audio responses). Stage 1 dropstalker.*andcode2wav.*weights at load. File a follow-up issue for speech synthesis when stage 1 lands. use_audio_in_video: interleaving a video's audio track with its visual tokens by timestamp (this is whatposition_id_per_secondsandseconds_per_chunkgovern). Audio clips and videos are handled as separate inputs in stage 1.- Quantized-export enablement beyond what the reused
Qwen3VLMoeModel/Qwen3VLVisionEncoderquantization paths already provide (verify on a quantized checkpoint if one is available, but do not block stage 1 on it).
Activity