Repository navigation
[OPUS] [Perf] Avoid zero-initializing the MoE Stage1 scale workspace - #5178
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
valarLip
approved these changes
Sep 1, 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.
Motivation
OPUS MoE Stage1 allocated its aligned output-scale workspace with
torch.zeroson every invocation. This launched an E8M0 elementwise fill kernel even though Stage1 overwrites every scale associated with a valid route and Stage2 discards results from padding routes.For the DeepSeek-V4 workload, the aligned workspace has shape
(12288, 16). Zero-initializing it costs about 5 us per invocation and places a repeated fill kernel on the decode critical path. The goal of this PR is to remove that unnecessary initialization without changing the workspace layout, dtype, routing behavior, or kernel interfaces.Technical Details
_make_out_scaleinaiter/ops/opus/moe_stage1_a8w4.pyfromtorch.zerostotorch.empty.torch.float8_e8m0fnudtype, device placement, and tensor shape.Test Plan
0x00,0x7F,0xFE,0xFF, and random byte patterns, then compare valid Stage1 and Stage2 outputs bit for bit.0xFFand0xFEbefore exercising the actualtorch.emptypath.Test environment:
cd161f16bd041b63bc3bc4f234f3d1915a80200drocm/atom-dev@sha256:1cd6abf29958cf0c332041b945249f7303ac86a36352f976b26d844ad72b4f5c2.10.0+rocm7.2.4.git3d3aa833Test Result
Single-operator correctness passed:
0xFF.torch.emptypath remained bitwise identical after forced allocator reuse from0xFF- and0xFE-prefilled buffers.Single-operator performance:
torch.zeros)torch.empty)(12288, 16)Full-model trace comparison:
FillFunctormetricThe target
vectorized_elementwise_kernel<..., FillFunctor<c10::Float8_e8m0fnu>, ...>was completely removed from all eight optimized traces. The summed duration above is an arithmetic sum across parallel ranks, not wall-clock latency.End-to-end validation:
The concurrent full-model runs showed noticeable run-to-run and tail-latency noise, so they are not used to claim a stable end-to-end throughput improvement. The deterministic result of this change is the complete removal of the targeted E8M0 fill launches. GSM8K showed no aggregate accuracy regression; concurrent serving was not byte-deterministic between runs, with 1,291 of 1,319 extracted answers matching and a net gain of four correct answers in the optimized run.
Submission Checklist