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

Đang mở Phù hợp với người mới
#153 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Đọc skills/bmad-*-builder/scripts/count_tokens.py để xem count_tokens() tải mã hóa tiktoken và gọi enc.encode(text) như thế nào. Kiểm tra các hàm gọi trong prepass-prompt-metrics.py và prepass.py của agent-builder để hiểu lỗi ảnh hưởng đến từng pre-pass ra sao. Công việc hoàn tất khi các chuỗi special-token được đếm mà không phát sinh ngoại lệ, cấu hình mã hóa được tái sử dụng giữa các tệp, và lệnh cùng các pre-pass chạy xong với đầu vào được mô tả.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
220
Fork
54
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bmad-code-org/bmad-builder

Tất cả issue của bmad-code-org/bmad-builder

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.