[Benchmark] Add --use_random_tokens flag to C benchmark - #2170
Merged
Baiju Meswani (baijumeswani) merged 7 commits intoMay 21, 2026
Merged
Conversation
… IDs Feeds randomly generated token IDs (uniform in [0, 99]) directly into the prompt sequences, skipping text encoding entirely. Requires -l/--prompt_length; mutually exclusive with --prompt and --prompt_file.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a --use_random_tokens mode to the C++ model_benchmark tool so it can benchmark model/runtime performance without tokenizing a real prompt (by directly feeding synthetic token IDs).
Changes:
- Introduces a
--use_random_tokensCLI flag and correspondingOptions::use_random_tokenssetting. - Adds validation and help text describing constraints for
--use_random_tokens. - Updates the benchmark to bypass tokenization and append randomly generated token IDs into
OgaSequences.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
benchmark/c/options.h |
Adds use_random_tokens to the benchmark options struct. |
benchmark/c/options.cpp |
Documents/parses --use_random_tokens and adds basic option validation. |
benchmark/c/main.cpp |
Generates random token sequences and bypasses tokenizer encoding when enabled. |
.github/copilot-instructions.md |
Fixes a documentation path (src/runtime_settings.cpp). |
Comments suppressed due to low confidence (1)
benchmark/c/options.cpp:105
--use_random_tokensvalidation is order-dependent becauseprompt_num_tokens_or_contentis overwritten during parsing. E.g.,--prompt "hi" -l 16 --use_random_tokenswill pass verification and silently ignore--prompt, even though the help/PR description say--use_random_tokenscannot be used with--prompt/--prompt_file. Track which prompt source flags were provided (or count prompt options) and fail if more than one is specified, regardless of argument order.
if (opts.use_random_tokens && !std::holds_alternative<size_t>(opts.prompt_num_tokens_or_content)) {
throw std::runtime_error(
"--use_random_tokens requires -l/--prompt_length and cannot be used with --prompt or --prompt_file.");
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
kunal-vaishnavi / Baiju Meswani (@baijumeswani) pls review this, added a new option in c/benchmark similar to python variant. |
Track which of --prompt_length, --prompt, and --prompt_file were explicitly specified via booleans and check those in VerifyOptions, instead of inspecting the variant value. This closes two gaps: - --use_random_tokens alone no longer silently uses the default prompt length; it now requires an explicit -l/--prompt_length. - Last-option-wins (e.g. --prompt foo -l 100) no longer bypasses mutual exclusivity checks among the prompt source options.
Use the existing optional<PromptNumberOfTokensOrContent> as a sentinel to detect conflicts eagerly at parse time (throw immediately if a second prompt source is given). After the loop, the optional's own state is sufficient to validate --use_random_tokens: absent means -l was never given, string means --prompt/--prompt_file was given. This avoids adding fields to Options and keeps VerifyOptions' signature unchanged.
Contributor
Author
|
pls consider this for 0.14.0 if possible. |
Update random token generation as suggested
Baiju Meswani (baijumeswani)
approved these changes
May 21, 2026
Baiju Meswani (baijumeswani)
enabled auto-merge (squash)
May 21, 2026 14:05
Baiju Meswani (baijumeswani)
merged commit May 21, 2026
701c03d
into
microsoft:main
15 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a
--use_random_tokensflag to the C benchmark that feeds randomly.a valid text prompt for the target model.
Usage
Constraints
-l/--prompt_length(token count must be known upfront)--promptand--prompt_file