Skip to content

feat: add Mistral-3 renderer - #172

Open
DIYA73 wants to merge 2 commits into
PrimeIntellect-ai:mainfrom
DIYA73:feat/mistral3-renderer
Open

DIYA73 wants to merge 2 commits into
PrimeIntellect-ai:mainfrom
DIYA73:feat/mistral3-renderer

Conversation

@DIYA73

@DIYA73 DIYA73 commented Oct 4, 2026 •

Copy link
Copy Markdown

What

Hard-coded Python renderer mirroring the Mistral-3 [INST]/[/INST] v3 chat template, following the same pattern as Llama3Renderer.

Covers

  • mistralai/Mistral-Small-3.1-24B-Instruct-2503
  • mistralai/Mistral-Small-3.2-24B-Instruct-2506
  • mistralai/Mistral-Nemo-Instruct-2407

Changes

  • renderers/mistral3.py — Mistral3Renderer with render, parse_response, bridge_to_next_turn
  • renderers/parsing.py — parse_mistral3 (detects [TOOL_CALLS]-anchored tool-call arrays)
  • renderers/configs.py — Mistral3RendererConfig
  • renderers/base.py — MODEL_RENDERER_MAP entries for all three checkpoints
  • renderers/__init__.py — lazy-load registration and __all__
  • tests/parity.py — catalog entry for Mistral-Small-3.1

Validation

uv run pytest tests/ -x -q: 9588 passed, 146 skipped

Note

Add Mistral3Renderer for Mistral-3.x Instruct chat rendering

  • Adds mistral3.py with Mistral3Renderer, which renders system, user, assistant, tool, and ipython messages into the Mistral-3 control-token format and emits assistant tool calls as a JSON array.
  • Adds Mistral3RendererConfig to the RendererConfig union and registers mistral-3 in the renderer and config registries; the Mistral-Small 3.1 Instruct and Mistral-Nemo Instruct model IDs map to it automatically.
  • Adds parse_mistral3 in parsing.py to parse completion text and tool-call JSON after the tool-call marker, with EOS as the only stop token.
  • bridge_to_next_turn reuses a prior prompt through its EOS close and appends new user/tool turns; render accepts tools but does not emit tool definitions, and unsupported roles raise errors.
  • Excludes mistral-3 from several reasoning-boundary test parameterizations in test_reasoning_boundaries.py and adds the Mistral-Small 3.1 checkpoint to the parity catalog with roundtrip and some tool-call suites disabled.
  • Risk: mistral-3 constructs raise errors when required special tokens are missing from the tokenizer vocabulary; check _token_id in mistral3.py if tokenizer load changes.

Macroscope summarized ddecce7.

@awesome-pro

Copy link
Copy Markdown

@DIYA73, tried to run the suite locally against your branch.

Two things actually:

  1. The renderer is never registered, so nothing can construct it. _populate_registry() in renderers/base.py (~L1353) is missing both the from renderers.mistral3 import Mistral3Renderer import and the "mistral-3": Mistral3Renderer entry. Currently:
ValueError: Unknown renderer 'mistral-3'. Available: deepseek-r1, ..., qwen3.8

Adding those two lines moves test_bridge.py from an error to 23 passed.

  1. After that fix the full suite is 61 failed / 11195 passed (main is 11116 passed / 126 skipped). The bulk - 31 - is test_reasoning_boundaries.py[...-mistral-3]: that file builds its case list from every renderer in MODEL_CATALOG and only excludes {"llama-3","default"} (L77 / L199). Since Mistral-3 has no reasoning channel (as your own config docstring says), it should be added to those exclusion sets; llama-3 is the precedent.

Two more things:

  • mistralai/Mistral-Small-3.1-24B-Instruct-2503 has no chat_template on the Hub (tokenizer.chat_template is None), so the parity oracle can't produce a reference. the three test_parity.py failures are "Cannot use chat template functions because tokenizer.chat_template is not set". Either exclude these models from the parity suite with a note, or point the oracle at the Mistral reference.

  • mistralai/Mistral-Small-3.2-24B-Instruct-2506's tokenizer currently fails to load at all (Couldn't instantiate the backend tokenizer, with and without fix_mistral_regex=True), so that mapping can't be verified in CI right now.

@DIYA73

DIYA73 commented Oct 8, 2026

Copy link
Copy Markdown
Author

Thanks for the thorough review. Fixed in 30e004e:

Added Mistral3Renderer import + "mistral-3" entry to _populate_registry()
Added "mistral-3" to all no-reasoning exclusion sets in test_reasoning_boundaries.py (same pattern as llama-3)
Set roundtrip=False for Mistral-Small-3.1 in parity catalog — no chat_template on Hub
Dropped Mistral-Small-3.2 from MODEL_RENDERER_MAP — tokenizer fails to load

Full suite now: 989 passed in test_reasoning_boundaries.py, 0 failed.

@DIYA73
DIYA73 force-pushed the feat/mistral3-renderer branch from 30e004e to b294b3b Compare October 21, 2026 22:48
Hard-coded Python renderer mirroring the Mistral-3 [INST]/[/INST] v3
chat template. Covers:
  - mistralai/Mistral-Small-3.1-24B-Instruct-2503
  - mistralai/Mistral-Small-3.2-24B-Instruct-2506
  - mistralai/Mistral-Nemo-Instruct-2407

Adds Mistral3Renderer, Mistral3RendererConfig, parse_mistral3, and
MODEL_RENDERER_MAP entries for all three checkpoints. Parity test
catalog entry added for Mistral-Small-3.1.
- Register Mistral3Renderer in _populate_registry() (missing import +
  registry entry); without this create_renderer raised ValueError
- Add 'mistral-3' to no-reasoning exclusion sets in
  test_reasoning_boundaries.py (same pattern as 'llama-3')
- Set roundtrip=False for Mistral-Small-3.1 in parity catalog:
  tokenizer.chat_template is None on the Hub so the oracle cannot
  produce a reference rendering
- Drop Mistral-Small-3.2 from MODEL_RENDERER_MAP: tokenizer fails to
  load (backend instantiation error with and without fix_mistral_regex)

Fixes all 4 issues raised in review by awesome-pro.

:wq:wq#
@DIYA73
DIYA73 force-pushed the feat/mistral3-renderer branch from b294b3b to ddecce7 Compare October 29, 2026 22:28

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.

2 participants