[JAX] Return max_logit from TE fused attn - #3112
Conversation
4f3fbb3 to
9a56117
Compare
ca8551c to
fc151f9
Compare
fd2fff3 to
f31d5de
Compare
Greptile SummaryThis PR adds an opt-in per-head
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Sequence DiagramsequenceDiagram
participant App as JAX/Flax caller
participant API as fused_attn
participant Primitive as JAX fused-attention primitive
participant Native as Native TE/cuDNN
participant Mesh as Mesh reduction
App->>API: "QKV, return_max_logit=True"
API->>Primitive: Bind fused forward
Primitive->>Native: Output and Max buffers
Native-->>Primitive: Attention output and row-wise Max
Primitive->>Primitive: Reduce Max to per-head values
Primitive->>Mesh: pmax across non-head mesh axes
Mesh-->>API: Global per-head max_logit
API-->>App: (output, max_logit)
Reviews (8): Last reviewed commit: "[pre-commit.ci] auto fixes from pre-comm..." | Re-trigger Greptile |
cc33228 to
8dabb52
Compare
2cb2b8d to
032eeea
Compare
| NVTE_Bias_Type bias_type, NVTE_Fused_Attn_Backend backend, | ||
| void *softmax_buf, void *rng_state_buf = nullptr, | ||
| void *bias_buf = nullptr, | ||
| void *softmax_buf, void *max_buf = nullptr, |
There was a problem hiding this comment.
Can we rename max_buf to max_logits_buf
| nvte_set_tensor_param(&max_aux, kNVTERowwiseData, &max_aux_data); | ||
| } | ||
|
|
||
| NVTETensor &rng_state_aux = tensor_pack->tensors[size++]; |
There was a problem hiding this comment.
Do we need to check the capacity of tensor_pack->tensors here?
There was a problem hiding this comment.
I was not too concerned about it here, because I think the max size is 10 and with max_logit we will have 5 tensors only: 1 softmax + 1 max + 1 RNG + 1 bias + 1 offset = 5 maximum so I wasn't concerned about exceeding.
However, that's a good point for the future when someone is packing in more tensors in here. Let me push a change not only for max_logit but also for the other 4 tensors packed in sothat it serves as a template for any tensors being packed in the future
| (batch, head, q.shape[1], 1), -jnp.inf, dtype=jnp.float32 | ||
| ) | ||
| return output_per_step, softmax_aux_per_step | ||
| max_logit_per_step = FusedAttnFwdPrimitive._empty_or_neg_inf_max_logit( |
There was a problem hiding this comment.
Why does this instance use empty max logits?
There was a problem hiding this comment.
That's a good question @jberchtold-nvidia !
TL;DR: So, this is the no-compute branch for a fully causal masked Ring step and hence attention, softmax, isn't calculated in this branch and we need a neutral placeholder (-inf/0) because veery lax.cond branch must return the same shapes .
Let me try expanding on that:
With causal Ring attention, every rank cycles through KV blocks from all CP ranks. Some received KV blocks are entirely in the future relative to that rank’s query block and because causal attention must not attend to any token in such a block, TE skips the cuDNN attention call completely. So skip_compute does not run attention, softmax, or max-logit computation. It returns identity values so the JAX control flow and subsequent accumulation remain valid.
When max logits are requested, the helper returns [H] filled with -inf, so the skipped step cannot affect the running maximum. FWIW, it returns (0,) only when max-logit return is disabled.
| @@ -399,6 +399,12 @@ def test_softcap_score_mod_with_aux_params_backward( | |||
| ), | |||
| ] | |||
|
|
|||
There was a problem hiding this comment.
Can you run L1 CI on this PR? I don't see a CI run
There was a problem hiding this comment.
I had run the test suite locally only. Launched CI right now. Thanks for the reminder !
…x aux to the user from TE JAX fused attn output Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
… and softmax through the JAX fused attn primitives Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
…JAX fused attn tests Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
for more information, see https://pre-commit.ci
… function for it Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
b305c49 to
90a3eaf
Compare
|
/te-ci jax L0 L1 L2 |
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
Signed-off-by: Kshitij Lakhani <klakhani@nvidia.com>
3e247dd to
2e71bc8
Compare
for more information, see https://pre-commit.ci
Description
Return the max_logit from TE JAX fused attn to maintain parity with TE PyT fused attn.
Returning the softmax aux stats is a separate request and a bit mroe involved, so it'll be addressed separately.
Exposing the max_logit gives sufficient telemetry insight to users, for starters.
Fixes #2945
Test timing added
Type of change
Changes
Checklist: