Skip to content

tokenizer: support Flint and authoritative GGML EOG arrays - #678

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
Burntgogi:feat/issue632-tokenizer
Oct 23, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
Burntgogi:feat/issue632-tokenizer

Conversation

@Burntgogi

Copy link
Copy Markdown
Contributor

Refs #632; second independent CPU-only slice after #677.

Change

  • Add a distinct pre=flint using existing ordered-split/classifier owners: numbers, CJK/Kana, then the pinned mainline effective word/punctuation/whitespace program. No alias, new regex engine, Unicode tables, NFC or prefix space.
  • Read tokenizer.ggml.eog_token_ids as an authoritative nonempty, typed, bounded, sorted/deduplicated stop set while retaining GGUF attribute overrides and ordinary BPE. The private bloomery key alone still selects HF mode; simultaneous sources must agree as canonical sets.
  • Select Flint strict UTF-8 decoding independently of NFC. Reproduced the previous default-path overlong-byte mismatch and above-U+10FFFF panic, then fixed both with a consumer regression. Surrogate-byte behavior remains the pinned reference behavior.
  • Document split-program versus final-ID differences and stop precedence.

Executed verification

Linux x86_64 i5-12600K/64GiB, no NVIDIA; nightly-2026-08-28, RUSTFLAGS=-C target-cpu=native. Base 40fec96.

  • cargo test -p bloomery-tokenizer --lib: 40 passed.
  • cargo clippy -p bloomery-tokenizer --all-targets -- -D warnings: passed; cargo fmt -p bloomery-tokenizer and comment check passed.
  • Built and exercised bloomery-tokenize against the actual bounded unsloth/flint-GGUF UD-Q4_K_XL header at revision 20468edfc38ab43d6914cc88b08cbecb05d0fc62. Header SHA256 fb0cc4b520f927f0b679193397ee0c36ca252426e7881283c5aa6de3e44a3a2b. --info: vocab150144, merges149744, add_bos=false/add_eos=false, eog=[150001,150003,150005,150018].
  • Built CPU-only llama-tokenize from exact mainline a37cc46104eb50900d5ab4a9ba02a0abdac039db. Reference --no-escape --no-bos, special parsing on/off. Ran 22 individual Unicode/number/tag cases in both modes: zero ID differences. Expanded deterministic 548-case corpus (36 explicit/boundary cases plus 512 seeded mixes), 38671 bytes: 24403 parsed IDs / 24407 no-parse IDs, byte-for-byte ID parity with mainline.
  • Official RecursiveSI/flint tokenizer.json at 2a247be0c0aec895ccb0ac7ca92229ec6df37288 (SHA256 a263cce0b7e2b03f7ee07ce809783ef4b47f160c3f268a4ea1524f638da45b68), executed with tokenizers0.22.2: all 24403 parsed corpus IDs also match. Actual HF pretokenizer boundaries differ for HelloWorld, iPhone, A+combining acute+B, and x-long-s-y; matching final IDs in this vocabulary is not universal split equivalence.
  • Malformed input after fix matches actual mainline: C0 80 -> [702]; F4 90 80 80 -> [1545]; ED A0 80 -> [169,254,222]; truncated E2 82 -> [702]. No panic.
  • A linked mainline vocab-only API probe enumerated the effective loaded EOG set [150001,150003,150005], omitting developer150018. This PR deliberately honors the artifact/official four-ID stop contract instead.

Reference execution used only the verified real header in a sparse length container because mainline validates file bounds even in vocab_only mode; its loader explicitly skipped tensors. No payload validation, full model download, inference, CUDA, performance or serve-seat claim. No model files/weights committed.

@github-actions github-actions Bot added documentation Improvements or additions to documentation model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja labels Oct 22, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: Flint duplicates the existing stop-name override rule.

Must fix

1. Apply stop-name overrides in one loop

