Fix: Correctly filter special tokens in benchmark_prefix_caching #28615
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Fixes a bug in
benchmarks/benchmark_prefix_caching.pywhere thesample_tokensfunction failed to filter special tokens.The original code was incorrectly comparing token strings (
k) with a set of special token IDs (all_special_ids). This PR fixes the logic to correctly compare the token ID (v) and simplifies the list comprehension by usingvocab.values()instead ofvocab.items(), as the token string key is not used.Test Plan
This is a self-contained logic fix within a benchmark script. The test plan is to ensure the script still runs successfully after the change.
I ran the benchmark script locally to confirm that it executes without any new errors.
Test Result
The script runs successfully. The
sample_tokensfunction now correctly filters all special token IDs from the sampling pool, as the original code intended.