Skip to content

Boxz: train an 8.1M model, audit the torch engine, and gate the first Kaggle run - #1

Open
nachikethsr1 wants to merge 3 commits into
mainfrom
arena/982f5844-boxz
Open

nachikethsr1 wants to merge 3 commits into
mainfrom
arena/982f5844-boxz

Conversation

@nachikethsr1

Copy link
Copy Markdown
Owner

What this is

Three commits that take Boxz from "a NumPy transformer with a zip in git" to an 8.1 M-parameter model trained end to end, with the PyTorch engine audited, a real inference path added, and the Kaggle run made safe to start.

Most of the work was finding and fixing defects that would have silently invalidated a training run, not adding features.

Commits

commit what
add455c Trained an 8.1 M model from scratch (NumPy, CPU, 88 min) + SFT; busted the coding router answering questions
14bd9ae Audited the existing torch_engine, fixed corrupt-checkpoint resume, added PyTorch inference + verified KV cache
460dcb5 Pre-training gates: pinned tokenizer, resume-by-default, Kaggle preflight

Bugs fixed (each verified by a test that fails without the fix)

  1. Tokenizer could be silently retrained — boxz-live-8m.json had tokenizer_path: null and no tokenizer was committed. A fresh clone retrains a 2048-token BPE with different ids (a75f6d73 vs bc28e7e4). Every weight would train on the wrong token space. Now committed + pinned by sha, and train_gpu.py refuses to start without one.
  2. Corrupt newest checkpoint was chosen over a valid older one — find_latest sorted directory names and never opened them. A truncated step_000300 beat a valid step_000200 and resume died with UnpicklingError. That is the exact Kaggle kill-mid-write scenario.
  3. Silent progress reset — a bare TorchTrainer() on an existing run restarted at step 0 and overwrote it. Resuming is now the default.
  4. KV-cache cursor never advanced (in my own new module) — every decode step overwrote position 0; logit diff 12.3 → 1e-5 after the fix.
  5. English questions were claimed by the coding router — explain css grid matched the snake template, so the model never spoke.
  6. .gitignore ignored backups/**/*.bin — the exact files the comment above it promised to commit, defeating the backup-on-wipe design.

Measured results

value
Base model 8,115,200 params, 1,643,060 train tokens, val 3.9330 (ppl 51.1)
After SFT held-out loss 2.3619
torch vs NumPy logits (real checkpoint) worst 1.86e-05, argmax agreement 1.000, 76/76 tensors bitwise identical
Inference, CPU NumPy+KV 138.4 tok/s → torch+KV 156.1 (1.13–1.34×)
Training, CPU 1,624 tok/s vs NumPy 1,169 → 1.39×
Tests 786 passed, 0 failed (+3 slow)

Dataset audit (read-only, nothing modified)

5,558,271 B · sha 7f761dfd · 37,185 docs (29,408 unique) · 1,643,060 / 50,817 tokens, exact match to the run. No leakage: 40/40 val chunks absent from train, 0.84 % 13-gram overlap is URL/CSS boilerplate, longest shared run 36 tokens.

What is not claimed

  • No GPU was available — CUDA, AMP and torch.compile are BLOCKED, not verified.
  • No Rust toolchain — the crate is source-reviewed only, nothing built or benchmarked.
  • No historical 26 M / 3 M checkpoints exist in this checkout; no recovery is claimed.
  • No long training was run (200- and 100-step bounded benchmarks only).
  • Full 20k-step run is not started — pending authorization.

Next steps (documented in reports/PRETRAIN_READINESS.md)

GO for the first Kaggle run, conditioned on three manual actions: upload the corpus as a Dataset (python tools/preflight_kaggle.py kaggle-dataset), run cell 5a to prove GPU VERIFIED, and confirm the 8.1 M architecture is the intended run #1.

Docs

docs/MIGRATION_AUDIT.md · reports/MIGRATION_REPORT.md · reports/PRETRAIN_READINESS.md · reports/LIVE_5M.md · reports/live_5m.json

Boxz Agent and others added 3 commits December 1, 2026 14:23
…ering questions

Model run (measured, reproducible):
* base: 8,115,200 params, 1.64M train tokens, 2000 steps -> val loss 3.9330 (ppl 51.1)
* SFT: 350 steps over 218 examples, best held-out loss 2.3619
* fixed 20-prompt suite: 15% requirement-met, 70% own-turn stop, 122 tok/s
* reports/LIVE_5M.md, reports/live_5m.json, tools/live_eval_5m.py,
  configs/boxz-live-5m.json, checkpoints/registry.json entries
* weights packed into backups/live-sft5m (3 shards, 86 MB) so they survive a wipe

