Add attention-internal diagnostics: MLA output, FP8 quant output

This commit is contained in:
2026-05-18 14:45:43 +00:00
parent 5c1dda10f6
commit 2a2a42c6d6
2 changed files with 10 additions and 1 deletions

View File

@@ -1754,7 +1754,7 @@ class DeepseekV4Model(nn.Module):
E2M1_LUT = torch.tensor([0, 0.5, 1, 1.5, 2, 3, 4, 6], dtype=torch.bfloat16)
self._dequant_nvfp4_to_bf16(mod, E2M1_LUT)
if layer_idx == 0:
print(f"[CLAWMINE] Layer 0: {proj_name} AFTER dequant: dtype={mod.weight.dtype} amax={mod.weight.data.amax().item():.4f} NaN={torch.isnan(mod.weight.data).any().item()}")
print(f"[CLAWMINE] Layer 0: {proj_name} AFTER dequant: dtype={mod.weight.dtype} amax={mod.weight.data.amax().item():.4f} NaN={torch.isnan(mod.weight.data).any().item()} quant_method={type(mod.quant_method).__name__}")
bf16_converted += 1
# FP8 conversion: wo_a (used by fp8_einsum, no input_scale)

View File

@@ -3,6 +3,7 @@
"""
DeepseekV4 MLA Attention Layer
"""
import os
from collections.abc import Callable
from dataclasses import dataclass
@@ -303,6 +304,10 @@ class DeepseekV4MultiHeadLatentAttentionWrapper(PluggableLayer):
)
o = o_padded[:, : self.n_local_heads, :]
if os.environ.get('CLAWMINE_DEBUG', '0') == '1':
with torch.no_grad():
print(f"[CLAWMINE] attn L{self.layer_name}: o amax={o.amax().item():.4f} NaN={torch.isnan(o).any().item()}")
# O projection: inverse RoPE + FP8 quant + einsum + wo_b
o_fp8, o_scale = fused_inv_rope_fp8_quant(
o,
@@ -315,6 +320,10 @@ class DeepseekV4MultiHeadLatentAttentionWrapper(PluggableLayer):
tma_aligned_scales=self._tma_aligned_scales,
)
if os.environ.get('CLAWMINE_DEBUG', '0') == '1':
with torch.no_grad():
print(f"[CLAWMINE] attn L{self.layer_name}: o_fp8 amax={o_fp8.float().amax().item():.4f} o_scale amax={o_scale.float().amax().item():.6f}")
wo_a_fp8 = self.wo_a.weight
wo_a_scale = self.wo_a.weight_scale_inv