Skip to content
Discussion options

You must be logged in to vote

Yes. Current JAX supports sequence-length-aware attention, with one important distinction: the public API uses padded dense tensors plus per-example length vectors, not FlashAttention-style flattened packed tokens with cumulative offsets.

The batched shapes are:

  • Query: [B, T, N, H]
  • Key/value: [B, S, K, H]
  • Query lengths: [B], int32
  • Key/value lengths: [B], int32
  • Output: [B, T, N, H]

N is the number of query heads and K is the number of key/value heads. N must be divisible by K; K == N is MHA, K == 1 is MQA, and intermediate divisors are GQA. Each sequence's valid tokens occupy the prefix of its padded row.

import jax
import jax.numpy as jnp


def varlen_attention(q, k, v, q_lengths, kv_le…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fountaindive
Comment options

Answer selected by fountaindive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants