Fix MHC_DIAG null check when SKIP_MHC is enabled
This commit is contained in:
@@ -406,7 +406,7 @@ def forward_layer(X_l, w, li, cfg, rope_cos, rope_sin,
|
||||
else:
|
||||
# -- mHC pre_block (attention) --
|
||||
x_in, attn_ctx = attn_mhc.pre_block(X_l) # x_in: (T, H)
|
||||
if MHC_DIAG: # mHC diagnostics
|
||||
if MHC_DIAG and attn_ctx is not None: # mHC diagnostics
|
||||
B_l, C_l = attn_ctx.B_l, attn_ctx.C_l
|
||||
print(f" L{li} pre_attn: |X_l|={X_l.abs().max().item():.2f} |x_in|={x_in.abs().max().item():.2f}", flush=True)
|
||||
|
||||
@@ -558,7 +558,7 @@ def forward_layer(X_l, w, li, cfg, rope_cos, rope_sin,
|
||||
# -- mHC post_block (attention) --
|
||||
X_mid = attn_mhc.post_block(X_l, F_attn, attn_ctx) # (T, n_hc, H)
|
||||
# Diagnostic: check mHC is stabilizing the residual
|
||||
if MHC_DIAG: # mHC diagnostics
|
||||
if MHC_DIAG and attn_ctx is not None: # mHC diagnostics
|
||||
B_l, C_l = attn_ctx.B_l, attn_ctx.C_l
|
||||
print(f" L{li} attn: |X_l|={X_l.abs().max().item():.2f} |F_attn|={F_attn.abs().max().item():.2f} |B|={B_l.abs().max().item():.4f} |C|={C_l.abs().max().item():.4f} |X_mid|={X_mid.abs().max().item():.2f}")
|
||||
# Check B_l is doubly stochastic (rows sum to 1.0)
|
||||
@@ -589,7 +589,7 @@ def forward_layer(X_l, w, li, cfg, rope_cos, rope_sin,
|
||||
else:
|
||||
# -- mHC post_block (FFN) --
|
||||
X_next = ffn_mhc.post_block(X_mid, F_ffn, ffn_ctx) # (T, n_hc, H)
|
||||
if MHC_DIAG: # ffn mHC diagnostics
|
||||
if MHC_DIAG and ffn_ctx is not None: # ffn mHC diagnostics
|
||||
B_l_ffn, C_l_ffn = ffn_ctx.B_l, ffn_ctx.C_l
|
||||
print(f" L{li} ffn: |X_mid|={X_mid.abs().max().item():.2f} |F_ffn|={F_ffn.abs().max().item():.2f} |B|={B_l_ffn.abs().max().item():.4f} |C|={C_l_ffn.abs().max().item():.4f} |X_next|={X_next.abs().max().item():.2f}", flush=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user