T5 sentencepiece tokenizer without precompiled_charsmap cannot be loaded
Author: DRKV333Created Sep 18, 2026Updated Oct 1, 2026
Labelsbug
System Info
transformersversion: 5.18.0.dev0- Platform: Linux-7.1.10-arch1-1-x86_64-with-glibc2.43
- Python version: 3.14.4
- Huggingface_hub version: 1.31.0
- Safetensors version: 0.8.0
- Accelerate version: 1.15.0
- Accelerate config: not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.12.0+rocm7.14.1 (CUDA)
- Using distributed or parallel set-up in script?: No
- Using GPU in script?: No
- GPU type: AMD Radeon RX 7800 XT
Who can help?
@ArthurZucker, @itazap
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - My own task or dataset (give details below)
Reproduction
Loading a sentencepiece tokenizer from a protobuf serialized spiece.model that is missing a precompiled_charsmap currently fails with the following error:
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
tok = T5Tokenizer.from_pretrained("/src/google_umt5-xxl")
File "/src/transformers/src/transformers/tokenization_utils_base.py", line 1736, in from_pretrained
return cls._from_pretrained(
~~~~~~~~~~~~~~~~~~~~^
resolved_vocab_files,
^^^^^^^^^^^^^^^^^^^^^
...<9 lines>...
**kwargs,
^^^^^^^^^
)
^
File "/src/transformers/src/transformers/tokenization_utils_base.py", line 1932, in _from_pretrained
tokenizer = cls(*init_inputs, **init_kwargs)
File "/src/transformers/src/transformers/models/t5/tokenization_t5.py", line 121, in __init__
self._tokenizer.normalizer = normalizers.Precompiled(_spm_precompiled_charsmap)
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Error while attempting to build Precompiled normalizer: Cannot parse precompiled_charsmapThis is because T5Tokenizer is trying to load a 0 length bytes as the precompiled_charsmap here:
The bytes comes from here:
Even if precompiled_charsmap is missing from the protobuf model, this will return empty bytes, as that is the default value for bytes fields.
This can be reproduced with the tokenizer from google/umt5-xxl. (Remove the tokenizer.json, keep only special_tokens_map.json, spiece.model, and tokenizer_config.json.)
Expected behavior
Something like this would work instead:
if len(self.proto.normalizer_spec.precompiled_charsmap) > 0:
kwargs["_spm_precompiled_charsmap"] = self.proto.normalizer_spec.precompiled_charsmap
else:
kwargs["_spm_precompiled_charsmap"] = NoneSource: huggingface/transformers