Repository navigation
fix: chunk NPU graph rows to the largest token bucket (#171) - #180
Merged
Merged
Conversation
_bucket returns T itself above the largest bucket, so each new prefill length compiled and cached another graph (one per expert in baked mode). run() now splits longer inputs into chunks of the largest bucket, which reuse the bucket graphs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Background
GraphNPUBackend.runpads the token count up totoken_buckets, but_bucketreturnsTitself above the largest bucket (256 on RNGD, 64 on ATOM). Prefill rows reachedrun()unchunked, so every new prompt length compiled another graph (one per expert in baked residency) and_graphsgrew without bound. With a stub backend, prefill lengths 300-303 gave 4 compiles in inputs mode and 32 in baked mode.Changes
opt_prime/opt_prime/accel/platforms/npu_graph.py:249-252:run()splits inputs longer than the largest token bucket into chunks of that bucket and concatenates the chunk outputs, so long prefills reuse the bucket graphs.opt_prime/tests/test_moe_review.py:test_npu_graph_chunks_rows_above_the_largest_bucket[inputs|baked]uses buckets (1, 4), feeds T = 5, 6, 7, 9, checks the result against an unchunked backend (bucket 64) and that only bucket-sized graphs are requested.Verification
CPU only (
CUDA_VISIBLE_DEVICES=1, no NPU), Python 3.10, torch 2.10.0+cu128, base optimus-rm @253be20.New test on the unfixed code (from
opt_prime/):(outputs already matched; only the compiled shapes were wrong.) After the fix: 2 passed.
Stub-backend repro from the issue (Fake
_compilecounter, prefill lengths 300-303, default buckets): inputs mode 4 -> 2 compiles (buckets 256 and 64, once each); baked mode 32 -> 16 (8 experts x the same two buckets), and no further compiles for other lengths.Whole suite:
Compatibility and limits
RngdOptBackend.run(rngd/experts_opt.py) is a separate code path and is not changed.Related Issue
Closes #171
🤖 Generated with Claude Code