Skip to content

test(awq): give the Mamba-hybrid fixture tokenizer one token per id - #6637

Merged
Qubitium merged 1 commit into
mainfrom
fix/awq-red-tests-main-hybrid-tokenizer
Dec 1, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/awq-red-tests-main-hybrid-tokenizer

Conversation

@Qubitium

@Qubitium Qubitium commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

tests/test_awq_hybrid_recurrent_mask_4671.py::test_awq_batch_size_one_quantizes_a_mamba_hybrid fails in a random fraction of fresh processes, regardless of test order, device visibility or -n. The errors are either "The tokenizer in <tmp> is unusable: it cannot encode ordinary text (loaded tokenizer: 129/130 token(s), model vocab_size=128)" or "WordLevel error: Missing [UNK] token from the vocabulary". Run alone on CPU on main it failed 3 of 10 runs here.

Root cause is a stale fixture, not a product bug. The fixture built {tok0..tok127 -> 0..127} and then set [PAD] -> 0 and [UNK] -> 1, so ids 0 and 1 each had two names. The tokenizers WordLevel model keeps an id-to-token map whose winner follows the Rust hash-map seed, which differs per process, and only one name per id survives save/load. Over 20 fresh processes:

Saved tokenizer Processes
both specials kept (128 tokens, usable) 3
[PAD] lost, re-added as id 128 (129 tokens) 11
[UNK] lost, load error "Missing [UNK] token" 6

The collision has been in the test since #4694. The loader now rejects such tokenizers on purpose (#6386, "reject tokenizer-less checkpoints instead of loading an empty tokenizer"). That is likely when the latent fixture bug became visible, but I did not bisect it.

What Changed

  • The fixture vocabulary has one token per id: [PAD]=0, [UNK]=1, tok2..tok127. It also asserts the ids are exactly range(config.vocab_size), so a colliding fixture fails deterministically instead of by hash seed.
  • The test's calibration rows (ids 3..26), the quantize call and its assertions are unchanged. No product code changed.
  • Companion: the other long-red AWQ test (test_awq_weight_mean.py::test_awq_pseudo_quantize_nan_guard_uses_one_host_read) had an unrelated cause, cache-order leakage in _awq_symmetric_scale_limit, fixed in fix(awq): keep the cached symmetric scale limit free of host reads #6633 (merged).

Tests

  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable. (The fixture now carries a deterministic one-token-per-id assertion; the end-to-end test is the regression.)
# env: PYTHONPATH=<clone> HF_HOME=/root/.cache/huggingface, python -P, torch 2.15, transformers 5.23
A=tests/test_awq_hybrid_recurrent_mask_4671.py::test_awq_batch_size_one_quantizes_a_mamba_hybrid
B=tests/test_awq_weight_mean.py::test_awq_pseudo_quantize_nan_guard_uses_one_host_read

# Red (main fixture), alone on CPU, 10 fresh runs: 3 failed (unusable tokenizer, 129/130 tokens), 7 passed.
# Red, deterministic: main's colliding vocabulary + the new guard
#   E  AssertionError: assert [0, 0, 1, 1, 2, 3, ...] == [0, 1, 2, 3, 4, 5, ...]

# Green: this branch, alone on CPU, 8 fresh runs: 8 passed
# Fixed vocabulary, 20 fresh processes: 20/20 load as a usable 128-token tokenizer ([PAD]=0, [UNK]=1)
# Order / device / xdist matrix on this branch (rebased on main with #6633):
#   cpu: A B, B A, -n 2 A B; CUDA (one GPU): A B, -n 2 B A; cpu whole file -- see results below

Matrix results (branch head cfa6d20, both fixes present):

cpu   A B          2 passed
cpu   B A          2 passed
cpu   -n 2 A B     2 passed
CUDA  A B          2 passed
CUDA  -n 2 B A     2 passed
cpu   tests/test_awq_hybrid_recurrent_mask_4671.py   10 passed
bash format/check.sh   # ruff 0.14.2: All checks passed!

Measured Impact

Not applicable: test-only change, no runtime, VRAM or accuracy effect.

Model Support / Module Plan

Not applicable: no model, alias, definition or module plan change.

Model test node IDs and results (or "not applicable"): not applicable.

AWQ onboarding safety

Not applicable: no AWQ grouping/search/replay/fold change; only a test fixture tokenizer.

Logic Flow Documentation

  • This change does not alter a major logic flow, or the required diagrams and docs page are included below.

Diagram summary: not applicable. This is a test fixture change only.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

  • Not applicable: no kernel change.

Notes

I grepped every models.WordLevel( fixture under tests/. No other fixture gives two tokens the same id (test_nemotron_omni_local_port.py deletes the placeholder before reassigning its id).

🤖 Generated with Claude Code

`test_awq_batch_size_one_quantizes_a_mamba_hybrid` failed in a random
fraction of fresh processes, independent of test order, device or xdist.
The failures looked like "the tokenizer ... is unusable (129/130 token(s),
model vocab_size=128)" or "WordLevel error: Missing [UNK] token".

Cause: the fixture built `{tok0..tok127 -> 0..127}` and then added
`[PAD] -> 0` and `[UNK] -> 1`, so ids 0 and 1 each had two names. The
tokenizers WordLevel model keeps an id -> token map whose winner depends on
the Rust hash-map seed, which differs per process. On save only one name per
id survives. Across 20 fresh processes, 3 kept both specials (128 tokens),
11 lost `[PAD]` (re-added as id 128, 129 tokens), and 6 lost `[UNK]`, which
cannot be loaded at all. The loader correctly rejects those tokenizers
(#6386), so the test failed whenever the seed dropped a special.

Fix: build the vocabulary with one token per id (`[PAD]`=0, `[UNK]`=1,
`tok2..tok127`) and assert the ids are exactly `range(vocab_size)`, so a
colliding fixture now fails deterministically instead of by seed. The test's
calibration rows (ids 3..26) and its assertions are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium
Qubitium marked this pull request as ready for review December 1, 2026 09:51
@Qubitium
Qubitium merged commit 9d7c6f4 into main Dec 1, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/awq-red-tests-main-hybrid-tokenizer branch December 1, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant