Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions tensorrt_llm/_torch/modules/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,10 @@ def load_weights_fused_qkv_linear(self, module: Linear,
if os.environ.get("TRTLLM_LOAD_KV_SCALES", "0") == "1":
if len(k_scale) != 0:
assert len(v_scale) != 0
# The calibrated KV scales are amax / (6 * 448), but the requested KV scales are amax / 448,
# to avoid overflow when dequantizing NVFP4 in attention kernels.
copy_weight(
module.kv_scales,
torch.tensor(
[1.0, max(k_scale) * 6.0,
max(v_scale) * 6.0],
dtype=torch.float32))
[1.0, max(k_scale), max(v_scale)], dtype=torch.float32))
module.inv_kv_scales.data = 1.0 / module.kv_scales

def load_weights_fused_gate_up_linear(self, module: Linear,
Expand Down Expand Up @@ -1096,14 +1092,10 @@ def load_weights_fused_qkv_linear(self, module: Linear,
if os.environ.get("TRTLLM_LOAD_KV_SCALES", "0") == "1":
if len(k_scale) != 0:
assert len(v_scale) != 0
# The calibrated KV scales are amax / (6 * 448), but the requested KV scales are amax / 448,
# to avoid overflow when dequantizing NVFP4 in attention kernels using FP8 math.
copy_weight(
module.kv_scales,
torch.tensor(
[1.0, max(k_scale) * 6.0,
max(v_scale) * 6.0],
dtype=torch.float32))
[1.0, max(k_scale), max(v_scale)], dtype=torch.float32))
module.inv_kv_scales.data = 1.0 / module.kv_scales

def load_weights_fused_gate_up_linear(self, module: Linear,
Expand Down