Skip to content

Fast encode fixes#2142

Merged
SBrandeis merged 7 commits into
feat/train_encode_splitfrom
fast-encode-fixes
Jul 2, 2026
Merged

Fast encode fixes#2142
SBrandeis merged 7 commits into
feat/train_encode_splitfrom
fast-encode-fixes

Conversation

@SBrandeis

Copy link
Copy Markdown
Contributor

No description provided.

SBrandeis added 5 commits July 2, 2026 19:21
(cherry picked from commit 2d8adb2)
(cherry picked from commit 927334c)
(cherry picked from commit 2247647)
(cherry picked from commit 6371e9c)
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

…e base

Split #2129's token store in two: a legacy map-backed `VocabStore`
(`crate::vocab_store`) that backs the models on this base, and the verbatim
MPHF store renamed to `BucketVocabStore`. The models are unchanged — their
`use crate::vocab_store::VocabStore` now resolves to the legacy twin, so the
fast store can be swapped back in by the pipeline PR via a one-line alias.

Restore the pre-#2129 PreTokenizedString `AddedVocabulary` as the active
tokenizer AV, and park the #2129 fast path — `BucketVocabStore`, `Buckets`,
and the bucket AV (renamed `bucket_added_vocabulary`) — unwired for the
pipeline PR. The parked modules are not re-exported at the crate root so they
don't collide with the legacy AV. This makes the base the genuine legacy
Tokenizer, a fair A/B baseline against PipelineTokenizer.

Models and the tk-train trainer stay byte-identical to #2129. The only #2129
code removed: its broken `extract_and_normalize` stub (replaced by a working
two-pass), the `encode_special_tokens` default (true->false), and the
legacy-tokenizer wiring of the new AV (reverted). BucketVocabStore is #2129
verbatim plus the on-branch PartialEq/doctest fixes, with expanded tests.

tk-encode: 219 pass / 0 fail / 2 ignored, 20 doctests, clippy clean; workspace builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@SBrandeis SBrandeis force-pushed the fast-encode-fixes branch from 7dc6f8c to c57b759 Compare July 2, 2026 21:15
…e base

Split #2129's token store in two: a legacy map-backed `VocabStore`
(`crate::vocab_store`) that backs the models on this base, and the verbatim
MPHF store renamed to `BucketVocabStore`. The models are unchanged — their
`use crate::vocab_store::VocabStore` now resolves to the legacy twin, so the
fast store can be swapped back in by the pipeline PR via a one-line alias.

Restore the pre-#2129 PreTokenizedString `AddedVocabulary` as the active
tokenizer AV, and park the #2129 fast path — `BucketVocabStore`, `Buckets`,
and the bucket AV (renamed `bucket_added_vocabulary`) — unwired for the
pipeline PR. The parked modules are not re-exported at the crate root so they
don't collide with the legacy AV. This makes the base the genuine legacy
Tokenizer, a fair A/B baseline against PipelineTokenizer.

The parked bucket path stays #2129 verbatim, minus dead/broken bits:
  - `BucketVocabStore` = #2129's store + on-branch PartialEq/doctest fixes,
    with expanded unit tests.
  - the bucket AV's `extract_and_normalize` (and its stub-only tests) is
    dropped — the PipelineTokenizer drives the AV solely through `extract_next`
    (the `PipelinePatternMatcher` trait); `extract_and_normalize` is only the
    legacy TokenizerImpl's entry point and uses the legacy AV.
  - `extract_next` had an inverted vocab selection (#2129 used `self.vocab` for
    normalized text); fixed to search `normalized_vocab` when normalized and
    `vocab` otherwise, and covered with tests (routing, offsets, lstrip/rstrip,
    single_word).

Models and the tk-train trainer stay byte-identical to #2129. The only other
#2129 code removed is the legacy-tokenizer wiring of the new AV, reverted so
the legacy AV is active again.

tk-encode: 216 pass / 0 fail / 1 ignored, 20 doctests, clippy + fmt clean; workspace builds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@SBrandeis SBrandeis force-pushed the fast-encode-fixes branch from c57b759 to 07ab513 Compare July 2, 2026 21:53
@SBrandeis SBrandeis merged commit 0208bc9 into feat/train_encode_split Jul 2, 2026
33 of 42 checks passed
@SBrandeis SBrandeis deleted the fast-encode-fixes branch July 2, 2026 22:07
let vocab = if normalized {
&self.vocab
} else {
&self.normalized_vocab

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lol

Ok(total - ignored)
}

pub fn extract_and_normalize<N: Normalizer>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice

AddedToken::from("ask>", false),
AddedToken::from("<pad>", true),
],
.add_special_tokens(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

he removed a bit too much here! As I think I made a mistake maybe no? (the while xx loop) ?

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.

3 participants