"""The training range is the experiment. If an unseen N appears in training, nothing complains. Same silent-failure shape as the held-out cells in test_unseen: every arm still trains and every number still prints, and `unseen N` quietly becomes `seen N`. """ import torch import scale def test_training_never_sees_an_n_outside_its_range(): gen = torch.Generator().manual_seed(0) for lo, hi in ((2, 16), (17, 32)): ns = {a.shape[0] for a, _, _ in scale.mixed_batch(lo, hi, gen, size=200)} assert ns and min(ns) >= lo and max(ns) <= hi def test_training_range_actually_varies_n(): # A range that collapsed to a single N would make the whole axis meaningless while still # satisfying the bounds check above. gen = torch.Generator().manual_seed(1) ns = {a.shape[0] for a, _, _ in scale.mixed_batch(2, 16, gen, size=200)} assert len(ns) > 8 def test_one_parameter_set_evaluates_at_every_n(): # The property under test: the same object, unchanged, runs at any entity count. model = scale.make_model("rp", 0, 1.0) before = [p.clone() for p in model.parameters()] gen = torch.Generator().manual_seed(2) for n in (2, 7, 16, 25, 32): for a, r, m in scale.configs(n, 1, gen): assert scale.run_model(model, a, r, m).shape == (n, scale.D) assert all(torch.equal(x, y) for x, y in zip(before, model.parameters())) def test_floor_shrinks_as_n_grows(): # The measurement note in scale.py depends on this being true, so it is checked rather # than asserted in prose: pooling more neighbours lowers the target's variance, which is # why the mse/floor ratio must not be read as a trend down the N axis. tea = scale.teacher(0) gen = torch.Generator().manual_seed(3) floors = [scale.evaluate(tea, tea, scale.configs(n, 32, gen))[1] for n in (2, 8, 32)] assert floors[0] > floors[1] > floors[2]