ttnn.experimental.indexer_score_dsa

ttnn.experimental.indexer_score_dsa(q, k, weights, chunk_start_idx, key_compression_ratio, program_config, compute_kernel_config, cache_batch_idx, kv_len, seq_shard_axes, block_cyclic_sp_axis, block_cyclic_chunk_local, block_cyclic_cache_tp_sharded) → None

DeepSeek-V3.2 DSA / GLM-5 lightning-indexer scorer.

score[b, 0, s, t] = sum_h relu(q[b,h,s,:] . k[b,0,t,:]) * weights[b,0,s,h]

ReLU(q.kT) gated by the learned per-head weights and summed over ALL Hi index heads into one shared selection row [B, 1, Sq, T]. For MiniMax M3’s raw-dot, per-GQA-group indexer, use indexer_score_msa instead.

Parameters:
  • q[B, Hi, Sq, D] bf16 or bfp8_b tiled (post non-interleaved RoPE)

  • k[B, 1, T, D] bf16 or bfp8_b tiled, single shared head

  • weights[B, 1, Sq, Hi] bf16 tiled learned per-head gates (scale pre-folded).

  • chunk_start_idxabsolute global position of rank 0’s query row 0 (rank 0 = lowest seq_shard_axes[0] (SP) coord; causality: key t visible to query s iff t < floor((chunk_start + s + 1) / key_compression_ratio)). OMIT on a mesh -> deduced from compressed K as T*key_compression_ratio - sp_ring*Sq (sp_ring = mesh extent along the SP axis, whole mesh if unset). Single device: set to history + rank*Sq per rank.

  • key_compression_ratioquery tokens represented by one K-cache row. 1 (default) preserves legacy behavior; 4 enables compressed-key DSA. K sequence/output/kv_len are compressed rows, while query and chunk_start_idx geometry remain token units.

  • program_configwork-unit knobs (q_chunk_size, k_chunk_size, head_group_size; elements, tile-aligned). Defaults always fit L1; raise head_group_size (0 = all resident) for performance.

  • compute_kernel_configoptional DeviceComputeKernelConfig. Only math_fidelity is honored (default: HiFi2, or LoFi when q and k are both bfloat8_b); fp32_dest_acc_en / dst_full_sync_en must stay false (the custom LLK is validated for bf16 DEST half-sync).

  • cache_batch_idxoptional int. Selects the batch slot of a shared [B, 1, T, D] k cache (which may then be ND-sharded across DRAM banks). Re-applied each dispatch, so switching slots does not recompile.

  • kv_lenoptional int. Valid prefix of a k allocated at its full T; the rest is masked out. Tile-aligned, in (0, T], with chunk_start_idx < kv_len – the chunk must BEGIN inside the valid prefix, but its causal window MAY end past kv_len (and past T): those trailing rows are pad queries with no keys to attend. Re-applied each dispatch, so a serving loop growing kv_len (<= T) reuses one program – no recompile. Only output columns [0, kv_len) are written.

  • seq_shard_axesthe mesh axes the query seq is sharded over, outermost (SP ring) first: [] = linear device order (single device / whole-mesh ring, chunk_start_idx used as-is), [sp] = 1D SP ring, [sp, tp] = 2D SP ring + TP sub-shard. The SP axis (seq_shard_axes[0]) sets each device’s causal offset: device r along it uses chunk_start = chunk_start_idx + r*Sq (Sq = q seq len). The optional TP axis (seq_shard_axes[1]) is the SECOND axis the query seq is block-cyclically sub-sharded over; set it (with a block-cyclic layout, when block_cyclic_chunk_local == tp*q_isl) so the exact geometry adds tp_rank*Sq to each device’s block-cyclic position, keeping the causal mask correct under rotated (mid-slab) starts — unlike the flat [] path, which is linear-approximate there. The TP axis must be in range and distinct from the SP axis.

  • block_cyclic_sp_axisoptional int. The MESH AXIS the K cache was striped over (chunked prefill + SP all-gather leaves [B,1,T,D] k in per-SP-shard slab / block-cyclic physical order). sp is DERIVED from the mesh shape on that axis, so a caller cannot pass an sp that disagrees with the device. The reader reads the permuted cache back in natural token order (invP per tile) so scores come out token-ordered and the causal mask/pool stay exact. Unset (or sp==1) = contiguous K (no remap). Pair with block_cyclic_chunk_local. Interface matches ttnn.transformer.sparse_sdpa.

  • block_cyclic_chunk_localoptional int, REQUIRED with block_cyclic_sp_axis. The per-shard chunk length in QUERY-TOKEN rows (chunk_size_global / sp); the physical K chunk is this value / key_compression_ratio. Cross-checked against q: must equal q_isl (Sq, seq sharded only on the SP axis) or tp*q_isl (tp = mesh_size/sp). The tp*q_isl case with tp>1 (seq sharded across BOTH axes) has two forms: seq_shard_axes=[] uses flat row-major linearization over all devices (linear-approximate under a mid-slab start); seq_shard_axes=[sp, tp] names both axes, giving the rotation-exact 2D geometry (see seq_shard_axes above).

  • block_cyclic_cache_tp_shardedoptional bool (default False). KV dedup: the K cache is striped across ALL sp*tp devices (linear chip = sp_coord*tp + tp_coord), so only the invP key remap moves to (sp*tp, block_cyclic_chunk_local/tp) – the causal geometry is unchanged. Needs block_cyclic_chunk_local divisible by tp with a tile-aligned quotient.

Returns: score [B, 1, Sq, T] bf16 row-major; future/pad columns -inf.