[Fix] logits: Preserve lm_head precision with shared buffers (#45855)

This commit is contained in:
YAMY
2026-10-22 12:46:27 -07:00
committed by GitHub
parent 0d6b283d7e
commit d67d1ae02c
2 changed files with 76 additions and 36 deletions
+3 -1
View File
@@ -1089,7 +1089,9 @@ class LogitsProcessor(nn.Module):
and hidden_states.dtype == lm_head.weight.dtype
and hidden_states.dtype in (torch.float16, torch.bfloat16)
)
if use_mm_out_dtype and (self.use_fp32_lm_head or out is not None):
# A shared FP32 buffer must not change the lm_head's output precision.
# Keep the same rounding as the unbuffered path unless FP32 is enabled.
if use_mm_out_dtype and self.use_fp32_lm_head:
logits = torch.mm(
hidden_states,
lm_head.weight.T,