refactor: consolidate speculative-validate profiling gating and fitting. - #2274
Open
weizhehuang0827 wants to merge 1 commit into
Open
refactor: consolidate speculative-validate profiling gating and fitting.#2274weizhehuang0827 wants to merge 1 commit into
weizhehuang0827 wants to merge 1 commit into
Conversation
- Hoist the adaptive gate out of profile_speculative_validate_time() to the ProfileManager ctor call site via should_profile_speculative_validate(), so the "only profile when adaptive speculative decode is enabled" intent is visible where profiling is orchestrated (the function keeps a defensive self-guard). - Move the least-squares fit + MAE/MAPE + coefficient sanitization into TimePredictor::fit_for_speculative_validate, matching fit_for_decode / fit_for_prefill. ProfileManager::train_speculative_validate_time_predictor now only maps the fitted coefficients into the registry struct and keeps the broadcast-first-then-commit publish path. - Strengthen TimePredictor::check_coefficients_non_neg to also clamp non-finite (NaN/Inf) coefficients, not just negatives; a rank-deficient QR solve or NaN latency sample could otherwise pass a negative-only check. Pure refactor: same design matrix, same publish contract, no behavior change to the adaptive controller.
weizhehuang0827
requested review from
DongheJin,
DragonFive,
JimHsiung,
Kang-Meng,
liujinguang0125,
liutongxuan,
ustcfy,
xiao-yu-chen,
yingxudeng,
yinjiawei01 and
zhang-minchao
as code owners
August 19, 2026 11:01
ustcfy
approved these changes
Aug 19, 2026
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
Pure refactor of the speculative validate-time profiling in
ProfileManager,no behavior change to the adaptive speculative controller.
validate-time predictor when adaptive speculative decode is enabled" now
lives in
should_profile_speculative_validate()and is checked at theProfileManagerctor where profiling is orchestrated, instead of beingburied inside
profile_speculative_validate_time(). The function keeps adefensive self-guard so a direct call cannot profile a config the controller
would never consume.
TimePredictor. The least-squares fit + MAE/MAPE +coefficient sanitization moves into
TimePredictor::fit_for_speculative_ validate, matching the existingfit_for_decode/fit_for_prefill.ProfileManager::train_speculative_validate_time_predictornow only maps thefitted coefficients into the registry struct and keeps the
broadcast-first-then-commit publish path (unchanged).
check_coefficients_non_negto also clamp non-finite(NaN/Inf) coefficients, not just negatives. A rank-deficient QR solve or a
NaN latency sample can otherwise slip through a negative-only check
(
NaN < 0is false). This matches the sanitizer the speculative pathpreviously did inline and now benefits the prefill/decode predictors too.
Test
xllm+all_tests).predictor still fits and the fit now logs from
TimePredictor::fit_for_speculative_validate(
Fitted speculative validate equation: ...), confirming the delegationpath. The adaptive controller consumes the predictor exactly as before.