Repository navigation
fix(tokenizer): point users at from_hf_hub on unknown model (#229) - #231
Conversation
…i#229) The static MODEL_NAME_TO_TOKENIZER_CLS map only covers older model snapshots. Newer models (mistral-small-3, mistral-medium-3, magistral, saba, ...) fall through to a bare "Unrecognized model: X" which doesn't tell the caller what to do next. Surface the available escape hatches in the error itself — point at MistralTokenizer.from_hf_hub() and .from_file(), and list the known names so typos are obvious.
There was a problem hiding this comment.
Hey thanks for the contribution !
i think that the best would be to simply deprecate this from_model method and indeed point to from_file or from_hf_hub as we won't maintain the model mapping (it's been quite a while ^^)
raising as you did can be kept with minor change
lmk if you'd like to do the iteration otherwise i'll take over in another pr :)
There was a problem hiding this comment.
| f"Unrecognized model: {model!r}. The static mapping in MistralTokenizer.from_model " | |
| f"Unrecognized model: {model}. The static mapping in MistralTokenizer.from_model " |
| raise TokenizerException( | ||
| f"Unrecognized model: {model!r}. The static mapping in MistralTokenizer.from_model " | ||
| f"only covers older model snapshots; newer or custom models should be loaded with " | ||
| f"MistralTokenizer.from_hf_hub(repo_id=...) or MistralTokenizer.from_file(...). " |
There was a problem hiding this comment.
to be consistent
| f"MistralTokenizer.from_hf_hub(repo_id=...) or MistralTokenizer.from_file(...). " | |
| f"MistralTokenizer.from_hf_hub(...) or MistralTokenizer.from_file(...). " |
| # The error should point users at from_hf_hub / from_file so they can | ||
| # handle model snapshots that aren't in the static mapping, and echo | ||
| # the bad name so typos are obvious. |
There was a problem hiding this comment.
| # The error should point users at from_hf_hub / from_file so they can | |
| # handle model snapshots that aren't in the static mapping, and echo | |
| # the bad name so typos are obvious. |
The static MODEL_NAME_TO_TOKENIZER_CLS map isn't kept current with new releases. Mark from_model with a FutureWarning pointing at from_hf_hub and from_file, drop the known-name listing from the unknown-model error (since the map isn't authoritative going forward), and migrate the repo's own callers to .v1() / .v3() or wrap them in pytest.warns so test output stays quiet. Addresses @juliendenize's review on mistralai#231.
|
Really appreciate the thoughtful review @juliendenize :D. The deprecation framing is a much cleaner direction than my original "better error" attempt, and the consistency notes on the suggestion blocks made the diff way tighter. Genuinely learned something from this iteration, so thanks for taking the time on it! Pushed the deprecation:
Local run is green ( |
juliendenize
left a comment
There was a problem hiding this comment.
Thanks for iterating looks good now
Co-authored-by: Julien Denize <40604584+juliendenize@users.noreply.github.com>

`MistralTokenizer.from_model` raises `TokenizerException("Unrecognized model: X")` whenever the model name isn't in `MODEL_NAME_TO_TOKENIZER_CLS`. That mapping only covers older snapshots (latest entry is `2411`), so anything new — `mistral-small-3`, `mistral-medium-3`, `magistral-medium`, `saba`, ... — hits this branch and the caller has no idea what to do next.
This swaps the bare message for one that points at the existing escape hatches and echoes the failing name so typos are obvious:
```text
Unrecognized model: 'mistral-small-3-2501'. The static mapping in
MistralTokenizer.from_model only covers older model snapshots; newer or
custom models should be loaded with MistralTokenizer.from_hf_hub(repo_id=...)
or MistralTokenizer.from_file(...). Known names: codestral-2405, codestral-mamba-2407, ...
```
I considered also adding new entries to `MODEL_NAME_TO_TOKENIZER_CLS` for the recent models, but I don't want to guess at the right tokenizer version (v3-tekken vs v7 vs v11 with image config) for each model — that decision really has to come from your side. Happy to send a follow-up once the mapping for the newer snapshots is published.
Refs #229.
Tests
Existing `tests/test_mistral_tokenizer.py::test_from_model` already asserts `TokenizerException` for `"unknown-model"`. Extended it to also assert the message includes the offending name and the two escape hatches:
```
$ pytest tests/test_mistral_tokenizer.py::TestMistralToknizer::test_from_model
1 passed in 0.40s
```