flashinfer.cake_dsa_sparse_attention_det_train.cake_dsa_sparse_attention_det_nope_varlen

flashinfer.cake_dsa_sparse_attention_det_train.cake_dsa_sparse_attention_det_nope_varlen(q: Tensor, kv: Tensor, gather_kv_indices: Tensor, cu_seqlens_q: Tensor, cu_seqlens_k: Tensor, max_seqlen_q: int | None = None, max_seqlen_k: int | None = None, *, causal: bool = False, topk_length: Tensor | None = None, softmax_scale: float | None = None, return_lse: bool = False, key_passes: int | None = None, backend: str = 'cake', dkv_acc: Tensor | Callable | None = None, dkv_dst_map: Tensor | None = None, dkv_direct: bool | None = None, check_dst_map: bool | None = None, check_cu_seqlens: bool = False)

Packed multi-document form of cake_dsa_sparse_attention_det_nope() (SM100 / SM103 / SM107); every output repeats bit for bit.

Documents are packed along the first dimension of q (T = cu_seqlens_q[-1]) and of kv (S = cu_seqlens_k[-1]; [S, 512] or [S, 1, 512]); query and key lengths may differ per document: the query segment is the tail of its key prefix, so query local_q of document d sits at key position (seqlen_k[d] - seqlen_q[d]) + local_q. gather_kv_indices [T, K_slots] int32 hold key positions relative to the row’s document (-1 or >= seqlen_k[d] invalid; any K_slots >= 1) and are offset by cu_seqlens_k on device. The route follows the table size (cake_backend.NOPE_CONVERT_SLOT_LIMIT slots): below the limit, without caller lengths, the forward kernel converts the rows itself in its single launch, position-preserving; at or above it, and always with a caller topk_length, one launch right before the forward kernel compacts each row (valid keys first, in slot order, then -1), and the caller’s topk_length is a position cut applied before compaction. See cake_dsa_sparse_attention_det_nope() for the other arguments, the 1 / 16 default scale, the FP32 dK + dV semantics and the returns.

cu_seqlens_q and cu_seqlens_k are caller-owned prefix sums: int32 [num_docs + 1] tensors of one length on the device of q, starting at 0 and non-decreasing, cu_seqlens_q[-1] == T, cu_seqlens_k[-1] == S and seqlen_q <= seqlen_k for every document. Their structure is checked on every call; their values only with check_cu_seqlens=True, since that check synchronizes with the device.

Parameters:
  • check_cu_seqlens (bool) – True checks the values of cu_seqlens_q / cu_seqlens_k against the invariants above at the cost of one blocking device-to-host copy per call, before any launch (skipped during CUDA-graph capture). False (default) keeps the structural checks only.

  • causal (bool) – With True a slot that selects a key after the query’s own position is invalid too; False (default) takes the index row as is.

  • key_passes – As in cake_dsa_sparse_attention_det(): accepted for parity, validated, without effect.

  • dkv_direct – As in cake_dsa_sparse_attention_det(): accepted for parity, validated, without effect.

  • check_dst_map (Optional[bool]) – As in cake_dsa_sparse_attention_det().