Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
7f399e4b
Unverified
Commit
7f399e4b
authored
Sep 19, 2025
by
huangtingwei
Committed by
GitHub
Sep 19, 2025
Browse files
[HiCacheStorage]support page_first_direct layout for generic set&get (#10522)
parent
873d858b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
python/sglang/srt/mem_cache/memory_pool_host.py
python/sglang/srt/mem_cache/memory_pool_host.py
+22
-0
test/srt/hicache/test_hicache_storage_file_backend.py
test/srt/hicache/test_hicache_storage_file_backend.py
+13
-0
No files found.
python/sglang/srt/mem_cache/memory_pool_host.py
View file @
7f399e4b
...
...
@@ -466,6 +466,9 @@ class MHATokenToKVPoolHost(HostKVCache):
return
self
.
kv_buffer
[:,
:,
index
:
index
+
self
.
page_size
,
:,
:].
flatten
()
elif
self
.
layout
==
"page_first"
:
return
self
.
kv_buffer
[:,
index
:
index
+
self
.
page_size
,
:,
:,
:].
flatten
()
elif
self
.
layout
==
"page_first_direct"
:
real_index
=
index
//
self
.
page_size
return
self
.
kv_buffer
[:,
real_index
:
real_index
+
1
,
:,
:,
:,
:].
flatten
()
else
:
raise
ValueError
(
f
"Unsupported layout:
{
self
.
layout
}
"
)
...
...
@@ -494,6 +497,13 @@ class MHATokenToKVPoolHost(HostKVCache):
2
,
self
.
page_size
,
self
.
layer_num
,
self
.
head_num
,
self
.
head_dim
)
)
elif
self
.
layout
==
"page_first_direct"
:
real_index
=
index
//
self
.
page_size
self
.
kv_buffer
[:,
real_index
:
real_index
+
1
,
:,
:,
:,
:]
=
(
data_page
.
reshape
(
2
,
1
,
self
.
layer_num
,
self
.
page_size
,
self
.
head_num
,
self
.
head_dim
)
)
else
:
raise
ValueError
(
f
"Unsupported layout:
{
self
.
layout
}
"
)
...
...
@@ -731,6 +741,9 @@ class MLATokenToKVPoolHost(HostKVCache):
return
self
.
kv_buffer
[:,
index
:
index
+
self
.
page_size
,
:,
:].
flatten
()
elif
self
.
layout
==
"page_first"
:
return
self
.
kv_buffer
[
index
:
index
+
self
.
page_size
,
:,
:,
:].
flatten
()
elif
self
.
layout
==
"page_first_direct"
:
real_index
=
index
//
self
.
page_size
return
self
.
kv_buffer
[
real_index
:
real_index
+
1
,
:,
:,
:,
:].
flatten
()
else
:
raise
ValueError
(
f
"Unsupported layout:
{
self
.
layout
}
"
)
...
...
@@ -762,6 +775,15 @@ class MLATokenToKVPoolHost(HostKVCache):
1
,
self
.
kv_lora_rank
+
self
.
qk_rope_head_dim
,
)
elif
self
.
layout
==
"page_first_direct"
:
real_index
=
index
//
self
.
page_size
self
.
kv_buffer
[
real_index
:
real_index
+
1
,
:,
:,
:,
:]
=
data_page
.
reshape
(
1
,
self
.
layer_num
,
self
.
page_size
,
1
,
self
.
kv_lora_rank
+
self
.
qk_rope_head_dim
,
)
else
:
raise
ValueError
(
f
"Unsupported layout:
{
self
.
layout
}
"
)
...
...
test/srt/hicache/test_hicache_storage_file_backend.py
View file @
7f399e4b
...
...
@@ -238,6 +238,19 @@ class TestHiCacheStorageLayerFirstDirectIO(HiCacheStorageBaseMixin, CustomTestCa
return
server_args
,
{}
class
TestHiCacheStoragePageFirstDirectIO
(
HiCacheStorageBaseMixin
,
CustomTestCase
):
"""Page first direct tests for HiCache Storage functionality"""
@
classmethod
def
_get_additional_server_args_and_env
(
cls
):
"""Get additional server arguments specific to configuration - override in subclasses"""
server_args
=
{
"--hicache-mem-layout"
:
"page_first_direct"
,
"--hicache-io-backend"
:
"direct"
,
}
return
server_args
,
{}
class
TestHiCacheStoragePageFirstLayout
(
HiCacheStorageBaseMixin
,
CustomTestCase
):
"""Page first layout tests for HiCache Storage functionality"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment