mstar.engine.resources.attn.ragged.block_causal#
Block-causal cacheless attention through FlashInfer’s paged prefill.
Within each declared span, a token in block b (block_size tokens a
block, counted from the span’s start) attends every key of blocks 0..b of
that span: causal between blocks, bidirectional within one. Whisper-style
encoders run this way so a streaming client sees the same features a
whole-clip forward would.
Prefixes of one span overlap, which a ragged kv_indptr (one contiguous key
range per query segment) cannot express. The paged kernel can: the packed
keys are viewed as pages of one token, and each query block is one paged
“request” whose page list is its prefix. No key is copied; the page lists are
host-side index arithmetic done at plan time.
Functions
|
|
|
Most query blocks a layout of at most this many spans and tokens has: every span may end on a partial block. |
|
Most page indices such a layout needs: one span holding every token, which maximizes the sum of its blocks' prefixes. |
Classes
|
FlashInfer's paged prefill over a packed, cacheless |
- class mstar.engine.resources.attn.ragged.block_causal.RaggedBlockCausalWrapper(workspace_buffer, num_qo_heads, num_kv_heads, head_dim, block_size, max_num_segments=None, max_total_tokens=None, device=torch.device('cuda'), accelerator_graph=False, sm_scale=None, q_data_type=torch.bfloat16, backend='auto')[source]#
Bases:
objectFlashInfer’s paged prefill over a packed, cacheless
[total, H, D]layout, planned block-causally per segment; see the module docstring.In graph mode the block count is padded to the bucket’s ceiling with zero-length blocks, and the index buffer is sized for the worst prefix sum the bucket’s token count allows, so any layout inside the bucket replays through the same captured kernel.
- Parameters:
- mstar.engine.resources.attn.ragged.block_causal.block_causal_layout(seg_lens, block_size)[source]#
(qo_indptr, kv_indptr, kv_indices)for spans packed end to end.One entry per query block. Block
iof a span starting atoffhas queries[off + i*B, off + min((i+1)*B, L))and keys[off, off + min((i+1)*B, L)).