Toke(n)icer
A (nicer) tokenizer you want to use for model inference and training: with all known peventable gotchas normalized or auto-fixed.
News
-
0.0.20 candidate (unreleased): Prepare legacy Metaspace JSON before construction, preserving source bytes and caller options through an immutable derived cache. Direct tokenizer retries/serialized rebuilds no longer retain Auto-only model configs that break JSON saving.
-
0.0.18: Respect supplied text
config/model_configwhen defaulting the Mistral regex repair; preserve original MiniCPM token IDs when old checkpoint JSON omitsmodel_type. Explicitfix_mistral_regexoverrides and affected Mistral-family defaults are unchanged. See config-selected regex correction. -
0.0.19:
Tokenicer.prepare_load_kwargs(path, **kwargs)prepares legacy AddedToken metadata before native or package-owned tokenizer construction, preserving explicit caller values and selected Hub assets. -
0.0.19: Historical identity-SentencePiece BPE conversion is explicit opt-in (
normalize_sentencepiece=True, default off); native Llama keeps authoritative serialized SP pipelines and declared special-token IDs across reloads. -
0.0.17 security follow-up: Tokenizer trust policy applies to every fallback. Unknown custom tokenizer classes fail closed without explicit trust or an already loaded instance; retries never turn trust on.
-
11/17/2026 0.0.17: Load legacy ERNIE 4.5 VL tokenizers natively without checkpoint Python; normalize image/video tokens and chat placeholders. SentencePiece-only bundles require
sentencepieceandprotobuf. -
10/15/2026 0.0.16: Keep the tokenization of the checkpoint's serialized
tokenizer.jsonwhen a*TokenizerFastclass resolves to a legacy tokenizer that rebuilds its own backend. FixesDeepSeek-R1-Distill-Llama-*and other Llama-3-style checkpoints loaded from a local directory, where every word lost its leading whitespace. -
07/22/2026 0.0.14: Auto-fix affected Mistral-family tokenizer regexes, including Laguna S 2.1.
-
03/03/2026 0.0.7: Fix Qwen 3.5 MoE compat.
-
02/09/2026 0.0.6: Fix ChatGLM compat.
-
09/04/2025 0.0.5: Fix
pad_token_iddetection forLongCatmodel. -
02/21/2025 0.0.4: ⚡ Now
tokenicerinstance dynamically inherits thenativetokenizer.__class__of tokenizer passed in or loaded via ourtokenicer.load()api. CI now tests tokenizer compat from64different models. -
02/10/2025 0.0.2: 🤗 Initial release!
Features:
- Compatible with all HF
Transformersrecognized tokenizers - Checkpoint tokenizer Python requires explicit
trust_remote_code=True. The default andNonefail closed for unknown custom classes; a serialized backend alone does not establish custom/scientific normalization semantics. Already loaded tokenizer instances retain their implementation. - Loads the tokenizer the checkpoint asks for: a checkpoint that declares a
*TokenizerFastclass keeps the tokenization of its serializedtokenizer.json, even whenTransformersaliases that name to a legacy class that rebuilds its own backend (LlamaTokenizerhardcodes a sentencepieceMetaspacepre-tokenizer, which drops the leading whitespace of every word for Llama-3-style checkpoints). Passprefer_serialized_tokenizer=Falseto keep the classTransformersresolves. - Auto-fix
modelsnot settingpadding_token - Auto-Fix
modelsreleased with wrongpadding_token: manymodelsincorrectly useeos_tokenaspad_tokenwhich leads to subtle and hidden errors in post-training and inference whenbatchingis used which is almost always. - Zero external dependency outside of
Transformers
Upcoming Features:
- Add
automatictokenizer validation tomodeltrainingand subsequentinferenceso that not only tokenizer config but actualdecode/encodeare 100% re-validated on model load. Often the case,inferenceandtrainingengines modifies the traditional tokenizers causing subtle and inaccurate output wheninferenceperformed on a platform that is disjointed from thetrainer.
Install
PIP/UV
pip install -v tokenicer
uv pip install -v tokenicer
Install from source
# clone repo
git clone https://github.com/ModelCloud/Tokencier.git && cd Tokenicer
# compile
pip install -v .
Usage
- Replace all calls to
AutoTokenizer.from_pretrained()withTokenizer.load(): args are 100% compatible withAutoTokenizer
# Replace `AutoTokenizer.from_pretrained()`
# from tokenizer import AutoTokenizer
# tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen2.5-0.5B-Instruct')
# With `Tokenicer.load()`
from tokenicer import Tokenicer
# Returns `Tokenicer` instance that inherits original `Qwen2TokenizerFast` type.
tokenizer = Tokenicer.load('Qwen/Qwen2.5-0.5B-Instruct')
# That's it! Toke(n)icer has auto-fixed Qwen2.5-0.5B-Instruct's incorrect `pad_token`.
# Now this this model can be `trained` and `inferenced` correctly with `batch` and `masks`.
# Now use the new tokenizer like any normal HF PretrainedTokenizer(Fast)
print(f"pad_token: `{tokenizer.pad_token}`")
- If you already have a loaded or composite config, pass it directly so Tokenicer can normalize the resolved text config in-place:
tokenizer = Tokenicer.load(tokenizer, model_config=model.config)
- Tokenizer classes are validated against the checkpoint's serialized
tokenizer.json. Checkpoints that declare a*TokenizerFastclass never fall back to a legacy class that tokenizes differently:
tokenizer = Tokenicer.load('deepseek-ai/DeepSeek-R1-Distill-Llama-8B')
print(tokenizer('Hello world, this is a test.')['input_ids'])
# [9906, 1917, 11, 420, 374, 264, 1296, 13]
# Opt out and keep whatever class `Transformers` resolves for the checkpoint:
tokenizer = Tokenicer.load('deepseek-ai/DeepSeek-R1-Distill-Llama-8B', prefer_serialized_tokenizer=False)
Citation
@misc{gptqmodel,
author = {ModelCloud.ai and qubitium@modelcloud.ai},
title = {Toke(n)icer},
year = {2025},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/modelcloud/tokenicer}},
note = {Contact: qubitium@modelcloud.ai}
}
Metadata
Release files for TokeNicer 0.0.21
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tokenicer-0.0.21.tar.gz | 23.8 kB | Without provenance | Details for tokenicer-0.0.21.tar.gz |
Release files / tokenicer-0.0.21.tar.gz
| Download URL | tokenicer-0.0.21.tar.gz |
|---|---|
| Size | 23.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4e8aeb2a380dd32ebb513292f1bfa8326933557df0d45cd413afbe373a54463c
|
|
BLAKE2b-256 checksum How to use checksums |
282da6b545cbb2c35e02eca6430307c252203c10f081cc26c9efc665207dc107
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for TokeNicer 0.0.21
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.