interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

branch main Branches Tags History

MojoLlama / src / mojollama / kernels / .debug-context

43 lines · 1901 bytes Raw Blame History
1# Debug Log: NaN in qwen3_forward_c at layer 7
2
3## Bug
4C fused forward function qwen3_forward_c produces all-NaN output for Qwen3-30B 7+ layers. Layers 1-6 work correctly (max_logit ~17), layer 7+ produces NaN.
5
6## Model Architecture
7- Qwen3-30B: 48 layers, N=2048, NH=32, n_kv_h=4, HD=128, FF_total=6144
8- 128 experts, top_k=8, n_ff_expert=768
9- Attention weights: Q4_K (type 12), K: Q4_K, V: Q4_K, O: Q4_K
10- Expert gate/up: Q4_K (type 12), Expert down: Q6_K (type 14)
11- Output weight: Q8_0 (type 8), shape [151936, 2048]
12
13## The C Function
14A single #pragma omp parallel region wraps all 48 layers. Inside:
15- RMS norm (omp for reduction)
16- QKV projection (omp for per-row quant_matmul_omp calls)
17- RoPE (omp for)
18- KV cache update (omp single)
19- GQA inline attention (omp for over kv_heads)
20- Output projection (omp single calls quant_matmul_omp)
21- RMS norm again (omp for reduction)
22- MoE via moe_forward_omp (omp single calls moe_forward_omp)
23
24## What's Been Checked
251. Individual quant_matmul_omp calls work from Python ✓
262. L=1..6 work correctly in the C function ✓
273. NaN detection after norm, QKV, GQA all show NO NaN ✓
284. NaN detection AFTER the MoE (ffn_out check with abort()) also shows NO NaN
29
30## Critical Unresolved
31The NaN check AFTER `x[i] = res[i] + ffn_out[i]` (after MoE residual) also shows NO NaN with abort().
32But the final logits are ALL NaN (151936 elements).
33This means NaN appears in the OUTPUT PROJECTION section (after the parallel region ends).
34The output projection does:
35 1. Final RMS norm on x
36 2. quantize_q8_0_c(x, xn_q8, N)
37 3. quant_matmul_omp(w_out, x, logits, 151936, 2048, 8)
38The output weight is Q8_0 type 8 with shape [151936, 2048].
39
40## Task
41Read cengine_batch_instr.c (the qwen3_forward_c function at the end)
42Read quant_kernels_omp.c (quant_matmul_omp and q8_0_matmul_omp)
43Find why the output projection produces NaN when x, xn_q8 are valid.