Repository navigation
Conversation
Collaborator
Author
|
Superseded by #5327 (merged). #5327 landed the same winners-only merge for Closing as superseded; the behaviour is covered by |
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 #5324.
Problem
#5295's all-or-nothing short-circuit only skips a full-reservoir merge when every new row loses to the worst kept priority. On a real routed expert that is rare — each of a capture's ~75 rows survives with probability about
cap / seen, so all-losing is under 1% of full-reservoir merges. OLMoE-2L stayed at 48,882 merges / 7.54 s.#5327 (merged after this branch started) already replaced the full
cap + countconcat/topk with a drop-set search, but it still ranks the whole capture on every merge. This branch is rebased onto currentmain(67de3469) and keeps #5327's drop-set merge as the fallback path.Fix
Build on #5327's drop-set merge with the per-row prefilter the issue asks for:
winners = priorities < kept.max()(strict, so a tie keeps the kept row) and skips the merge when there are none.len(winners)rows can leave, and they are the largest of(len(winners) largest kept rows + winners). The drop/insert therefore runs on2 * len(winners)candidates instead of2 * count, and only the surviving new rows are copied into the freed slots.used < budget_cap(the one-time crossing) and a capture with at least as many winners as kept rows keep perf(awq): size routed-expert reservoirs from their own captures (#5284) #5327's generalized drop-set path unchanged.capkept rows. Ties at the boundary keep the kept row (the old topk tie order was unspecified).CPU-side only; device and provenance handling are unchanged.
Measurements
The issue's CPU repro (64 experts x 128 captures, rows ~N(75, 30), cap 906, hidden 2048, bf16,
torch.set_num_threads(1)),time.process_time(), one process per tree, this container's CPU (the reporter's CPU is ~1.8x faster; the ratio is the point).full_few/full_manysplit by the number of winners (<16 / >=16) before the call:35d97a79(pre-#5327)92276f43(current main, #5327)That is -14% vs current main and -39% vs pre-#5327, with the same call count and the same all-losing skips. The winning path's remaining dominant cost is the copy of the surviving rows (a 5-row bf16 scatter is ~13 us against ~132 us for 75 rows).
I did not re-run the OLMoE-2L wall clock in this environment; the CPU simulation is the same measurement the issue used to size the cost.
Also repairs current main's capture-perf tests
#5327's merge makes two
torch.topkcalls and fills the same kept set into different buffer slots, so on currentmainthese fail:test_a_winning_capture_still_merges(asserts exactly onetopkcall)test_tied_priorities_take_the_merge_path(asserts exactly onetopkcall)test_merge_matches_the_previous_algorithm[2](compares the buffer elementwise)This PR updates them:
assert calls, a tie now skips the merge and keeps the kept row, and the equivalence oracle canonicalizes by(source, row)before comparing (the method docstring says the buffer layout is deliberately not a contract). The kept rows, priorities, sources and row indices are still compared exactly.Tests
test_a_realistic_capture_merges_only_its_winners: 24 x 75-row captures fill a 906-slot reservoir, then a 75-row capture with two winners must never rank more thancap + 2elements (fails on pre-perf(awq): size routed-expert reservoirs from their own captures (#5284) #5327 main:topksees 981). It also checks the result against the previous algorithm.test_a_capture_that_beats_every_kept_row_still_merges: more winners than kept rows exercises the fallback path.tests/test_awq_capture_perf_5284.py,test_awq_moe_quant_speed_5284.py,test_awq_reservoir_incremental_5233.py,test_awq_reservoir_sibling_rows_5267.py,test_awq_token_row_position_5265.py,test_awq_token_rows_bounded_capture_5137.py,test_awq_hash_moe_kept_rows_5015.py,test_awq_moe_root_capture_4697.py,test_awq_weight_mean.py,test_awq_shift_capture_5094.py,test_awq_deepseek_v4_hash_moe_4880.py,test_awq_hybrid_moe_root_4903.py,test_awq_sink_token_rows_5275.py: 168 passed, 1 skipped.bash format/check.shpasses.Docs:
docs/awq-calibration-aggregation.mdnow describes the per-row prefilter and pins the new test nodes.