Skip to content

Stage 2: cuDNN fmhaScaleBias variant (additive attention bias, cumulative on #37)#39

Merged
janpfeifer merged 3 commits into
gomlx:mainfrom
guygrigsby:stage2-bias
Jul 8, 2026
Merged

Stage 2: cuDNN fmhaScaleBias variant (additive attention bias, cumulative on #37)#39
janpfeifer merged 3 commits into
gomlx:mainfrom
guygrigsby:stage2-bias

Conversation

@guygrigsby

Copy link
Copy Markdown
Contributor

Stage 2 of the fused-attention work: the cuDNN ScaleBias variant for additive attention bias. Cumulative on top of Stage 1 (#37), the prerequisite; the Stage 1 commits show here too until #37 merges to main, then this shrinks to the bias delta.

selectFMHAVariant routes a non-nil bias to __cudnn$fmhaScaleBiasSoftmax and its backward; bias combines with causal, and bias+seqlens returns ErrNotImplemented (the ScaleBias kernel takes no seqlen operands) so it decomposes. Forward has the bias at operand index 3; backward at index 5 with an added dBias result at index 3, matching the JAX-lowered dot_product_attention(bias=..., implementation=cudnn) reference. Bias is cast to bf16 and shape-validated.

Validated on an RTX 3070 Ti: the non-uniform-V test shows the bias changes the output (it is genuinely applied), and forward and backward both match the decomposed reference.

…bias

selectFMHAVariant routes cfg.Bias to the fmhaScaleBias targets (bias+seqlens ->
ErrNotImplemented, cuDNN limitation). Bias operand inserted before seqlens (fwd)
and before O (bwd); backward declares the dBias result slot (not propagated).
validateBias requires bias dtype == q/k/v dtype (no auto-conversion, matching the
backend's explicit-dtype policy). Adapts onto the refactored dispatch/config.
…was hardcoded BF16)

The intermediate_tensor_shape element_type was hardcoded BF16, so the Float16
fused BACKWARD custom-call failed to compile ('Input datatypes do not match')
while the forward tolerated it. Derive it from the q/k/v dtype (BF16/F16) in
selectFMHAVariant, enabling f16 fused training (fwd+bwd).
@guygrigsby

Copy link
Copy Markdown
Contributor Author

Beyond the fmhaScaleBias bias variant, this includes a fix to the base fused path: flashBackendConfigV hardcoded the intermediate tensor element_type to BF16, so the Float16 fused BACKWARD custom-call failed to compile (Input datatypes do not match) while the forward tolerated the mismatch. Now derived from the q/k/v dtype (BF16/F16) in selectFMHAVariant.

This repairs f16 fused training generally, not just the bias path. Validated on cuda (RTX 3070 Ti): f16 fused forward+backward now compiles and matches the decomposed reference; full fusion suite green with no bf16 regression.

@janpfeifer janpfeifer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!! Looks good to me, I'll wait till the changes in compute are merged to merge this one.

@janpfeifer
janpfeifer merged commit af8f2aa into gomlx:main Jul 8, 2026
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants