Repository navigation
Add Mistral Medium 3.5 training chat template - #7940
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
βΉοΈ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with π while any review is running, comments if it has suggestions, and reacts with π once all reviews finish with no findings. |
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3753dd2e8
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if chat_template == mistral_medium_3_5_chat_template: | ||
| return mistral_medium_3_5_training_chat_template |
There was a problem hiding this comment.
Register Mistral response parsing before enabling tool training
When this processor is passed to GRPOTrainer or DistillationTrainer with tools, the constructors call add_response_schema before reaching this training-template mapping. The new tiny processor is copied directly from the checkpoint without adding a response_template or response_schema, while add_response_schema has no branch for mistral_medium_3_5_chat_template; initialization therefore raises Unrecognized chat template and never reaches either this mapping or the newly fixed _get_tool_suffix_ids path. Add the corresponding response parser mapping and cover the trainer's public initialization path rather than only supports_tool_calling.
AGENTS.md reference: AGENTS.md:L66-L70
Useful? React with πΒ / π.
There was a problem hiding this comment.
Not in this PR. A response parser alone moves the failure further down: GRPO's prompt tokenization also breaks on Pixtral processors, which return tensors, so the tool loop then fails on Tensor + list. Supporting GRPO with tools on Mistral 3 needs both, plus a place in the GRPO VLM tests, so it gets its own PR. This one is about SFT (the training template) and the template checks.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
β¦mplate # Conflicts: # docs/source/chat_templates.md
albertvillanova
left a comment
There was a problem hiding this comment.
Thanks! I checked the stored template against the Hub, the training-template diff, and the new tests on an H100. With the tensor-to-list conversion removed from chat_template_utils.py, 12 of the 13 mistral3 tests fail, so the fix is needed and covered. With assistant_only_loss=True, the mask covers both assistant turns and their </s>, and nothing from the system or user turns.
Two comments:
-
The tiny model is now FP8, and with the current transformers release it can't be trained: LoRA fails with "quantized with fp8 but that quantization method do not support training", and full fine-tuning with "cannot perform fine-tuning on purely quantized models". This PR only loads the processor, so nothing breaks here. With huggingface/transformers#50031, LoRA on the unmodified tiny trains (SFT with
assistant_only_loss=True), so the GRPO tests planned in the follow-up can use a PEFT config and be gated on the transformers release that ships it. -
Nit on the skip reason "Ministral 3 was introduced in transformers-5.0.0": these tests only load the processor, and what needs 5.0 there is the tokenizer. The tiny's tokenizer class is
TokenizersBackend, added in 5.0.0 (huggingface/transformers#40936); on 4.57.6,AutoProcessor.from_pretrainedfails with "Tokenizer class TokenizersBackend does not exist". Maybe "Mistral Medium 3.5 tokenizer requires transformers>=5.0.0", like the GLM4 and LFM2.5 params next to it?
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
β Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b7aa518. Configure here.

Adds Mistral Medium 3.5's chat template (
mistralai/Mistral-Medium-3.5-128B) and its training variant, soassistant_only_loss=Trueworks for it. The original is already prefix-preserving: the training template only wraps the assistant turn (content, tool calls and</s>) in{% generation %}markers.It also fixes processors that return tensors from
apply_chat_template(PixtralProcessordefaults toreturn_tensors="pt"):get_training_chat_templatedied with "Boolean value of Tensor with more than one value is ambiguous" andis_chat_template_stop_token_trainedreturnedFalse. Same unbatching in GRPO's and Distillation's_get_tool_suffix_ids.trl-internal-testing/tiny-Mistral3ForConditionalGeneration(script added), used in the tool-calling and training-template tests.Note
Low Risk
Changes are scoped to chat-template plumbing and VLM processor edge-case handling, with no auth or training-core logic altered beyond safer ID normalization.
Overview
Adds Mistral Medium 3.5 (
mistralai/Mistral-Medium-3.5-128B) to TRLβs bundled chat templates: a referencemistral_medium_3_5.jinjaand a training variant that only wraps the assistant turn (content, tool calls, EOS) in{% generation %}markers, since the base template is already prefix-preserving for GRPO tools.Pixtral / Mistral processors can return
torch.TensorIDs fromapply_chat_templateeven when lists are expected. The PR normalizes those tensors to lists in prefix-preserving checks, stop-token training checks, and GRPO/Distillation_get_tool_suffix_ids, fixing template selection and tool-suffix logic for this family.Docs and
check_chat_templates.pylist the new family; a tiny Mistral3 hub script and test parametrization exercise tool-calling and training-template behavior (transformers β₯ 5.0, vision marks).Reviewed by Cursor Bugbot for commit bc46223. Bugbot is set up for automated code reviews on this repo. Configure here.