Repository navigation
[Feature]: scaledDotProductAttention backward β gradients currently stop at attentionΒ #1384
Copy link
Copy link
Open
0 / 40 of 4 issues completedOpen
0 / 40 of 4 issues completed
Copy link
Labels
darcFeature driven through the DARC workflow (Document / Assess / Research / Code)Feature driven through the DARC workflow (Document / Assess / Research / Code)enhancementNew feature or requestNew feature or requesttrackingParent/tracking issue with sub-issuesParent/tracking issue with sub-issuestrainingTraining pipeline, optimizers, lossTraining pipeline, optimizers, loss
Description
π§ D: DOCUMENT β Problem & Opportunity
scaledDotProductAttentionBackward in skainet-compile/skainet-compile-dag/src/commonMain/kotlin/sk/ainet/lang/graph/DefaultExecutionTape.kt returns null for every input, so training any attention model silently produces no gradient for Q, K, V or anything upstream of them. It is now listed in stubbedBackwardOpNames and shows as β stub in the Backward column of the coverage matrix.
Summary: implement the SDPA adjoint (dQ, dK, dV, honouring scale, causal and padding masks) so attention layers train.
π A: ASSESS β Feasibility & Impact
- Feasibility: medium. The math is standard; the work is matching every forward option (
scale,causal, mask / key-padding lengths from [Feature]: key-padding lengths for scaledDotProductAttention β mask as op metadata, lengths-based loweringΒ #1343) and keeping memory reasonable (recompute the attention weights rather than storing them). - Risks: numerical stability of the softmax backward; masked positions must get exactly zero gradient.
π R: RESEARCH β What Must Be Understood First?
- Derivation note covering every forward option (Lane 1)
π οΈ C: CODE β Implementation Plan
- Implementation (Lane 2)
- Gradient check (Lane 4)
- Review (Lane 6)
Acceptance Criteria
- Gradients match PyTorch autograd for
torch.nn.functional.scaled_dot_product_attentionon causal and non-causal cases -
scaledDotProductAttentionremoved fromstubbedBackwardOpNames; matrix Backward column shows β
Lane breakdown
- [Lane 1 Β· numerics] SDPA backward β derivation note for the attention adjointΒ #1385 β [Lane 1 Β· numerics] derivation note for the attention adjoint (
size:s, good first issue) - [Lane 2 Β· kotlin-core] SDPA backward β implement scaledDotProductAttentionBackwardΒ #1386 β [Lane 2 Β· kotlin-core] implement scaledDotProductAttentionBackward (
size:m) - [Lane 4 Β· kotlin-core] SDPA backward β gradient check test for SDPAΒ #1387 β [Lane 4 Β· kotlin-core] gradient check test for SDPA (
size:s) - [Lane 6 Β· review] SDPA backward β review SDPA backwardΒ #1388 β [Lane 6 Β· review] review SDPA backward (
size:s)
Lanes 0, 3 and 5 skipped.
New here? Read Getting started as a contributor and the Issue taxonomy. Lanes marked good first issue assume no prior SKaiNET codebase knowledge. The gap markers and the coverage matrix were introduced in #1370.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
darcFeature driven through the DARC workflow (Document / Assess / Research / Code)Feature driven through the DARC workflow (Document / Assess / Research / Code)enhancementNew feature or requestNew feature or requesttrackingParent/tracking issue with sub-issuesParent/tracking issue with sub-issuestrainingTraining pipeline, optimizers, lossTraining pipeline, optimizers, loss
Activity
Link coverage gaps to their DARC tracking issues