Skip to content

[Benchmark] Add --use_random_tokens flag to C benchmark - #2170

Merged
Baiju Meswani (baijumeswani) merged 7 commits into
microsoft:mainfrom
VishalX:vkjain/c-benchmark-random-tokens
May 21, 2026
Merged

[Benchmark] Add --use_random_tokens flag to C benchmark#2170
Baiju Meswani (baijumeswani) merged 7 commits into
microsoft:mainfrom
VishalX:vkjain/c-benchmark-random-tokens

Conversation

@VishalX

Copy link
Copy Markdown
Contributor

Summary

Adds a --use_random_tokens flag to the C benchmark that feeds randomly.

  • Generated token IDs (uniform in [0, 99]) directly into the prompt sequences, bypassing tokenization entirely.
  • This is useful for isolating model/runtime performance from tokenizer overhead and for benchmarking without requiring
    a valid text prompt for the target model.
  • Similar to benchmark_e2e.py
    parser.add_argument(
          "--use_random_tokens", action="store_true", help="Use random tokens instead of generating a prompt"
      )

Usage

model_benchmark -i <model-dir> --use_random_tokens -l 512 -g 128 -r 2 -w 2

Constraints

  • Requires -l/--prompt_length (token count must be known upfront)
  • Mutually exclusive with --prompt and --prompt_file

… 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.
Copilot AI review requested due to automatic review settings May 20, 2026 09:43
@VishalX
Vishal Jain (VishalX) requested a review from a team as a code owner May 20, 2026 09:43

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 --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_tokens CLI flag and corresponding Options::use_random_tokens setting.
  • 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_tokens validation is order-dependent because prompt_num_tokens_or_content is overwritten during parsing. E.g., --prompt "hi" -l 16 --use_random_tokens will pass verification and silently ignore --prompt, even though the help/PR description say --use_random_tokens cannot 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.");
  }

Comment thread benchmark/c/options.cpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@VishalX

Copy link
Copy Markdown
Contributor Author

kunal-vaishnavi / Baiju Meswani (@baijumeswani) pls review this, added a new option in c/benchmark similar to python variant.

Comment thread benchmark/c/main.cpp Outdated
Comment thread benchmark/c/main.cpp

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

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

Comment thread benchmark/c/options.cpp Outdated
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.
Comment thread benchmark/c/options.h Outdated
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.
@VishalX

Copy link
Copy Markdown
Contributor Author

pls consider this for 0.14.0 if possible.

Update random token generation as suggested
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