Bug: English questions were claimed by the coding template router --
'explain css grid' matched the snake template and 'what is the main idea
behind flexbox' was answered with a menu of projects, so the model never
spoke.  Question framing now routes to the model unless a build verb
follows it.  Regression tests in tests/test_coding_selection.py.

Bug: .gitignore ignored backups/**/*.bin, the exact files the comment above
it promised to commit -- a packed backup could never be pushed.  Fixed, with
a test that asks git itself.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
… inference

Audit finding: the brief assumed Boxz had no PyTorch engine. It already has
one (boxz/torch_engine, 1778 lines) and it is numerically faithful -- verified
directly on the 8.1M checkpoint: worst logit diff 1.86e-05 vs NumPy, argmax
agreement 1.000, 76/76 tensors bitwise identical. Building a second PyTorch
implementation would have been the rewrite the brief forbids, so this fixes
what was actually wrong and adds what was actually missing.

BUG (data loss): TorchTrainer.find_latest returned the newest step_* directory
without opening it. A truncated checkpoint left by a killed session was picked
over a valid older one and resume died with UnpicklingError. Added
verify_checkpoint() (files present, non-empty, parseable, model+optimizer
present, format version readable) and made find_latest skip failures
newest-first. 6 tests, 2 of which fail without the fix.

NEW: boxz/torch_engine/generate.py -- PyTorch inference with a verified KV
cache. PyTorch was training-only before this; every chat path ran NumPy. The
sampler is imported from the NumPy side so identical logits give identical
tokens. Also fixes a bug in my own first version: cache.length was never
advanced, so each step overwrote position 0 (max logit diff 12.3 -> 1e-5).
7 tests, 4 of which fail if the cursor advance is removed.

Measured (CPU, same checkpoint, same sampler):
  NumPy + KV cache      146.1 tok/s   1.00x
  PyTorch + KV cache    196.5 tok/s   1.34x
  PyTorch no cache       82.4 tok/s   0.56x

CLI: 'boxz torch sample' and 'boxz torch infer-bench'.
Docs: docs/MIGRATION_AUDIT.md, reports/MIGRATION_REPORT.md with explicit
VERIFIED/BLOCKED labels -- CUDA, AMP, torch.compile and Rust are BLOCKED in
this sandbox and are not claimed.

Full suite: 778 passed, 56 skipped (was 727 passed).

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
…reflight

Found while preparing the first Kaggle run, worst first:

1. TOKENIZER COULD BE SILENTLY RETRAINED (would invalidate every weight).
   configs/boxz-live-8m.json shipped tokenizer_path=null and no tokenizer is
   committed, so prepare_dataset retrains a 2048-token BPE on a fresh clone.
   Measured: same vocab size, DIFFERENT ids (sha a75f6d73 vs bc28e7e4; 3/3
   probes differ). Fixed by committing data/tokenizers/live-2048/ with a
   pinned-sha manifest, pointing all live configs at it, and making
   tools/train_gpu.py refuse to start without one (verified: exit 1).

2. SILENT PROGRESS RESET. A bare TorchTrainer(cfg, checkpoint_dir=...) on an
   existing run started at step 0 and overwrote it. Resuming is now the
   default; resume='none' is required to start over and logs what it discards.
   Also: resume='latest' on an empty dir now starts a fresh run instead of
   raising (that would have failed the first Kaggle session); an explicit
   missing path still refuses. The old test encoding the previous contract was
   rewritten deliberately into 3 tests; the safety is preserved.

Added:
  configs/kaggle-8m.json        session-sized config, ckpt dir /kaggle/working
  tools/preflight_kaggle.py     12 checks -> GO/NO-GO, and kaggle-dataset builder
  data/corpus_manifest.json     corpus + tokenizer provenance with sha256
  reports/PRETRAIN_READINESS.md audit, benchmark, status table, GO/NO-GO

Dataset audit (read-only): 5,558,271 bytes, sha 7f761dfd, 37,185 docs
(29,408 unique), 1,643,060 train / 50,817 val tokens -- exact match to the run.
No leakage: 40/40 val chunks absent from train; 0.84% 13-gram overlap is
cross-source boilerplate; longest shared run 36 tokens.

Bounded benchmark (measured, 2 vCPU, FP32, 8.1M params):
  100 steps 1,592.1 tok/s | 200 steps 1,623.9 tok/s | NumPy baseline 1,168.8
  => torch is 1.39x NumPy for training on CPU.

Tests: 786 passed, 56 skipped, 0 failed (was 778).
No production checkpoint touched (model.npz sha unchanged), no dataset
downloaded, no full training started, no history rewritten.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant