debug: add LSE verification and merge debug prints

This commit is contained in:
2026-05-28 23:54:30 +00:00
parent 2f2259395e
commit 869460a932

View File

@@ -144,6 +144,9 @@ static int test_single(int T, int n_h = 1, int batch = 1) {
cs /= (sqrtf(na)*sqrtf(nb)+1e-10f);
if(cs<min_cos) min_cos=cs;
if(cs<0.999f) { printf(" FAIL b=%d h=%d t=%d cos=%.6f\n",b,h,t,cs); failed++; }
// Check LSE
float lse_err = fabsf(h_lse[idx*T+t] - lse_ref[t]);
if(lse_err > 0.01f) { printf(" FAIL LSE b=%d h=%d t=%d kernel=%.6f ref=%.6f err=%.6f\n",b,h,t,h_lse[idx*T+t],lse_ref[t],lse_err); failed++; }
}
}
}
@@ -218,6 +221,13 @@ static int test_multitile_merge(int T) {
free(h_o_tile);
}
// Debug: print first LSE values per tile
for (int tile = 0; tile < N_TILES; tile++) {
printf(" tile %d lse[0]=%.6f", tile, lse_per_tile[tile * T]);
if (T > 1) printf(" lse[1]=%.6f", lse_per_tile[tile * T + 1]);
printf("\n");
}
// Python KV merge with normalized O + LSE:
// O = Σ exp(lse_i - L) * O_i_norm / Σ exp(lse_i - L)
// where L = max(lse_i) for numerical stability