[Benckmark] Benchmark refactor example#1199
Open
lowdy1 wants to merge 4 commits intolinkedin:mainfrom
Open
Conversation
Tcc0403
reviewed
Apr 25, 2026
Comment on lines
+130
to
+132
| def x_values_fn(config): | ||
| return [2**i for i in range(10, int(math.log2(config.seq_len)) + 1)] | ||
|
|
Collaborator
There was a problem hiding this comment.
Should we put it in build_token_length_sweep? I feel we can set this function as default x range.
Comment on lines
+121
to
+128
| def extra_config_fn(config): | ||
| return { | ||
| "bsz": config.batch_size, | ||
| "hidden_size": model.hidden_size, | ||
| "intermediate_size": model.intermediate_size, | ||
| "hidden_act": "silu", | ||
| "dtype": model.dtype, | ||
| } |
Collaborator
There was a problem hiding this comment.
How about we pass a key list to build_token_length_sweep and let it query those keys from model configs?
Comment on lines
106
to
119
| @@ -171,40 +118,41 @@ def _probe(): | |||
| x, layer = _setup_swiglu(probe_input) | |||
| return layer(x) | |||
Collaborator
There was a problem hiding this comment.
Same idea, add arguments probe_length/provider, and put probe_fn in build_token_length_sweep
| "model_configs": model_configs_info, | ||
| "bsz": sweep.batch_size, | ||
| "seq_len": sweep.seq_len, | ||
| def probe_fn(model_cfg, probe_seq_len): |
Collaborator
There was a problem hiding this comment.
Ditto. Could it merge into build_model_config_sweep?
5648ac6 to
f7e3e18
Compare
ef7d096 to
83c76fc
Compare
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
The current benchmark scripts contain significant boilerplate when constructing
common_configsforrun_benchmarks. Althoughcompute_model_config_sweep_configandcompute_seq_len_sweep_configprovide the core sweep logic, each script still:extra_benchmark_configcommon_configsassembly_resolve_*and*_model_configvariantsThis PR removes that duplication by introducing higher-level builders that standardize how benchmarks are defined.
Proposal
1. Introduce higher-level sweep builders
Add two unified helper functions in
benchmark_model_configs.py:These functions:
Wrap existing sweep utilities (
compute_*_sweep_config)Internally handle memory probing via
setup_fn + forward_fnAutomatically construct
extra_benchmark_configfrom:model_keys(dynamic model attributes)extra_configs(static overrides)Return a fully-formed
common_configsdictSo benchmark scripts reduce to:
2. Standardize kernel definition via
setup_fnInstead of manually writing
probe_fn, all kernels now define:The builders handle:
A default is provided:
This removes duplicated forward/probe logic across scripts.
3. Eliminate redundant helpers
The following patterns are removed across benchmark scripts:
probe_fndefinitionsextra_config_fn_resolve_model_config_*bench_*_model_configvariantsAll are now handled centrally by the builders.
New APIs
build_model_config_sweepB * T) approximately constantsetup_fn + forward_fnto estimate memory per modelbuild_token_length_sweepsetup_fn + forward_fnabstractionExample (after refactor)
Benchmark Command Examples
Notes
model_config: sweeps across different model configurations (fixed total tokens)token_length: sweeps across sequence lengths / batch sizes (fixed model) and this is the default and can be omittedmake testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergence