Skip to main content

Standalone TITO (Token-In-Token-Out) tokenizers extracted from the miles project.

Project description

miles-tito-tokenizers

Standalone TITO (Token-In-Token-Out) tokenizers extracted from the miles project.

This package lets you reuse miles' chat-template / incremental-tokenization logic for multi-turn agentic rollout without importing the full miles training framework.

Attribution

  • The TITO tokenizer design and implementation are derived from the miles project by the radixark/miles contributors.
  • DeepSeek V3.2 and V4 encoders are vendored from SGLang under the Apache License 2.0.
  • See ATTRIBUTION.md and LICENSE for details.

Install

pip install miles-tito-tokenizers

No sglang installation is required — DeepSeek encoders are vendored as pure Python.

Quick start

from transformers import AutoTokenizer
from miles_tito_tokenizers import get_tito_tokenizer

tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-4B")

tito = get_tito_tokenizer(
    tokenizer,
    tokenizer_type="qwen3",
    allowed_append_roles=["tool", "user"],
)

messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"},
]

ids = tito.render_messages(messages, add_generation_prompt=True)
print(ids)

For DeepSeek models:

tito = get_tito_tokenizer(
    tokenizer,
    tokenizer_type="deepseekv32",
    allowed_append_roles=["tool"],
)

Migrating from transformers

miles_tito_tokenizers.apply_chat_template mirrors tokenizer.apply_chat_template(..., return_dict=False), which is the format used by SGLang and miles:

What you want transformers call miles_tito_tokenizers call
Rendered text tokenizer.apply_chat_template(messages, tokenize=False) mtt.apply_chat_template(messages, tokenizer=tokenizer)
Token IDs tokenizer.apply_chat_template(messages, tokenize=True, return_dict=False) mtt.apply_chat_template(messages, tokenizer=tokenizer, tokenize=True)
BatchEncoding tokenizer.apply_chat_template(messages) not supported by design

apply_chat_template takes tokenizer as a keyword-only argument so the intent is explicit.

Supported model families

tokenizer_type Notes
qwen3 Qwen3
qwen35 Qwen3.5
qwennext Qwen3-Thinking-2507 / Qwen3-Next-Thinking
glm47 GLM 4.7
nemotron3 NVIDIA Nemotron 3
kimi25 Moonshot Kimi K2.5
kimi26 Moonshot Kimi K2.6
minimax_m25 MiniMax-M2.5
minimax_m27 MiniMax-M2.7
deepseekv32 DeepSeek V3.2
deepseekv4 DeepSeek V4
default HF-native chat template, no TITO merge logic

Validation scripts

Two CLI helpers from miles are included:

# CPU / fast: verify that rendered token sequences are append-only.
python -m miles_tito_tokenizers.scripts.verify_chat_template \
    --model Qwen/Qwen3-4B \
    --tito-model qwen3 \
    --tito-allowed-append-roles tool user

# GPU / e2e: verify against a real SGLang-served checkpoint.
python -m miles_tito_tokenizers.scripts.verify_session_tito_tokenizer \
    --hf-checkpoint Qwen/Qwen3-4B \
    --tito-model qwen3 \
    --tito-allowed-append-roles tool user \
    --sglang-reasoning-parser <rp> \
    --sglang-tool-call-parser <tcp> \
    --rollout-num-gpus-per-engine 1

Relationship to miles

miles-tito-tokenizers is an independent, personal-fan package that extracts a well-defined slice of miles. It is not affiliated with or endorsed by the miles team. If you are building inside miles itself, use the original miles.utils.chat_template_utils module.

License

Contributing

See CONTRIBUTING.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

miles_tito_tokenizers-0.1.1.tar.gz (65.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

miles_tito_tokenizers-0.1.1-py3-none-any.whl (63.0 kB view details)

Uploaded Python 3

File details

Details for the file miles_tito_tokenizers-0.1.1.tar.gz.

File metadata

  • Download URL: miles_tito_tokenizers-0.1.1.tar.gz
  • Upload date:
  • Size: 65.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for miles_tito_tokenizers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5ba010c667b443ac12fdffca91b4880e2f61312d2db5d949a9188d628f88952f
MD5 2716e264e742cd985e56925b869d133b
BLAKE2b-256 1d9f71b745beea8b33aaee0184d79358ddaaeef1e5f7b7d9f0157512a9e5a374

See more details on using hashes here.

File details

Details for the file miles_tito_tokenizers-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for miles_tito_tokenizers-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f794c97288d06b024cc6c128842b23c5525ee39d7ffc35c854cad6abcf173121
MD5 cd9b342b7b256166d0a48a8c4b07a68f
BLAKE2b-256 101a27ba34d9d063a6cca4251d65bfd0a73e8256eb86f9e54121b465a46d29ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page