Repository navigation
fix(awq): make the routed-expert capture a real uniform reservoir (#5204) - #5212
Merged
Merged
Conversation
) #5175 bounded routed-expert capture by resampling the kept buffer evenly together with each new batch. That is not a reservoir: once the buffer is full, the `budget_cap` kept rows -- which stand for every earlier batch -- weigh the same as the fresh batch, so each new batch replaces about `L / (cap + L)` of the sample and the surviving share decays geometrically. On a 128-document calibration set this put 70-87% of every routed expert's rows in the last quarter of the batches and left the first quarter at 1-5%, so AWQ picked each expert's scales and clip ranges on a sample dominated by the tail of the corpus. Dense modules and MoE roots were unaffected because they match the precomputed plan. Keep the `budget_cap` rows with the lowest deterministic uniform priority instead. That is the deterministic equivalent of Algorithm R: a uniform sample of every row seen, so a batch keeps a share proportional to its length wherever it falls in the stream. Memory stays O(cap) and the sample is reproducible across processes. Survivors are re-sorted into capture order so replayed rows and provenance stay grouped. Adds a regression test asserting every quarter of the calibration stream keeps 15-35% of the rows (raw share 25%). It fails on the pre-fix tree (quarter 0 kept 1.3%).
This was referenced Nov 18, 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.
Fixes #5204.
Root cause
#5175 bounded routed-expert capture by resampling the kept buffer evenly together with each new batch:
That is not a reservoir. Once the buffer is full, the
budget_capkept rows — which stand for every earlier batch — weigh the same as the fresh batch, so each batch ofLrows replaces aboutL / (cap + L)of the sample and earlier batches decay geometrically.Measured before the fix
128 C4 rows, budget 906, routed-expert row counts varying per batch:
After:
Fix
Keep the
budget_caprows with the lowest deterministic uniform priority. That is the deterministic equivalent of Algorithm R: a uniform sample of every row seen, so a batch keeps a share proportional to its length wherever it falls in the stream.O(cap): 43,385 raw rows × hidden 4096 would be ~678 MiB unbounded; the kept buffer is ~14 MiB.Tests
test_awq_token_rows_streaming_reservoir_keeps_every_quarter_proportionalasserts every quarter of the stream keeps 15–35% of rows. It fails on the pre-fix tree (quarter 0 kept 1.3%).tests/test_awq_token_rows_bounded_capture_5137.py.format/check.shclean.I could not run a real MoE checkpoint here (no OLMoE on this host, and the CUDA toolkit is unavailable), so the numbers above come from the same capture path exercised directly with varying per-batch row counts.