You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: models with max_length=0 in tokenizer config break #685
However, in the tokenizer spec by Hugging Face, it is possible for either of these values to be 0. This does not impact their functioning in transformers tokenizers. When such a model is loaded in fastembed, it will not truncate at all, and crash on longer inputs.
I think an easy fix is that, instead of checking for existence, the tokenizer is checked for non-zero values.
I also have to admit that it takes a little bit of editing to get to a state where you create a tokenizer with max_length = 0, so it's definitely a corner case.
What is the expected behaviour?
Change the check to reject a key if it is not present or 0.
A minimal reproducible example
This is a bit difficult to reproduce, but happens when a tokenizer has a padding module with a fixed length of 0. This can be done to be able to store the padding token on a tokenizer.json without resorting to an external file.
What Python version are you on? e.g. python --version
Fixed on main by bdf6816 (#716). load_tokenizer now rejects a 0, a null,
a non-integer, and the 1e30 placeholder, and picks the stricter of model_max_length and max_length when both are usable. If neither key
gives a usable limit you get a ValueError pointing at the model directory
rather than silently disabled truncation.
This is not in 0.8.0. It ships in the next release.
Thanks for the report, and thanks to @unusdon for the fix in #687.
Activity
joein commentedon Sep 21, 2026
Fixed on main by bdf6816 (#716).
load_tokenizernow rejects a 0, a null,a non-integer, and the
1e30placeholder, and picks the stricter ofmodel_max_lengthandmax_lengthwhen both are usable. If neither keygives a usable limit you get a
ValueErrorpointing at the model directoryrather than silently disabled truncation.
This is not in 0.8.0. It ships in the next release.
Thanks for the report, and thanks to @unusdon for the fix in #687.