-
Notifications
You must be signed in to change notification settings - Fork 249
perf(qwen35): add opt-in F32 rollback checkpoints for single-GPU inference #515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davide221
merged 4 commits into
Luce-Org:main
from
Amidwestnoob:perf/single3090-f32-rollback-clean
Jul 16, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #pragma once | ||
|
|
||
| #include <algorithm> | ||
| #include <cstdio> | ||
| #include <cstdlib> | ||
| #include <cstring> | ||
|
|
||
| namespace dflash::common { | ||
|
|
||
| struct ChainRollbackPolicy { | ||
| bool checkpoint_f32 = false; | ||
| int fast_rollback_threshold = 5; | ||
| bool diagnostics = false; | ||
| }; | ||
|
|
||
| inline bool env_flag_enabled(const char * name) { | ||
| const char * value = std::getenv(name); | ||
| return value != nullptr && value[0] != '\0' && std::strcmp(value, "0") != 0; | ||
| } | ||
|
|
||
| inline ChainRollbackPolicy resolve_chain_rollback_policy() { | ||
| ChainRollbackPolicy policy; | ||
| policy.checkpoint_f32 = env_flag_enabled("DFLASH_SINGLE_CHAIN_CHECKPOINT_F32"); | ||
| policy.diagnostics = env_flag_enabled("DFLASH_SINGLE_CHAIN_ROLLBACK_DIAG"); | ||
|
|
||
| // Lower thresholds are valid only with exact F32 checkpoints. This keeps | ||
| // the established F16 behavior unchanged when no opt-in flags are set. | ||
| if (policy.checkpoint_f32) { | ||
| const char * value = std::getenv("DFLASH_FAST_ROLLBACK_THRESHOLD"); | ||
| if (value != nullptr) { | ||
| const int requested = std::atoi(value); | ||
| if (requested >= 1 && requested <= 5) { | ||
| policy.fast_rollback_threshold = requested; | ||
| } | ||
| } | ||
| } | ||
| return policy; | ||
| } | ||
|
|
||
| // Rollback diagnostics shared by the two spec-decode loops | ||
| // (Qwen35Backend::do_spec_decode and run_dflash_spec_decode). Keeping the | ||
| // counters and the print format in one place prevents the loops from | ||
| // drifting when the diagnostics change. | ||
| struct RollbackDiag { | ||
| int accept_hist[17] = {}; | ||
| int fast_low = 0; // fast rollbacks below the F16 breakeven (accept_n < 5) | ||
| int fast_high = 0; // fast rollbacks at accept_n >= 5 | ||
| int legacy_replay = 0; | ||
| int failed_fallback = 0; | ||
|
|
||
| void record_accept(int accept_n) { | ||
| accept_hist[std::min(accept_n, 16)]++; | ||
| } | ||
| void record_fast_rollback(int accept_n) { | ||
| if (accept_n < 5) fast_low++; | ||
| else fast_high++; | ||
| } | ||
| void record_failed_fallback() { failed_fallback++; } | ||
| void record_legacy_replay() { legacy_replay++; } | ||
|
|
||
| void print(const ChainRollbackPolicy & policy, std::FILE * out) const { | ||
| if (!out || !policy.diagnostics) return; | ||
| std::fprintf(out, | ||
| "[chain-rollback-policy] checkpoint=%s threshold=%d fast_low=%d fast_high=%d legacy_replay=%d failed_fallback=%d accept_hist=1:%d,2:%d,3:%d,4:%d,5:%d,6:%d,7:%d,8:%d,9:%d,10:%d,11:%d,12:%d,13:%d,14:%d,15:%d,16+:%d\n", | ||
| policy.checkpoint_f32 ? "F32" : "default", | ||
| policy.fast_rollback_threshold, | ||
| fast_low, fast_high, legacy_replay, failed_fallback, | ||
| accept_hist[1], accept_hist[2], accept_hist[3], | ||
| accept_hist[4], accept_hist[5], accept_hist[6], | ||
| accept_hist[7], accept_hist[8], accept_hist[9], | ||
| accept_hist[10], accept_hist[11], accept_hist[12], | ||
| accept_hist[13], accept_hist[14], accept_hist[15], | ||
| accept_hist[16]); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace dflash::common | ||
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.