Vision-model coding advice

This section walks the source that was actually executed. model.py and train.py are the mutable surface, which the notary restores after every non-keep, so the files on disk are not a reliable witness. Each listing below is read from the candidate commit a named run executed: the incumbent E0008 (development) and the sealed E0009 (test). E0009's candidate diff was empty, so its train.py is byte-identical to E0008's; the two provenance lines show the same hash. No verifier script is declared: the metric comes from the library evaluator kleinlib.eval_multiclass.evaluate_multiclass, which refuses non-finite probabilities and collapsed single-class predictions, prints the metric block and pins the confusion table.

The network: model.py at E0008

Three conv-BN-ReLU blocks (32, 64, 128 channels), max-pool after the first two, global average pooling and a linear head. The third block lifts the receptive field to about the whole cell, and global pooling makes the head independent of the image size.



The recipe: train.py at E0008

Four things deserve a close read. (1) d4 applies the dihedral symmetries to the training batch, inside the loop, from its own generator (SEED + 10_000), so the batch order stays identical to the anchor's at the same seed and an augmentation run is a paired comparison. (2) The budget is optimizer steps, not epochs, so runs compare across devices. (3) Batches come from iterate_minibatches, a streamed index shuffle, never a DataLoader over a TensorDataset. (4) After training, the BatchNorm running statistics are reset, set to a cumulative average (momentum = None) and recomputed over one pass of the training set in train mode with no gradient, before eval(). That block is the whole difference between E0003 and E0004.



The sealed cell: train.py at E0009

The same bytes, run once on the official test split after a dry run. The sealed refit trains on train plus development (13,668 rows against 11,959), a difference that comes from the contract's partition and not from the code.



Pitfalls and war stories that bit this study

  1. Default BatchNorm inference cost a candidate. E0003 added BatchNorm2d and scored 0.3005 because evaluation used momentum-0.1 running averages. An off-loop diagnostic (one seed, not evidence) showed batch-statistics accuracy staying high while eval-mode accuracy collapsed, which points at the inference path. Before calling a normalization candidate a failure, compare train-mode and eval-mode outputs, and recompute the statistics on the training set. The mechanism (averages lagging weights that are still moving at a constant learning rate) is an untested interpretation.
  2. One bundle, one unattributed gain. E0008 changed four levers together. Budget the single-lever cells inside the phase cap, or the gain stays unattributed.
  3. Measure fit noise, not only item noise. The bar came from an item bootstrap; the seed-block spread was several times larger at the anchor. Read each keep together with its seed spread.
  4. A near-duplicate audit before training. Eleven cross-split near-duplicates were removed from the evaluation partitions; state that the official split is image-level, not patient-grouped.
  5. Compare a sealed number with a published one in standard errors. A gap under two binomial standard errors is “indistinguishable” whatever the arithmetic verdict of a rule says.
  6. Per-seed tables, not one aux row. The aux rows of the earliest runs hold only the last seed; read runs/E####/seeds.tsv for seed means.
  7. Run the label-shuffled control. This study did not; the harness check therefore rests on analytic chance levels alone.