mstar.engine.resources.attn.base#
The attention resource’s shared machinery: the spec-time factory, the custom op every backend attends through, and the workspace pool.
The backends themselves live beside this — flashinfer, cross, dense, flex — and AttentionManager.build reaches them by deferred import, so naming a backend in a spec does not load the others.
Functions
|
Page ids a captured wrapper's index buffer holds for a bucket of |
|
The concrete backend for |
Classes
|
One eager wrapper — the counterpart of |
|
Fingerprint of a wrapper |
|
FlashInfer workspace buffers, one per (plan label, cg slot). |
- class mstar.engine.resources.attn.base.AttentionManager[source]#
Bases:
AttentionResource- classmethod build(spec, info)[source]#
- Parameters:
spec (AttentionSpec)
info (EngineResourceInfo)
- fingerprint()[source]#
What this resource contributes to the prefix cache’s root.
Everything a stored page depends on beyond its own tokens. None leaves the resource out of the root, which is right only where it cannot change what a page holds.
- Return type:
- property requires_kv_write: bool#
Whether a layer must write this step’s K/V through the KV resource before calling
run.False only for backends that take the fresh K/V straight into the kernel (the dense one). A layer therefore reads
- if self.attn.requires_kv_write:
self.kv.write_kv(k, v, layer_idx=i, label=label)
out = self.attn.run(q, label, kv.layer_view(i), k=k, v=v, layer_idx=i)
and stays correct whichever backend the spec named.
- class mstar.engine.resources.attn.base.EagerSlotKey(label, slot, is_decode=False)[source]#
Bases:
NamedTupleOne eager wrapper — the counterpart of
CGSlotKey, slotted for the same reason (FlashInfer’s plan stages into a pinned buffer per wrapper).
- class mstar.engine.resources.attn.base.PlanCacheKey(q_seq_lens, page_indices, last_page_lens)[source]#
Bases:
NamedTupleFingerprint of a wrapper
plancall’s inputs. When it is unchanged between steps the re-plan is skippable.
- class mstar.engine.resources.attn.base.WorkspacePool(device)[source]#
Bases:
objectFlashInfer workspace buffers, one per (plan label, cg slot).
Persistent: a wrapper is planned against the buffer it was built with, so these outlive any single step.
- Parameters:
device (device)
- mstar.engine.resources.attn.base.captured_page_capacity(num_rows, num_tokens, kv_config)[source]#
Page ids a captured wrapper’s index buffer holds for a bucket of
num_rowsrows andnum_tokenstokens.Per row, not per pool: rows that matched one cached prefix all name its pages, so a step can name more page ids than the pool holds. And at least the bucket’s own pages: a capture’s rows name a SINK_PAGE per page of span, whatever the pool’s size.
- mstar.engine.resources.attn.base.resolve_attn_backend(backend, device)[source]#
The concrete backend for
backendondevice.AUTObecomes the platform’s default, FlashInfer on every platform for now. A backend named in the spec or YAML is returned as is.- Parameters:
backend (AttnBackend)
device (device)
- Return type: