litellm/litellm-rust/crates
yassin 5a2fc06d01 perf(rust): count byte-level BPE tokens without the GPT-2 split regex
The oniguruma run of the ByteLevel pre-tokenizer regex is about 90% of
encode_fast on a 100k token body (100 ms of the ~110 ms Rust admission
count in the gateway pod). A hand-written scanner that yields the same
pieces, then feeds the model directly, counts the same text in 10 ms.
It only engages for tokenizers with the Anthropic shape (optional NFKC,
ByteLevel without prefix space, no post-processor) and falls back to the
full encoder when the text contains an added token. Parity with
encode_fast is tested on random texts, the pieces are compared with the
real pre-tokenizer, and the \p{L}/\p{N}/\s tables are checked against
oniguruma for every code point.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-10 08:26:51 +00:00
..
ai-gateway refactor(rust): rescope /v1/messages admission to a Python-called Rust token counter 2026-09-09 19:19:54 +00:00
CODING_STANDARDS feat(python): rename Rust rollout API (#39704) 2026-09-04 08:40:44 -07:00
config refactor(rust): extract config crate (#39706) 2026-09-04 08:17:07 -07:00
core perf(rust): count byte-level BPE tokens without the GPT-2 split regex 2026-09-10 08:26:51 +00:00
python-bridge refactor(rust): rescope /v1/messages admission to a Python-called Rust token counter 2026-09-09 19:19:54 +00:00
python-interop fix(python-bridge): harden sync and async route boundaries (#39332) 2026-09-02 16:26:35 -07:00