Skip to content

Add native WeMM-Video multimodal inference - #2776

Open
Blaizzy wants to merge 7 commits into
mainfrom
codex/wemm-video
Open

Blaizzy wants to merge 7 commits into
mainfrom
codex/wemm-video

Conversation

@Blaizzy

@Blaizzy Blaizzy commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Tencent's WeMM-Video checkpoints extend Qwen3.5 with a Whisper encoder and windowed Q-Former. Dense checkpoints still advertise qwen3_5, so the existing loader misses the audio architecture and synchronized video/audio preprocessing.

Solution

Add native MLX WeMM-Video support for text, image, audio, video, and video-with-audio inputs, producing text. Reuse the dense/MoE Qwen3.5 backbones, implement the Whisper/Q-Former path, and preserve video paths for soundtrack extraction and timestamp alignment. Include checkpoint conversion, processor dispatch, usage examples, and shared parameterized model/processor tests. Dense and MoE configurations reuse the JSON model cases; loading and serialization share coverage with Qwen processors. Tests use generated inputs without checked-in reference fixtures. Use model_type: wemm_video for normalized MLX checkpoint configs and register the processor through the existing install_auto_processor_patch helper. Remove upstream auto_map entries during normalization. get_model_type, load_processor, and models/base.py retain their original implementations; the only shared utility change preserves video paths and metadata for processors that handle their own video loading. Tencent source configs must be normalized locally before loading or conversion; the model README includes the steps. The native processor loads without prompting to execute upstream code.

Validation

  • 1,317 tests passed, 1 skipped, 53 deselected with the existing EmbeddingGemma2 exclusions. This covers the processor and generation suites, shared model contracts, normalized model routing, sanitization, and media ordering. Black, isort, and autoflake passed.
  • Normalized all eight local MLX 8-bit/4-bit exports across 2B, 4B, 9B, and 35B-A3B. Model routing, native processor loading, tokenizer IDs, and detokenizer selection passed in fresh processes for each export.
  • Fresh normalized 2B and 35B-A3B 4-bit runs passed all five input modes: text, image, audio, video, and video with audio. All ten runs stopped naturally and matched the earlier generated output text exactly, including the existing quality limitations below. BF16 was not rerun in this follow-up because the cached source paths are no longer present.
  • Earlier 60 full-checkpoint runs: all four sizes (2B, 4B, 9B, 35B-A3B), each in BF16, MLX 8-bit, and MLX 4-bit, across all five input modes. All runs produced text without execution errors. Source weight shards were SHA-256 verified; every checkpoint's weight names/shapes matched after sanitization. Pinned revisions and usage are in the model README.
  • M5 Max, 128 GB; MLX 0.32.4; Transformers 5.23.0. The same Apollo 11 media and prompts were used with greedy decoding, reasoning disabled, a 512-token limit, and video sampling at 1 FPS / 4–16 frames / 262,144 total pixels. All 40 BF16/8-bit examples stopped naturally within 512 tokens; 18/20 4-bit examples did. These counts measure stopping, not correctness.
  • Reference comparisons are 2B only: full-size FP32 audio embeddings matched Tencent's implementation with mean cosine similarity 1.0 and maximum absolute difference ~6.2e-4. BF16 greedy PyTorch MPS runs reproduced the standalone-audio transcript and first 128 video-with-audio tokens, including recognition errors. With a 512-token limit, all five BF16 examples reached EOS in both implementations; image/video wording still differs. Audio inference also passed in an environment without PyTorch.
pytest -q mlx_vlm/tests/test_processors.py mlx_vlm/tests/test_generate.py \
  mlx_vlm/tests/test_models.py::test_model_contract \
  mlx_vlm/tests/test_models.py::test_hybrid_backbone_sanitize_is_idempotent \
  mlx_vlm/tests/test_models.py::test_media_features_follow_placeholder_order \
  mlx_vlm/tests/test_models.py::test_get_model_and_args_routes_checkpoint_architectures \
  -k 'not embedding_gemma2'

Limits

The unit tests do not include a stored upstream numerical-parity fixture; reference comparisons above were separate validation runs. These are functional smoke checks, not a standardized accuracy benchmark or full-family reference parity. The 2B 4-bit export answered the arithmetic prompt incorrectly. The 4B 4-bit video-with-audio output repeated through both 512- and 2,048-token limits. The 9B 4-bit video-with-audio output was longer and stopped naturally at 575 tokens with the larger cap. BF16 and 8-bit avoided the arithmetic and repetition failures on these examples, but recognition errors remain. The default conversion keeps the vision/audio encoders in BF16.

EmbeddingGemma2 has existing compatibility failures with the local Transformers 5.23 environment. The latest unfiltered processor/generation run had 13 such failures; all 13 were reproduced on the unchanged prior PR head. The current shared run excludes EmbeddingGemma2.

This branch has not been deployed

No deployments
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.

1 participant