crates/tokenizer/src/vocab.rs:577 repeats crates/tokenizer/src/vocab.rs:570. Both loops resolve a name, add its ID to EOG, and mark it CONTROL. This is a kind-B duplication defect under R14.
Cost: combining them removes four lines and one loop without adding a helper or local name. Keeping both requires two edits when this rule changes.
Replace the two adjacent name loops with:

        for name in EOG_NAMES.iter().chain(if self.pre == "flint" {
            ["<|user|>", "<|observation|>"].as_slice()
        } else {
            &[]
        }) {
            if let Some(id) = self.id_of(name) {
                eog.insert(id);
                self.attrs[id as usize] |= attr::CONTROL;
            }
        }

Checked

Duplicates: 8 added function definitions inspected, including the extracted stop validator and ordered splitter. The repeated override rule is item 1. Dryer reported 0 pairs.
Complexity: diagnostics report Vocab::apply_overrides growing from 14 to 17 through the Flint branch and loop; item 1 reuses the existing loop.
Silent failure: invalid stop IDs return errors; absent stop keys and inferred names are optional.
Tests: static mutation checks cover dropping explicit stop replacement, weakening the ID bound, requiring NFC for strict decoding, dropping contractions, and selecting HF mode from GGML stops. The changed assertions reject these mutants. Rust tests and mutants were not executed during validation.
Gates: none removed or relaxed; no pin moved.
Escape catalog: C1–C4 do not match this diff.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@Burntgogi

Copy link
Copy Markdown
Contributor Author

Addressed R14 in 5eae54a. The shared EOG_NAMES loop now chains Flint's two additional stop names; ID resolution, EOG insertion and CONTROL marking have one owner. The duplicate loop was deleted, with no helper, allocation, or alternate path added.

Executed on the corrected head:

  • cargo test -p bloomery-tokenizer:40 passed; the15 external model/oracle integration cases remain ignored.
  • cargo clippy -p bloomery-tokenizer --all-targets -- -D warnings; cargo fmt -p bloomery-tokenizer --check; check-comments:passed.
  • Built and launched bloomery-tokenize against the exact5,470,528-byte Flint header (SHA256 fb0cc4b520f927f0b679193397ee0c36ca252426e7881283c5aa6de3e44a3a2b). --info retains EOG [150001,150003,150005,150018] and add_bos=false/add_eos=false. The four concatenated special tags encode to those four IDs.
  • Actual CLI malformed-input results remain C080->[702], F4908080->[1545], EDA080->[169,254,222], E282->[702]. A mixed Unicode/number/tag string round-trips byte-for-byte.

No tokenizer semantics or four-stop contract changed; prior oracle evidence remains in the PR body. This correction was revalidated with the checks above, not a new mainline/HF corpus run.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review: must-fix 1 is fixed in crates/tokenizer/src/vocab.rs:570. Both name sets now use one override loop.

Verdict: CLEAN: The incremental change resolves the earlier duplication and preserves stop IDs and token attributes.

Checked

Duplicates: 0 new items; the repeated loop is removed. Dryer reported 0 pairs.
Complexity: crapper flagged no functions. The change combines two loops without adding an owner.
Silent failure: 1 optional-name lookup followed into stop IDs and CONTROL attributes. Absent names remain optional; all resolved names retain both effects.
Tests: no tests changed. Existing flint_stops_preserve_gguf_encoding_and_special_parsing assertions reject dropping the Flint names or the CONTROL assignment in the changed loop (static mutation check; tests not executed).
Gates: none removed or relaxed; no pin moved.
Escape catalog: C1–C4 do not match. Flint, non-Flint, missing-name and explicit-array precedence scenarios preserve prior behavior. This is load-time code.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4
juliankang4 merged commit c5fb086 into midagedev:main Oct 23, 2026
7 checks passed
@juliankang4

Copy link
Copy Markdown
Collaborator

@Burntgogi Thanks for the contribution. The review is done, so I'm merging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants