Skip to content

bench: make target tokenizer overrideable in bench_he and bench_llm - #93

Merged
davide221 merged 2 commits into
Luce-Org:mainfrom
ppsx:target-tokenizer-flag
May 4, 2026
Merged

davide221 merged 2 commits into
Luce-Org:mainfrom
ppsx:target-tokenizer-flag

Conversation

@ppsx

@ppsx ppsx commented May 4, 2026

Copy link
Copy Markdown
Contributor

Both bench scripts hardcoded Qwen/Qwen3.5-27B as the HF tokenizer reference, making them unusable for Qwen3.6 or future Qwen variants without forking the repo. This was already inconsistent with run.py, which honors $DFLASH_TOKENIZER and defaults to Qwen/Qwen3.6-27B.

Each bench script gets the override via its own idiomatic API:

bench_he.py: --target-tokenizer CLI flag (joins the existing
argparse surface). Default falls back through
$DFLASH_TOKENIZER -> "Qwen/Qwen3.5-27B", so:
- no flag, no env -> Qwen/Qwen3.5-27B (current behavior)
- $DFLASH_TOKENIZER set -> that wins
- --target-tokenizer foo -> that wins over both

bench_llm.py: TOKENIZER module-level read from $DFLASH_TOKENIZER
(matches the file's existing env-driven config style
- TARGET, DRAFT, TEST_DFLASH, etc. are all env vars).
Same default chain. Logged on the [bench] line.

Defaults preserve current behavior on both scripts; existing call sites that don't set the env var or pass the flag are unaffected. Users running Qwen3.6 set DFLASH_TOKENIZER once and both scripts pick it up, matching run.py's convention.

Both bench scripts hardcoded Qwen/Qwen3.5-27B as the HF tokenizer
reference, making them unusable for Qwen3.6 or future Qwen variants
without forking the repo. This was already inconsistent with run.py,
which honors $DFLASH_TOKENIZER and defaults to Qwen/Qwen3.6-27B.

Each bench script gets the override via its own idiomatic API:

  bench_he.py:   --target-tokenizer CLI flag (joins the existing
                 argparse surface). Default falls back through
                 $DFLASH_TOKENIZER → "Qwen/Qwen3.5-27B", so:
                   - no flag, no env  → Qwen/Qwen3.5-27B (current behavior)
                   - $DFLASH_TOKENIZER set → that wins
                   - --target-tokenizer foo  → that wins over both

  bench_llm.py:  TOKENIZER module-level read from $DFLASH_TOKENIZER
                 (matches the file's existing env-driven config style
                 — TARGET, DRAFT, TEST_DFLASH, etc. are all env vars).
                 Same default chain. Logged on the [bench] line.

Defaults preserve current behavior on both scripts; existing call sites
that don't set the env var or pass the flag are unaffected. Users
running Qwen3.6 set DFLASH_TOKENIZER once and both scripts pick it up,
matching run.py's convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 4, 2026 15:04

Copilot AI 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.

Pull request overview

Adds a configurable HuggingFace tokenizer reference to the benchmarking scripts so users can run benches against newer Qwen variants (or any compatible tokenizer) without editing the repo, aligning with the existing DFLASH_TOKENIZER convention used by run.py.

Changes:

  • bench_llm.py: reads TOKENIZER from $DFLASH_TOKENIZER (fallback Qwen/Qwen3.5-27B), logs it, and uses it for AutoTokenizer.from_pretrained(...).
  • bench_he.py: adds --target-tokenizer CLI flag (defaulting to $DFLASH_TOKENIZER then Qwen/Qwen3.5-27B) and uses it for prompt tokenization, logging the chosen tokenizer.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dflash/scripts/bench_llm.py Makes tokenizer configurable via DFLASH_TOKENIZER, logs it, and removes hardcoded tokenizer id.
dflash/scripts/bench_he.py Adds --target-tokenizer override (with env var fallback) and logs/uses it during tokenization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dflash/scripts/bench_llm.py Resolved

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="dflash/scripts/bench_he.py">

<violation number="1" location="dflash/scripts/bench_he.py:300">
P2: `--target-tokenizer` is not reflected in the cached prompt files, so `--skip-tokenize` can reuse tokenization from a different tokenizer and corrupt benchmark results.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread dflash/scripts/bench_he.py Resolved
…lm env var

Two review-feedback fixes:

1. bench_he.py cached prompt files at TMPDIR/he_prompt_NN.bin with no
   tokenizer in the path, so a sequence like
       run 1: --target-tokenizer Qwen/Qwen3.5-27B (no --skip-tokenize)
       run 2: --target-tokenizer Qwen/Qwen3.6-27B --skip-tokenize
   would silently feed Qwen3.5 token IDs to the bench under the
   pretense of Qwen3.6 — corrupting results without any signal.

   Cache path is now TMPDIR/he_prompt_<slug>_NN.bin where <slug> is
   re.sub(r'[^A-Za-z0-9._-]+', '_', target_tokenizer). Different
   tokenizers cache to distinct files; switching back is free. As a
   safety net, --skip-tokenize now sys.exit's with a clear message if
   no cache exists for the requested tokenizer (instead of falling
   into a misleading file-not-found later in the bench loop).

   Threaded the slug through both call sites (tokenize loop + bench
   loop). Also moved the [bench] tokenizer = ... print up to the
   header so the resolved tokenizer is visible regardless of
   --skip-tokenize.

2. bench_llm.py docstring's env-var list didn't mention the new
   DFLASH_TOKENIZER knob (the "TOKENIZER" module constant was
   reading it but the docstring stayed silent). Added it to the
   list with a note that it matches run.py's convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@davide221
davide221 merged commit 52c9d19 into Luce-Org:main May 4, 2026
1 check passed
@ppsx
ppsx deleted the target-tokenizer-flag branch May 5, 2026 09:09
@ppsx
ppsx restored the target-tokenizer-flag branch May 5, 2026 09:09
@ppsx
ppsx deleted the target-tokenizer-flag branch May 5, 2026 09:09
oliveagle pushed a commit to oliveagle/lucebox-hub that referenced this pull request May 22, 2026
bench: make target tokenizer overrideable in bench_he and bench_llm
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