feat(linear-logp): add batch-invariant fused SM90 operator - #337
Draft
ThreeMonth03 wants to merge 1 commit into
Draft
feat(linear-logp): add batch-invariant fused SM90 operator#337ThreeMonth03 wants to merge 1 commit into
ThreeMonth03 wants to merge 1 commit into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ThreeMonth03
force-pushed
the
codex/batch-invariant-linear-logp-sm90
branch
from
August 24, 2026 22:12
a70f545 to
cb1ccb8
Compare
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.
The SM90 fused
linear_logpfrom #122 chooses its split-V schedule from the number of row blocks and the GPU SM count. This improves occupancy, but changing the batch size can also change the vocabulary partition and online-softmax merge order.As a result, the existing path is deterministic for a fixed shape but does not guarantee batch invariance: the same token row may produce different output bits when evaluated alone, moved within a batch, or evaluated in different chunks. This matters when rollout and training regroup the same tokens but compare their log probabilities exactly.
Method
This PR adds a separate forward-only
batch_invariant_linear_logpoperator for SM90. It reuses the fused TMA + tensor-core kernel while making the reduction topology independent of the token-row countN:V;The operator therefore preserves identical output bits across batch sizes, row positions, neighboring rows, and batch chunking without materializing the
[N, V]logits tensor.The initial scope is intentionally limited to single-card Hopper, BF16 hidden states and weights, and forward execution. Tensor parallelism, backward, and fallback backends are not included.
Verification
Tests cover FP32 reference accuracy and exact batch invariance across row positions, batch sizes, chunk sizes, vocabulary boundaries, layouts, and CUDA streams. The code compiles for CUDA 12.4 and 13.1, and the non-H100 test and lint suites pass.
The real SM90 launch and bitwise checks still require H100 GPU CI, so this PR remains a draft.
Related to #122. Potentially overlaps with the broader strict mode in #336.