Skip to content

Stage 2: additive attention bias (config field + CPU reference)#4

Closed
guygrigsby wants to merge 3 commits into
stage1-seqlen-configfrom
stage2-bias
Closed

Stage 2: additive attention bias (config field + CPU reference)#4
guygrigsby wants to merge 3 commits into
stage1-seqlen-configfrom
stage2-bias

Conversation

@guygrigsby

Copy link
Copy Markdown
Owner

Reopens the Stage 2 bias work (compute#2 was accidentally merged into stage1-seqlen-config and reverted; stage1-seqlen-config has been reset to its clean Stage 1 head). Stacked on the Stage 1 PR branch. Bias only (dropout, bias+dropout, fp8 all cut as NotImplemented seams).

  • ScaledDotProductAttentionConfig.Bias Value (additive attention-score bias [B,H,Sq,Skv]; NOT the Q/K/V projection bias). Deduped via operand identity (equality compares the hasBias flag, not the Value).
  • go-backend CPU reference adds bias to scores pre-softmax; combines with causal + seqlens. validateBias (rank-4, exact shape) returns a clear error, not a panic. Capability stays false; direct unit tests.

Validated on RTX 3070 Ti via the downstream go-xla/gomlx bias PRs: cuDNN ScaleBias applies the bias forward + backward.

Stage 1: seqlen config fields + CPU reference + fp8 gate
Add Bias Value field to ScaledDotProductAttentionConfig. Thread it as an
operand through buildSDPANode (deduped via input identity, not equality
check). Extract it in the executor, transpose BSHD rank-4 bias to BHSD,
compute broadcast strides via sdpaComputeMaskStrides, and add to scores
before softmax in sdpaGeneric. No capabilities change; no dropout; no fp8.

Tests: TestSDPADirect_WithBias (bias shifts weights to strongly-favored key)
and TestSDPADirect_BiasWithCausal (causal masks future positions while bias
shifts scores within valid positions). Both confirm RED before implementation
and GREEN after.
…QA bias offset

Bias operand now checked: float dtype, rank 2-4, each dim broadcastable (1 or
equal) to the corresponding score dim [B,H,S,Skv]. Returns a wrapped error on
mismatch instead of panicking deep in the kernel.

Add one-line comment on the *groupSize term in the bias offset computation
(per-Q-head bias under GQA, mirroring the mask comment).

TestSDPADirect_BiasValidation covers rank-1, bad-kvdim rank-2, and bad-seqdim
rank-4 cases; existing WithBias/BiasWithCausal tests stay green.
@guygrigsby

Copy link
Copy Markdown
Owner Author

Superseded by the cumulative upstream PR gomlx#15 (Stage 2 bias, stacked on gomlx#13).

@guygrigsby guygrigsby closed this Jul 1, 2026
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.

1 participant