Skip to content

Commit 8e87b08

Browse files
authored
Applying scales rename to fp8 config (ROCm#387)
1 parent 84f5d47 commit 8e87b08

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

vllm/model_executor/layers/quantization/compressed_tensors/compressed_tensors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ def get_cache_scale(self, name: str) -> Optional[str]:
425425
return name.replace(".k_proj.output_scale", ".attn.k_scale")
426426
if name.endswith(".output_scale") and ".v_proj" in name:
427427
return name.replace(".v_proj.output_scale", ".attn.v_scale")
428+
if name.endswith(".output_scale") and ".q_proj" in name:
429+
return name.replace(".q_proj.output_scale", ".attn.q_scale")
430+
if name.endswith("self_attn.prob_output_scale"):
431+
return name.replace(".prob_output_scale", ".attn.prob_scale")
428432
# If no matches, return None
429433
return None
430434

vllm/model_executor/layers/quantization/fp8.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ def get_quant_method(self, layer: torch.nn.Module,
113113
return Fp8KVCacheMethod(self)
114114
return None
115115

116+
def get_cache_scale(self, name: str) -> Optional[str]:
117+
"""
118+
Check whether the param name matches the format for k/v cache scales
119+
in compressed-tensors. If this is the case, return its equivalent
120+
param name expected by vLLM
121+
122+
:param name: param name
123+
:return: matching param name for KV cache scale in vLLM
124+
"""
125+
if name.endswith(".output_scale") and ".k_proj" in name:
126+
return name.replace(".k_proj.output_scale", ".attn.k_scale")
127+
if name.endswith(".output_scale") and ".v_proj" in name:
128+
return name.replace(".v_proj.output_scale", ".attn.v_scale")
129+
if name.endswith(".output_scale") and ".q_proj" in name:
130+
return name.replace(".q_proj.output_scale", ".attn.q_scale")
131+
if name.endswith("self_attn.prob_output_scale"):
132+
return name.replace(".prob_output_scale", ".attn.prob_scale")
133+
# If no matches, return None
134+
return None
135+
116136

117137
class Fp8LinearMethod(LinearMethodBase):
118138
"""Linear method for FP8.

0 commit comments

Comments
 (0)