vllm.distributed.kv_transfer.kv_connector.v1.moriio.moriio_layout
¶
Classes:
-
HeadLayout–Byte addressing of one attention layer's KV heads in its region.
-
MambaOffsetTemplate–Slot-independent conv+ssm offset decomposition for a KDA layer.
-
MambaStateLayout–Byte addressing of one mamba layer's per-slot conv and SSM state.
-
MambaTransferGeometry–Geometry of a hybrid (mamba/KDA) layer's recurrent state.
Functions:
-
apply_mamba_offset_template–Apply per-request slot bases to a cached
MambaOffsetTemplate. -
build_mamba_offset_template–Precompute the slot-independent conv+ssm offset decomposition.
-
compute_head_slice_offsets–Offsets copying
num_headsheads of each local block into a remote one. -
compute_mamba_conv_split_count–Number of leading conv entries in a KDA layer transfer plan.
-
compute_mamba_slice_offsets–(local, remote, sizes, n_conv) moving one target's share of the state.
-
get_layer_head_layout–Describe where each KV head of a block lives, from the cache strides.
-
get_mamba_transfer_geometry–Derive the slot-strided geometry of a KDA layer's conv + ssm state.
-
kda_conv_ssm–Return zero-copy conv and SSM views over a packed two-state page.
-
validate_transfer_block_ids–Check that a block transfer stays inside both sides' caches.
HeadLayout
¶
Bases: NamedTuple
Byte addressing of one attention layer's KV heads in its region.
Offsets are relative to the layer's registered region. plane_offsets
holds the start of the K and V planes when they are stored apart, or
(0,) when K and V are packed into each head's content.
Attributes:
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
is_dense
property
¶
Each block plane is one contiguous run of all its heads and tokens.
MambaOffsetTemplate
¶
Bases: NamedTuple
Slot-independent conv+ssm offset decomposition for a KDA layer.
Homogeneous-TP geometry (conv/ssm slot strides, conv sub-projection
offsets, ssm per-slot size) is identical across requests and across the
homogeneous GDN layers, so it is computed once and reused; only the
per-request slot bases vary (see apply_mamba_offset_template).
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
MambaStateLayout
¶
Bases: NamedTuple
Byte addressing of one mamba layer's per-slot conv and SSM state.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
MambaTransferGeometry
¶
Bases: NamedTuple
Geometry of a hybrid (mamba/KDA) layer's recurrent state.
A KDA layer's packed page is exposed as conv_state and ssm_state
views. Each is slot-strided, so a slot's bytes live at
slot * slot_stride * element_size and span slot_bytes. The two
tensors are registered as two separate MoRIIO regions per layer.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
_element_runs(layout, first_head, num_heads)
¶
One run per (token, head), ordered token-major.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
_head_runs(layout, first_head, num_heads)
¶
Coarsest (offset in block plane, size) runs covering num_heads heads.
Returns the run kind with the runs; two layouts can be paired run by run only when their kinds match.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
_state_slice(local_bytes, remote_bytes, local_slice, local_slices, remote_slice, remote_slices)
¶
(local offset, remote offset, size) of the bytes one target receives.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
apply_mamba_offset_template(template, local_slots, remote_slots)
¶
Apply per-request slot bases to a cached MambaOffsetTemplate.
Conv sub-projection entries (all slots) come first, followed by one ssm entry per slot.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
build_mamba_offset_template(conv, ssm, split_info, tp_ratio)
¶
Precompute the slot-independent conv+ssm offset decomposition.
Only homogeneous TP (tp_ratio == 1) is supported; heterogeneous TP is
gated with NotImplementedError (see the design doc). The returned
template is a pure function of the layer geometry and split_info, so it
can be cached and reused across requests without recomputation.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
compute_head_slice_offsets(local, remote, local_block_ids, remote_block_ids, local_head, remote_head, num_heads, merge_fn=merge_contiguous_offsets)
¶
Offsets copying num_heads heads of each local block into a remote one.
Local heads [local_head, local_head + num_heads) land on remote heads
[remote_head, remote_head + num_heads); every other remote head is
left for the producer rank that holds it.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
compute_mamba_conv_split_count(local_slots, split_info)
¶
Number of leading conv entries in a KDA layer transfer plan.
Entries [:count] are conv sub-projections (conv region/session);
entries [count:] are the per-slot ssm state (ssm region/session).
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
compute_mamba_slice_offsets(local, remote, local_slots, remote_slots, local_slice, local_slices, remote_slice, remote_slices)
¶
(local, remote, sizes, n_conv) moving one target's share of the state.
Entries [:n_conv] address the conv region; the rest the SSM region.
Each conv sub-projection and the SSM state are sharded across TP ranks
independently, so each is sliced or gathered on its own.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
get_layer_head_layout(layer_name, kv_cache, layer_to_spec)
¶
Describe where each KV head of a block lives, from the cache strides.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
get_mamba_transfer_geometry(conv, ssm)
¶
Derive the slot-strided geometry of a KDA layer's conv + ssm state.
conv/ssm are zero-copy views over the layer's packed page. Slot byte
offset is slot * slot_stride * element_size and each
slot spans subtensor[0].numel() * element_size bytes; the whole tensor
is registered as one region (*_region_len bytes).
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
kda_conv_ssm(kv_cache, spec)
¶
Return zero-copy conv and SSM views over a packed two-state page.
Source code in vllm/distributed/kv_transfer/kv_connector/v1/moriio/moriio_layout.py
validate_transfer_block_ids(local_block_ids, remote_block_ids, local_num_blocks, remote_num_blocks)
¶
Check that a block transfer stays inside both sides' caches.
A shorter or empty local list transfers only what decode allocated (a READ after a partial or full prefix hit); a longer local list is a bug.