Repository navigation
accel.moe: drop padding ids through the routing tables; padding not counted (#89) - #288
Merged
Merged
Conversation
…-call masks (#89) The owner/local tables get one extra entry whose owner is no tier, so padding ids (-1 and num_experts, as in transformers' expert parallelism) reach no tier: no per-call compare/clamp/mul kernels on the decode path. The routing EMA and tier counts no longer count padding as expert 0; the native dispatcher skips padding ids instead of indexing the owner table with -1. opt_grouped_mm starts from zeros (an inf in hidden_states no longer becomes NaN). tests/conftest.py skips tests that need a transformers 5 model family on transformers 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tables dispatch.c now takes num_experts and skips any id outside [0, num_experts) instead of reading owner[] out of bounds for ids above num_experts. _snapshot builds the padded owner/local tables once per placement instead of two torch.cat per layer call on the decode path. The routing-id contract ([-1, num_experts]) is documented on _padded_tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
#89: after #83,
OffloadedLayer.forwardmasked and clamped the routing on every call (about 5 extra kernel launches × 48 layers per decode token), padding ids were counted as hits on expert 0, andopt_grouped_mmturned an inf inhidden_statesinto NaN. This is PR #98 rebased onto current optimus-rm with the review fixes; #98 was closed only because the GPU A/B had no valid run on a busy host. That A/B has now run on a quiet host.Changes
accel/moe/layer.py: the owner/local routing tables get one extra entry owned by no tier, so padding ids-1andnum_expertsreach no tier with no per-call ops; the device count bins, the Python fast path and the general split skip it; the routing EMA countsids mod (E+1)and drops the padding bin. The padded host tables are built once per placement. The id contract ([-1, num_experts]) is documented on_padded_tables.platforms/cpu/csrc/dispatch.c/native.py:moe_disp_starttakesnum_expertsand skips any id outside [0, num_experts).accel/moe/batched.py:opt_grouped_mmstarts from zeros connected to both inputs through empty slices (zero gradients for all-padding calls, no NaN from inf).num_experts.Verification
pytest tests/test_moe_review.py tests/test_moe_offload.py: 118 passed, 1 skipped (CPU + one A100). Full suite: CI.moe_offload_generate.py --gpu-budget-gb 20 --kv-cache --max-new-tokens 128, greedy, torch 2.10.0+cu128, transformers 5.1.0. A = optimus-rm 0e69cc9, B = this change (c8f2de8; the MoE/CPU code is byte-identical on this branch, rebased onto aad0ff2). One warmup per side, then 19 alternating A/B pairs. Runs during which another process used at least one full core were discarded (8 runs).B was faster in 11 of 13 paired clean runs. Generated text was identical in all 40 runs, and every run routed the same work (36301 GPU / 15923 CPU expert pairs). The gain is less GPU time waiting on the CPU expert tier (2.70 s → 2.53 s per generate).
Compatibility and limits
Related Issue
Closes #89. Supersedes #98.
🤖 Generated with Claude Code