Repository navigation
tokenizer: read a Qwen2 slow-tokenizer export when tokenizer.json is absent - #2225
Conversation
|
Thanks @shuuul. Checking against a golden
|
|
All seven points make sense. Plan:
I'll push the new head with these. |
|
Thanks @shuuul, that plan covers all seven. Documenting the structured-output limit rather than threading the bytes through the server is fine. Please push it when it's ready, with the refusal tests' error names in the description. |
|
Pushed 8637c4f with all seven points: the converter is in |
|
Thanks @shuuul. All seven are in, and refusing another class before reading half a gigabyte of vocab and merges is a nice touch. Ready to land, and it's in the queue. |
8637c4f to
8973794
Compare
…is absent loadTokenizer now reads a directory's vocab.json, merges.txt and tokenizer_config.json when tokenizer.json is missing and tokenizer_class is Qwen2Tokenizer, emitting the tokenizer.json transformers 4.57's Qwen2Converter produces and parsing it as before. Checkpoints that ship only slow-tokenizer files need no Python conversion at serve time. The test converts a 267-token export and compares encode, decode and the added token against a golden tokenizer.json from transformers 4.57.1.
Move the converter to qwen2_slow.zig, parse vocab.json as an object of non-negative integer ids, and write added-token ids from parsed numbers so non-JSON keys cannot slip through. Read tokenizer_config.json first, so another tokenizer class is refused before the vocab and merges. Missing merge tokens and malformed adds get their own errors. The refusal tests cover a non-object vocab, a merge naming a missing token, another class and bad added ids. Structured output still reads tokenizer.json itself; the CHANGELOG says so.
8973794 to
d9175a2
Compare
|
Thank you @shuuul. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
|
Thanks @shuuul! This is in TensorFold 1.2.3, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.3 |
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
…hart#2105) Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (ashhart#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
Qwen3-ASR's 0.6B and 1.7B admitted from config.json: the audio tower's geometry (chunks of 100 frames, windows of n_window_infer frames) and the Qwen3 language model's, its interleaved M-RoPE refused unless its sections span the head (audio positions are equal on all three axes, so it is plain RoPE). Every stored tensor checked by name, shape and dtype, none left over; the stored lm_head must be bit-equal to the tied embedding. WhisperFeatureExtractor's log-mel rows in float64, and the tower in float64 stage by stage, either exact or at torch's bf16 rounding points. The checkpoint ships no tokenizer.json; the shared tokenizer reads its slow export (#2225). tf-qwen3-asr-check compares weights, prompt ids, the reply's decode, mel rows and every tower stage with a case from tools/zig/qwen3_asr_case.py (the qwen-asr 0.0.6 package's transformers backend, hooked stage by stage).
What
loadTokenizerfalls back to a Qwen2 slow tokenizer whenpath/tokenizer.jsonis absent and the directory holdsvocab.json,merges.txtandtokenizer_config.jsonwithtokenizer_classQwen2Tokenizer. The newqwen2_slow.zigwrites the tokenizer.json a Qwen2 checkpoint would ship, and the existing parser reads it unchanged.The converter reads
tokenizer_config.jsonfirst, so another class is refused before the vocab and merges are read.vocab.jsonmust be one object of string keys to non-negative integer ids; the model's vocab is written back from the parsed ids. Every merge must name two tokens in that vocab, and added-token ids must be decimal digits written as parsed integers.Why
Some checkpoints ship only a slow tokenizer's files. Today the loader returns
FileNotFoundfor them; with this they can be served without a Python conversion step.Test
zig test zig/src/core/tokenizer/tokenizer.zig: 48/48 pass. The fixture is a 267-token export whose goldentokenizer.jsonwas generated by transformers 4.57.1'sconvert_slow_tokenizer; encode, decode and<|endoftext|>'s id and flags match the golden on five inputs.Refusal tests and their errors:
vocab.json:InvalidTokenizer;MissingMergeToken;tokenizer_class:UnsupportedModel, before vocab and merges are read;+5and1_0:InvalidAddedTokenId.Limits
Only
Qwen2Tokenizer-class exports are converted; any other slow class still returnsUnsupportedModel. Structured output still needstokenizer.json, becauseserver.zigreads that file itself; the CHANGELOG says so.loadTokenizeron a.jsonpath, and on a directory withtokenizer.json, is unchanged.