Skip to content

fix: count literal special tokens like <|endoftext|> as plain text - #129

Merged
anhnh2002 merged 1 commit into
mainfrom
fix/tiktoken-special-tokens
Oct 8, 2026
Merged

anhnh2002 merged 1 commit into
mainfrom
fix/tiktoken-special-tokens

Conversation

@anhnh2002

Copy link
Copy Markdown
Collaborator

Problem

Some repos contain the literal string <|endoftext|> in source code (e.g. vendored CLIP tokenizers). count_tokens calls tiktoken's encode, which raises ValueError: Encountered text corresponding to disallowed special token '<|endoftext|>' by default. This aborts module clustering before any LLM call (seen on Fsoft-AIC/SBDC).

Fix

Pass disallowed_special=() in count_tokens so such strings are counted as normal text. This only affects token counting, not what is sent to the model.

Repos that vendor tokenizer code (e.g. CLIP) contain the literal string
'<|endoftext|>'. tiktoken rejects it by default, so count_tokens raised
and module clustering aborted before any LLM call.
@anhnh2002
anhnh2002 merged commit f0975ea into main Oct 8, 2026
2 checks passed
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