Repository navigation
[KV cache] support-past-present-share-buffer - #268
Conversation
🏗️ Architecture Diff
gemma4 (gemma4) / decoder — 9 change(s)Op summary: 127 → 125 nodes --- base
+++ head
@@ -47,14 +47,13 @@
MatMul
Constant
Reshape
-Cast
Mul
ReduceMean
Constant
+CastLike
Add
Sqrt
Div
-CastLike
Reshape
Attention
Transpose
@@ -91,14 +90,13 @@
MatMul
Constant
Reshape
-Cast
Mul
ReduceMean
Constant
+CastLike
Add
Sqrt
Div
-CastLike
Reshape
Attention
TransposeAdded nodes:
Removed nodes:
Connectivity changes:
gemma4 (gemma4) / vision_encoder — 95 change(s)Op summary: 190 → 202 nodes --- base
+++ head
@@ -50,8 +50,14 @@
Reshape
RMSNormalization
RMSNormalization
-CastLike
-RMSNormalization
+Mul
+Constant
+ReduceMean
+Constant
+CastLike
+Add
+Sqrt
+Div
Constant
Gather
Constant
@@ -175,16 +181,22 @@
Mul
Add
Constant
+CastLike
OneHot
-CastLike
-Transpose
-MatMul
-Constant
-CastLike
-Mul
-CastLike
-RMSNormalization
-Transpose
-MatMul
-Constant
-Reshape
+Transpose
+MatMul
+Constant
+CastLike
+Mul
+Mul
+Constant
+ReduceMean
+Constant
+CastLike
+Add
+Sqrt
+Div
+Transpose
+MatMul
+Constant
+ReshapeAdded nodes:
Removed nodes:
Modified attributes:
Connectivity changes:
Initializer changes:
gemma4_text / model — 9 change(s)Op summary: 129 → 127 nodes --- base
+++ head
@@ -49,14 +49,13 @@
MatMul
Constant
Reshape
-Cast
Mul
ReduceMean
Constant
+CastLike
Add
Sqrt
Div
-CastLike
Reshape
Attention
Transpose
@@ -93,14 +92,13 @@
MatMul
Constant
Reshape
-Cast
Mul
ReduceMean
Constant
+CastLike
Add
Sqrt
Div
-CastLike
Reshape
Attention
TransposeAdded nodes:
Removed nodes:
Connectivity changes:
Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
Performance Comparison
|
|
The author of this PR, rui-ren, is not an activated member of this organization on Codecov. |
There was a problem hiding this comment.
Pull request overview
This PR updates the ORT GenAI config generation path to enable past_present_share_buffer by default for more execution providers (via EpCapabilities), and refines the logic that caps max_length for memory-constrained EPs (e.g., WebGPU) to reduce KV-cache-related memcpy overhead.
Changes:
- Extend
EpCapabilitieswithcap_kv_buffer_max_lengthand setsupports_past_present_share_buffer=Truefor several built-in EPs. - Update
genai_configdefault search params to capmax_lengthbased on the new capability flag rather than tying it directly to buffer-sharing. - Update/add unit tests to reflect the new defaults and to cover the new max-length capping behavior for custom EPs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/mobius/integrations/ort_genai/genai_config.py | Switch max_length capping logic to a dedicated EP capability while propagating past_present_share_buffer from EP caps. |
| src/mobius/integrations/ort_genai/genai_config_test.py | Update expectations for CPU/CUDA defaults; add tests for custom EP max-length capping behavior. |
| src/mobius/_execution_providers.py | Add cap_kv_buffer_max_length to EpCapabilities and enable supports_past_present_share_buffer across more built-in EP entries. |
Comments suppressed due to low confidence (1)
src/mobius/_execution_providers.py:106
- EpCapabilities now has cap_kv_buffer_max_length but there is no invariant enforcement that it only makes sense when supports_past_present_share_buffer=True (as described in the docstring). Consider adding a post_init check that raises when cap_kv_buffer_max_length is True but supports_past_present_share_buffer is False, to prevent silent misconfiguration by custom EP registrations.
name: str
gqa_dtypes: frozenset[ir.DataType] = dataclasses.field(default_factory=frozenset)
qkv_pack_dtypes: frozenset[ir.DataType] = dataclasses.field(default_factory=frozenset)
supports_fused_rope: bool = True
supports_skip_layer_norm: bool = True
supports_fused_moe: bool = True
supports_packed_multi_head_attention: bool = False
default_int4_accuracy_level: int = 0
provider_options: dict[str, str] = dataclasses.field(default_factory=dict)
enable_graph_capture: bool = False
supports_past_present_share_buffer: bool = False
cap_kv_buffer_max_length: bool = False
def __post_init__(self) -> None:
if not self.supports_fused_rope and self.qkv_pack_dtypes:
raise ValueError(
|
Thanks! |
Support past present share buffer
Add
supports_past_present_share_buffer=TrueBenefit:
Save the
memcpyoverhead.