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 and validate CPU models. Use --align-from for an existing v1 checkpoint."""
import argparse
from pathlib import Path
from neural import Data, train, Model, torch
ROOT = Path(__file__).resolve().parent
def main():
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("--reuse", action="store_true", help="evaluate fitted output checkpoints")
group.add_argument("--align-from",type=Path, help="align an existing recurrent checkpoint and reuse its stateless comparator")
parser.add_argument("--output", type=Path, default=ROOT/"out")
args = parser.parse_args()
out = args.output.resolve()
out.mkdir(exist_ok=True, parents=True)
legacy = Data(ROOT/"data")
apps = Data(ROOT/"data", prefix="application-")
models = []
for recurrent,name in [(True,"recurrent_jev"),(False,"stateless_mlp")]:
table = None if recurrent else models[0].emb.detach()
if args.reuse or args.align_from:
source = args.align_from or out
model = Model(recurrent,table)
model.load_state_dict(torch.load(source/(name+".pt"),map_location="cpu",weights_only=True))
else:
model = train(legacy,recurrent,table)
if recurrent and not args.reuse:
from align import align
model = align(model,legacy,apps)
if not args.reuse:
torch.save(model.state_dict(),out/(name+".pt"))
models.append(model)
from evaluate import evaluate
evaluate(legacy,*models,out,applications=apps)
if __name__=="__main__":
main()