Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
bf93e83b
Commit
bf93e83b
authored
Mar 04, 2026
by
zhangshao
Browse files
解决fp8 kv cache scale错误问题
parent
3fe3d07c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
2 deletions
+3
-2
vllm/attention/layer.py
vllm/attention/layer.py
+3
-2
No files found.
vllm/attention/layer.py
View file @
bf93e83b
...
...
@@ -358,10 +358,11 @@ class Attention(nn.Module, AttentionLayerBase):
query
,
key
,
value
,
self
.
layer_name
)
def
calc_kv_scales
(
self
,
query
,
key
,
value
):
self
.
check_fp8_overflow
=
False
if
self
.
calculate_kv_scales
==
False
:
if
self
.
kv_cache_dtype
in
{
"fp8"
,
"fp8_e4m3"
}
and
torch
.
abs
(
query
).
max
().
item
()
<=
200
:
#check fp8 overflow
return
if
torch
.
abs
(
query
).
max
().
item
()
>=
0.01
:
#check fp8 too small
if
self
.
kv_cache_dtype
in
{
"fp8_e5m2"
}
and
torch
.
abs
(
query
).
max
().
item
()
>=
0.01
:
#check fp8 too small
return
bias
=
0.0
# add bias to avoid q values are too small(or zeros) and scales are not correct
if
torch
.
abs
(
query
).
max
().
item
()
<
0.01
:
...
...
@@ -378,7 +379,7 @@ class Attention(nn.Module, AttentionLayerBase):
self
.
_v_scale_float
=
self
.
_v_scale
.
item
()
# We only calculate the scales once
self
.
calculate_kv_scales
=
False
self
.
check_fp8_overflow
=
False
def
extra_repr
(
self
)
->
str
:
s
=
f
"head_size=
{
self
.
impl
.
head_size
}
"
# type: ignore
...
...
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