frame-benchmarking: allow 2-point slope fits in min_squares_iqr#12075
Merged
Conversation
`a33b7c2e36` short-circuits `min_squares_iqr` to `median_value` whenever `r.len() <= 2` to avoid OLS panics on `--steps=1 --repeats=1`. That fallback also catches the case where two samples sit at different x-values, where the slope is exactly determined. However, benchmarks whose valid sample set is narrowed to two values (e.g. by `BenchmarkError::Skip` filtering a `Linear<lo, hi>` parameter) lose their linear component. Route the `r.len() <= 2` fallback through `median_slopes` instead, which fits a slope exactly from two samples at different x-values. The degenerate "all samples share one x" case now surfaces an explicit error from `median_slopes`'s own check.
Contributor
Author
|
/cmd prdoc |
shawntabrizi
approved these changes
May 18, 2026
gui1117
approved these changes
May 20, 2026
gui1117
reviewed
May 20, 2026
|
Successfully created backport PR for |
EgorPopelyaev
added a commit
that referenced
this pull request
May 21, 2026
Backport #12075 into `unstable2604` from tindzk. See the [documentation](https://github.com/paritytech/polkadot-sdk/blob/master/docs/BACKPORT.md) on how to use this bot. <!-- # To be used by other automation, do not modify: original-pr-number: #${pull_number} --> Co-authored-by: Tim Nieradzik <tim@sparse.tech> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Egor_P <egor@parity.io>
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.
Description
a33b7c2 short-circuits
min_squares_iqrtomedian_valuewheneverr.len() <= 2to avoid OLS panics on--steps=1 --repeats=1. That fallback also catches the case where two samples sit at different x-values, where the slope is exactly determined. However, benchmarks whose valid sample set is narrowed to two values (e.g. byBenchmarkError::Skipfiltering aLinear<lo, hi>parameter) lose their linear component.Route the
r.len() <= 2fallback throughmedian_slopesinstead, which fits a slope exactly from two samples at different x-values. The degenerate "all samples share one x" case now surfaces an explicit error frommedian_slopes's own check.Integration
No API or storage changes. Downstream runtimes do not need to update code.
Regenerating weights may produce different values for benchmarks whose valid sample set is exactly 2 points at distinct x-values. The resulting weight expression will now include a linear component fitted via
median_slopesinstead of falling back to the constant median.Benchmarks whose 2 remaining samples share an x-value will now fail with an explicit
median_slopeserror rather than returning the median. If you see this, broaden the parameter range or increase--steps/--repeatsso more than one distinct x-value is sampled.Review Notes
min_squares_iqrhad a single guard combining two unrelated short-circuits:The
components.is_empty()branch is correct: a benchmark with no parameters has no slope to fit, so a constant median should be returned. Ther.len() <= 2branch was a workaround forlinregress's OLS fit, which is under-determined with two samples and one intercept + one slope variable. Both cases fell through to the samemedian_valuecall, which drops slopes entirely.The no-components fallback is kept on
median_value, whiler.len() <= 2is routed tomedian_slopesinstead.median_slopesis well-suited: it forms the pairwise slope list(y_i - y_j) / (x_i - x_j)over samples with distinct x-values, takes the median, then derives the intercept from per-sample offsets. With exactly two distinct-x samples the slope list has length 1, so the median is the exact slope. No regression is needed.