HF tokenizers bug: 32-bit digest-only check makes BPE return wrong token IDs

art_zucker · x · 2026-11-25

tokenizers maintainer artzucker shares that for the library's next speed-focused release, the hot vocab-lookup path uses a memory-efficient perfect hash structure — until a community member found a nasty bug (issue #2722). In unmodified v1.0.0-rc.4 Rust sources, BucketVocabStore accepts a match based only on a 32-bit digest without comparing the candidate token's full bytes, so BPE can encode input into an unrelated vocab entry, changing the decoded text. It reproduces with a self-contained five-entry vocabulary and with real tokenizers like DeepSeek-V4.1-Flash-1017 and GLM-5.3. A fix is already linked (issues #2767/#2737 in review), and the author is publicly challenging others to beat it: any implementation where a hit is under 3ns wins open-source respect.

Original post →

More from Infra

Infra channel →