diff --git a/single_shot_inference.py b/single_shot_inference.py index 742495aa..11082a42 100644 --- a/single_shot_inference.py +++ b/single_shot_inference.py @@ -429,6 +429,13 @@ def forward_layer(X_l, w, li, cfg, rope_cos, rope_sin, w[f"{pre}.q_b_proj.weight_scale"], w[f"{pre}.q_b_proj.weight_scale_2"]) # (T, n_h * hd) + # q_b_norm — unweighted RMSNorm after q_b_proj (paper §2.3.1) + # This is critical: normalizes Q before attention, preventing score collapse. + # No learnable parameters — just q / RMS(q). + q_f = q.float() + q_rms = q_f.pow(2).mean(-1, keepdim=True).add(1e-6).rsqrt() + q = (q_f * q_rms).bfloat16() + # -- KV projection (MQA: 1 KV head) + KV norm -- kv = nvfp4_linear(x_normed, w[f"{pre}.kv_proj.weight"],