feat(kernels): explicit hd512 sm_scale and the final-logit softcap - #873
Merged
FeathBow merged 1 commit intoAug 14, 2026
Merged
Conversation
Signed-off-by: Feathbow <feathbow@gmail.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.
Description
Closes #872
The four hd512 attention wrappers baked in
rsqrt(512), and hd512's only prospective consumer cannot use it: Gemma 4 runs unscaled attention (scaling = 1.0in the HF reference, for both layer kinds). This makessm_scalean explicit parameter with a finite check, as the hd256 single-prefill wrapper already does. The entries have no current callers, so no call sites move.Alongside it, the last elementwise piece the 12B forward needs: an in-place final-logit softcap,
cap * tanh(x / cap)in f32 with a single rounding back to bf16. Every published Gemma 4 size declaresfinal_logit_softcapping30.0; nothing in the elementwise family could express it. The wrapper validates the cap positive and finite and the buffer extent under the crate's capacity contract; the launcher computes its grid with an overflow-free ceil-div.Test Env
Single GPU (sm_89, x86_64), CUDA 12.9,
PEGAINFER_REQUIRE_GPU=1.Verification
cargo fmt --all -- --check— clean.cargo build --release -p pegainfer-kernels --tests— clean.cargo clippy --release -p pegainfer-kernels --all-targets -- -D warnings— clean, zero diagnostics.cargo test --release -p pegainfer-kernels --test softcap_smoke— running 2 tests, 2 passed: the softcap op against a host f32 reference on constructed cases, and cap validation (rejects zero/negative/non-finite).Type of Change