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
cd4da1f1
Unverified
Commit
cd4da1f1
authored
Sep 26, 2025
by
Mohammad Miadh Angkad
Committed by
GitHub
Sep 25, 2025
Browse files
Refactor kv_cache_scheme handling for quantization (#10132)
parent
91678474
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
10 deletions
+31
-10
python/sglang/srt/layers/quantization/modelopt_quant.py
python/sglang/srt/layers/quantization/modelopt_quant.py
+31
-10
No files found.
python/sglang/srt/layers/quantization/modelopt_quant.py
View file @
cd4da1f1
...
@@ -140,11 +140,21 @@ class ModelOptFp8Config(QuantizationConfig):
...
@@ -140,11 +140,21 @@ class ModelOptFp8Config(QuantizationConfig):
# Flat format (config.json quantization_config)
# Flat format (config.json quantization_config)
# For kv_cache, check if kv_cache_scheme exists and extract algo
# For kv_cache, check if kv_cache_scheme exists and extract algo
kv_cache_scheme
=
config
.
get
(
"kv_cache_scheme"
)
kv_cache_scheme
=
config
.
get
(
"kv_cache_scheme"
)
if
(
kv_cache_scheme
kv_cache_type
=
None
and
kv_cache_scheme
.
get
(
"type"
)
==
"float"
kv_cache_bits
=
None
and
kv_cache_scheme
.
get
(
"num_bits"
)
==
8
if
isinstance
(
kv_cache_scheme
,
dict
):
):
# Handles the expected format: {"type": "float", "num_bits": 8}
kv_cache_type
=
kv_cache_scheme
.
get
(
"type"
)
kv_cache_bits
=
kv_cache_scheme
.
get
(
"num_bits"
)
elif
isinstance
(
kv_cache_scheme
,
str
):
# Handles the shorthand format: "FP8"
if
kv_cache_scheme
.
upper
()
==
"FP8"
:
kv_cache_type
=
"float"
kv_cache_bits
=
8
# Now, safely use the extracted values
if
kv_cache_type
==
"float"
and
kv_cache_bits
==
8
:
kv_cache_quant_method
=
"FP8"
kv_cache_quant_method
=
"FP8"
# Map 'ignore' field to 'exclude_modules'
# Map 'ignore' field to 'exclude_modules'
...
@@ -594,11 +604,22 @@ class ModelOptFp4Config(QuantizationConfig):
...
@@ -594,11 +604,22 @@ class ModelOptFp4Config(QuantizationConfig):
if
not
kv_cache_quant_algo
:
if
not
kv_cache_quant_algo
:
# For config.json format, derive from kv_cache_scheme if available
# For config.json format, derive from kv_cache_scheme if available
kv_cache_scheme
=
config
.
get
(
"kv_cache_scheme"
)
kv_cache_scheme
=
config
.
get
(
"kv_cache_scheme"
)
if
(
kv_cache_scheme
kv_cache_type
=
None
and
kv_cache_scheme
.
get
(
"type"
)
==
"float"
kv_cache_bits
=
None
and
kv_cache_scheme
.
get
(
"num_bits"
)
==
8
if
isinstance
(
kv_cache_scheme
,
dict
):
):
# Handles the expected format: {"type": "float", "num_bits": 8}
kv_cache_type
=
kv_cache_scheme
.
get
(
"type"
)
kv_cache_bits
=
kv_cache_scheme
.
get
(
"num_bits"
)
elif
isinstance
(
kv_cache_scheme
,
str
):
# Handles the shorthand format: "FP8"
# We can infer the properties from the string.
if
kv_cache_scheme
.
upper
()
==
"FP8"
:
kv_cache_type
=
"float"
kv_cache_bits
=
8
# Now, safely use the extracted values in the original logic
if
kv_cache_type
==
"float"
and
kv_cache_bits
==
8
:
kv_cache_quant_algo
=
"FP8"
kv_cache_quant_algo
=
"FP8"
else
:
else
:
kv_cache_quant_algo
=
"auto"
kv_cache_quant_algo
=
"auto"
...
...
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