-
Notifications
You must be signed in to change notification settings - Fork 0
[None][feat] Support V2 Mamba disaggregated serving #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| # Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass, field | ||
|
|
@@ -48,12 +62,24 @@ class PhysicalPool: | |
| base_address: int # uint64 | ||
| slot_bytes: int | ||
| num_slots: int | ||
| # Distance between the starts of adjacent slots. Most pools are densely | ||
| # packed, so the stride defaults to the transferable payload size. V2 | ||
| # Mamba views point into a coalesced physical slot whose stride can be | ||
| # larger than the state payload described by ``slot_bytes``. | ||
| slot_stride_bytes: Optional[int] = None | ||
|
|
||
| def __post_init__(self) -> None: | ||
| if self.slot_stride_bytes is None: | ||
| self.slot_stride_bytes = self.slot_bytes | ||
| if self.slot_stride_bytes < self.slot_bytes: | ||
| raise ValueError("slot_stride_bytes must be greater than or equal to slot_bytes") | ||
|
|
||
| def to_dict(self) -> dict: | ||
| return { | ||
| "base_address": int(self.base_address), | ||
| "slot_bytes": int(self.slot_bytes), | ||
| "num_slots": int(self.num_slots), | ||
| "slot_stride_bytes": int(self.slot_stride_bytes), | ||
| } | ||
|
|
||
| @staticmethod | ||
|
|
@@ -62,6 +88,11 @@ def from_dict(data: dict) -> "PhysicalPool": | |
| base_address=int(data["base_address"]), | ||
| slot_bytes=int(data["slot_bytes"]), | ||
| num_slots=int(data["num_slots"]), | ||
| slot_stride_bytes=( | ||
| int(data["slot_stride_bytes"]) | ||
| if data.get("slot_stride_bytes") is not None | ||
| else None | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -204,6 +235,11 @@ class MambaLayerGroup(LayerGroup): | |
| ssm_states: Optional[PhysicalPool] = None | ||
| conv_section_bytes: Optional[List[int]] = None | ||
| ssm_bytes_per_head: Optional[int] = None | ||
| # V2 pools are slot-major and may coalesce several layer/role buffers into | ||
| # one physical slot. These are the manager-provided buffer offsets within | ||
| # slot 0; they cannot be derived with V1's layer-major pointer formula. | ||
| conv_layer_slot0_addresses: Optional[Dict[int, int]] = None | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be worth collapsing these four fields into a single optional
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is not true in V2. |
||
| ssm_layer_slot0_addresses: Optional[Dict[int, int]] = None | ||
|
|
||
| def to_dict(self) -> dict: | ||
| return { | ||
|
|
@@ -213,12 +249,24 @@ def to_dict(self) -> dict: | |
| "ssm_states": self.ssm_states.to_dict(), | ||
| "conv_section_bytes": self.conv_section_bytes, | ||
| "ssm_bytes_per_head": self.ssm_bytes_per_head, | ||
| "conv_layer_slot0_addresses": { | ||
| int(k): int(v) for k, v in (self.conv_layer_slot0_addresses or {}).items() | ||
| } | ||
| if self.conv_layer_slot0_addresses is not None | ||
| else None, | ||
| "ssm_layer_slot0_addresses": { | ||
| int(k): int(v) for k, v in (self.ssm_layer_slot0_addresses or {}).items() | ||
| } | ||
| if self.ssm_layer_slot0_addresses is not None | ||
| else None, | ||
| } | ||
|
|
||
| @classmethod | ||
| def from_dict(cls, data: dict) -> "MambaLayerGroup": | ||
| conv_section_bytes = data.get("conv_section_bytes") | ||
| ssm_bytes_per_head = data.get("ssm_bytes_per_head") | ||
| conv_layer_slot0_addresses = data.get("conv_layer_slot0_addresses") | ||
| ssm_layer_slot0_addresses = data.get("ssm_layer_slot0_addresses") | ||
| return cls( | ||
| pool_group_idx=int(data["pool_group_idx"]), | ||
| mamba_layer_offsets={int(k): int(v) for k, v in data["mamba_layer_offsets"].items()}, | ||
|
|
@@ -228,6 +276,14 @@ def from_dict(cls, data: dict) -> "MambaLayerGroup": | |
| if conv_section_bytes is not None | ||
| else None, | ||
| ssm_bytes_per_head=int(ssm_bytes_per_head) if ssm_bytes_per_head is not None else None, | ||
| conv_layer_slot0_addresses={ | ||
| int(k): int(v) for k, v in conv_layer_slot0_addresses.items() | ||
| } | ||
| if conv_layer_slot0_addresses is not None | ||
| else None, | ||
| ssm_layer_slot0_addresses={int(k): int(v) for k, v in ssm_layer_slot0_addresses.items()} | ||
| if ssm_layer_slot0_addresses is not None | ||
| else None, | ||
| ) | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layer_slot0_addresseslooks like it could be derived rather than stored. In the single contiguous pool it's equivalent tobase_address + lid*num_slots*stride, so it may be redundant. Andphysical_slot_stride_bytescaptures a genuinely necessary concept, but perhaps a single field would suffice since the conv/ssm pair is always equal (and derivable from the twoslot_bytessummed).block_stride_bytesmight also read a bit more clearly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In KVCacheManagerV2 the states are arranged in slot-first order, so we can't reuse the calculation of V1.