Add Mistral3 vision-language model support (For Flux2 Migration) #3246
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
This PR adds support for the Mistral3 (Mistral-Small-3.x) vision-language model to candle-transformers. Mistral3 combines the Pixtral vision encoder with the Mistral language model, enabling multimodal image-text understanding.
Changes
New files in
candle-transformers/src/models/mistral3/:mod.rs- Module exports and documentationconfig.rs-Mistral3Configwith vision, text, and projector settingsmodel.rs-Mistral3ModelandMistral3ForConditionalGenerationpatch_merger.rs-PatchMergerfor reducing image tokensprojector.rs-MultiModalProjector(RMSNorm + PatchMerger + MLP)Modified files:
candle-transformers/src/models/mod.rs- Addedmistral3module exportcandle-transformers/src/models/pixtral/vision_model.rs- Addedforward_with_hidden_states()andVisionModelOutputstructcandle-transformers/src/models/mistral.rs- Addedforward_embeds_hidden()for multimodal integrationArchitecture
Key Implementation Details
PatchMerger: Uses
reshape + permuteto implement PyTorch'sunfoldoperation (kernel_size == stride, no overlap), merging 2x2 patches into one.Image Token Replacement: Implements
replace_image_tokens()as Candle equivalent of PyTorch'smasked_scatter.Vision Tower Integration: Uses
forward_with_hidden_states()to get batch-dimension-preserved output matching PyTorch Transformers behavior.Supported Models
Differences from Pixtral LLaVA
Usage
Verification
The implementation has been verified against PyTorch Transformers reference:
Checklist