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.

train: reject a dataset whose split is shorter than --seq + 1

Leo Camusfc33c89ef2ea
diff --git a/03-minigpt-train/main.asm b/03-minigpt-train/main.asm
index f308340..0842f0d 100644
--- a/03-minigpt-train/main.asm
+++ b/03-minigpt-train/main.asm
@@ -355,6 +355,18 @@ _start:
call gpt_init_weights
.ready_train:
+ ; sample_batch reads T + 1 tokens from the start of a split, so each split it samples must hold them
+ mov rax, [rbp + TRN_SEQ]
+ cmp [rbp + TRN_TRAIN_LEN], rax
+ jbe .err_data_short
+ cmp qword [rel opt_eval_every], 0
+ je .data_len_ok
+ cmp qword [rel opt_dump_debug], 0
+ jne .data_len_ok
+ cmp [rbp + TRN_VAL_LEN], rax
+ jbe .err_data_short
+.data_len_ok:
+
; Decide whether live ANSI TUI is active:
; --dump-debug -> always plain
; --tui -> force TUI on
@@ -722,6 +734,13 @@ _start:
mov edi, 3
call sys_exit_group
+.err_data_short:
+ mov edi, 2
+ lea rsi, [rel msg_err_data_short]
+ call write_cstr
+ mov edi, 3
+ call sys_exit_group
+
.err_ckpt:
mov edi, 2
lea rsi, [rel msg_err_ckpt]
@@ -1883,6 +1902,7 @@ msg_close_nl: db ")", 10, 0
msg_err_need_load: db "error: --sample-only requires --load <ckpt>", 10, 0
msg_err_data: db "error: failed to load dataset", 10, 0
+msg_err_data_short: db "error: dataset too short for --seq (the train and val splits need seq + 1 bytes each)", 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