Skip to content

Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.

fix(train): reject model shapes the kernels cannot use

shi-wang781d27f41d8f
diff --git a/03-minigpt-train/main.asm b/03-minigpt-train/main.asm
index 14cee9c..a7d469d 100644
--- a/03-minigpt-train/main.asm
+++ b/03-minigpt-train/main.asm
@@ -236,6 +236,23 @@ _start:
jmp .arg_lp
.args_done:
+ ; Kernels need D, head_dim and FF on a 16-float boundary, and H dividing D
+ mov rax, [rbp + TRN_DIM]
+ test al, 15
+ jnz .err_shape
+ mov rcx, [rbp + TRN_HEADS]
+ test rcx, rcx
+ jz .err_shape
+ xor edx, edx
+ div rcx
+ test rdx, rdx
+ jnz .err_shape
+ test al, 15
+ jnz .err_shape
+ mov rax, [rbp + TRN_HIDDEN]
+ test al, 15
+ jnz .err_shape
+
; Set RNG seed (must be non-zero for xorshift64*)
mov rax, [rel opt_seed]
test rax, rax
@@ -721,6 +738,13 @@ _start:
mov edi, 6
call sys_exit_group
+.err_shape:
+ mov edi, 2
+ lea rsi, [rel msg_err_shape]
+ call write_cstr
+ mov edi, 7
+ call sys_exit_group
+
; ============================================================================
; DATASET LOADER, VOCAB DISCOVERY, BATCH SAMPLER & VAL EVAL
; ============================================================================
@@ -1857,6 +1881,7 @@ msg_err_data: db "error: failed to load dataset", 10, 0
msg_err_ckpt: db "error: failed to load checkpoint", 10, 0
msg_err_save: db "error: failed to save checkpoint", 10, 0
msg_err_oom: db "error: mmap arena allocation failed", 10, 0
+msg_err_shape: db "error: --dim, --hidden and head_dim must be multiples of 16, and --heads must divide --dim", 10, 0
msg_usage:
db "asm-gpt-train (100% pure x86-64 AVX2/FMA Mini-GPT trainer & sampler, zero libc)", 10