count_tokens.py crashes on text containing special tokens like <|endoftext|> (tiktoken disallowed_special default)

Aperta Adatta ai principianti
#153 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Leggi skills/bmad-*-builder/scripts/count_tokens.py per vedere come count_tokens() carica la codifica tiktoken e chiama enc.encode(text). Controlla i chiamanti in prepass-prompt-metrics.py e nel prepass.py di agent-builder per capire in che modo gli errori influiscono su ogni pre-pass. Il lavoro è completo quando le stringhe di token speciali vengono conteggiate senza sollevare eccezioni, la configurazione della codifica viene riutilizzata tra i file e il comando e i pre-pass terminano per l’input descritto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

count_tokens() in skills/bmad-*-builder/scripts/count_tokens.py guards only import tiktoken and tiktoken.get_encoding(...), then calls enc.encode(text) with tiktoken's default disallowed_special="all". tiktoken raises ValueError ("Encountered text corresponding to disallowed special token '<|endoftext|>'...") when the text contains a special-token string.

Any skill or reference that mentions such a token, for example a skill about tokenizers, prompt formats or LLM evaluation, makes:

  • count_tokens.py <file> exit with a traceback;
  • prepass-prompt-metrics.py crash, since it imports count_tokens and calls it on every file, which aborts the Analyze pre-pass.

(The agent-builder prepass.py swallows the exception and silently falls back to chars // 4 for that file.)

This report is from reading the code: the tiktoken encoding download is blocked in my test sandbox, so I couldn't run the tiktoken path. The behaviour is tiktoken's documented default.

Steps to reproduce

printf -- '---\nname: sk\ndescription: Explains tokenizers. Use when asked.\n---\n# sk\n\nModels end documents with the <|endoftext|> marker.\n' > sk/SKILL.md
uv run skills/bmad-workflow-builder/scripts/count_tokens.py sk/SKILL.md
# expected with tiktoken available: ValueError: Encountered text corresponding to disallowed special token '<|endoftext|>'

Expected behavior

Count special-token text as ordinary text: enc.encode(text, disallowed_special=()). Also cache the encoding at module level. Today get_encoding runs per file, and when the encoding can't be downloaded the pre-passes retry the network for every file before falling back, about 0.2 s/file here.

Environment

  • Model(s) used: n/a (deterministic script)
  • Agentic IDE used: n/a (scripts run directly)
  • BMad version: bmad-builder main @ d4a921c (v2.2.2 + #118)
  • Project language: Python 3.13, Linux
Lingua principale
Python
Stelle
220
Fork
54
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bmad-code-org/bmad-builder

Tutte le issue di bmad-code-org/bmad-builder

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.