Repository navigation
Support Mistral Multimodal Embed for text and image embeddings - #3654
Merged
inureyes merged 4 commits intoDec 2, 2026
Merged
Conversation
…bution Include top-level `text_vocab_size` in `resolve_vocab_size` so Mistral Multimodal Embed checkpoints enforce token-id bounds even without an HF tokenizer fallback, and add a unit test in `src/embeddings/limits_tests.rs`. Add a unit test in `src/embeddings/engine_tests.rs` verifying `EmbeddingEngine::embed_tokens` rejects rows missing `required_eos_token()` with `InvalidRow` and the offending index. Complete per-file third-party attribution URLs and `NOTICE` pointers in `src/models/mistral_contrastive.rs` and `src/vision/dense/preprocess.rs`. Validated with 244 `mistral_contrastive`/`preprocess`/`embeddings` unit tests, `cargo fmt --check`, and a real Metal `mlxcel-server --embeddings` test on `nativ-community/Mistral-Multimodal-Embed-1B-4bit` (raw norms 224.3538 text / 27.8373 image_url, matching caption cosine 0.2210 vs unrelated 0.0158, missing-EOS HTTP 400). Refs lablup#3631, lablup#3654
inureyes
force-pushed
the
feat/mistral-contrastive-3631
branch
from
December 2, 2026 00:24
7ab3e1f to
6655c57
Compare
Member
Implementation Hardening SummaryAudited PR #3654 against issue #3631 across the Mistral Multimodal Embed dual encoder, image preprocessing, embedding engine, and HTTP routes. Findings & Fixes
Validation
|
This was referenced Dec 2, 2026
inureyes
added a commit
that referenced
this pull request
Dec 2, 2026
Parallel `cargo test --features cuda --lib -- --test-threads=4` aborted in most runs with "invalid memory registered when calling <op>::eval_gpu". The cause is a race in MLX's debug-only CUDA allocation tracker: `move_to_unified_memory` and `move_to_device_memory` freed the old pointer before calling `swap_allocation`, so another thread could be handed that address and track it, and the late swap then moved the live entry away and its next `verify_graph` aborted. A new overlay of `mlx/backend/cuda/allocator.cpp` (base 5a48f9cc) retargets the tracker before the free. Release and test-fast builds define NDEBUG and never ran this code, which is why the merge gates did not see it. MLX-evaluating lib tests now take `mlx_test_guard()` as their first statement, and `tests/mlx_test_guard_coverage.rs` gains a source scan that fails when a test reaches an eval or host readback before taking the guard. Helpers that took their own guard or the device lock were adjusted so nothing deadlocks. CI clippy now also lints examples (about one second of extra time). Main broke several times while this was open, and the branch carries the fixes the verification needed: the diffusing_interval settings classification, LLaVA-OneVision in FAMILY_ORDER, two clippy lints, the WebUI string fixture and bundle, and guards on tests added by #3654, #3657 and #3678. Validation: five consecutive 4-thread CUDA lib runs on GB10 passed (14080 passed, 0 failed each) where the base aborted; the guard scan, family_order, fmt, clippy with examples, the scripts/ci contract checks, the WebUI suite and contract check pass. OpenXLA feature compile fails with the same RUSTFLAGS quoting error as on main. Closes #3660
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.
Closes #3631.
Adds the Mistral contrastive text and image towers, checkpoint detection and loading, and image preprocessing. Both towers return raw 1024-dimensional projections; the embedding engine applies normalization when requested. Pretokenized text must include EOS for pooling.
Validated on Spark1 CUDA with the BF16 (625384b8) and 4-bit (c7cbea8b) exports against mlx-vlm at c745aa70. Text-only, image-only and interleaved requests preserved input order. Across four captions and three images, minimum cosine to reference was 0.999959, and all three images retrieved their matching caption on both exports. Raw projection relative error was below 0.93% across the mixed batch. Both native routes matched the OpenAI route; a token row without EOS returned HTTP 400 with its input index.
Independent review identified normalization being applied inside the towers. The included HTTP regression check failed against that implementation and passed against both rebuilt exports after the correction.