Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9bca3f3
Project the softmax parametrization's log-weights exactly onto the ca…
MaxGhenis Oct 2, 2026
4bddde6
Record the in-loop cap ratio in the ACS tool and sweep; add the full-…
MaxGhenis Oct 2, 2026
1949e4b
Merge remote-tracking branch 'origin/l2-design-basis' into softmax-ex…
MaxGhenis Oct 2, 2026
493eacf
Measure the softmax cap step at full scale before and after the exact…
MaxGhenis Oct 2, 2026
c4bf1d4
Run the float32 cap-step measurement on Modal; record why the 32-roun…
MaxGhenis Oct 2, 2026
16ff6eb
Document the exact cap projection and its measurement; re-pin the dig…
MaxGhenis Oct 2, 2026
a0a05a6
Merge origin/main into softmax-exact-cap-projection
MaxGhenis Nov 3, 2026
c2acba5
Keep uncapped records their share when the caps hold the total (revie…
MaxGhenis Nov 3, 2026
8ae6934
Cite #1078's merged cap step in the rounds_32 docstrings (review N6)
MaxGhenis Nov 3, 2026
f86e9e1
Merge origin/main into softmax-exact-cap-projection
MaxGhenis Nov 3, 2026
51d0839
Merge origin/main into softmax-exact-cap-projection
MaxGhenis Nov 3, 2026
47c0625
Scope the measured-step pin and the measurement claims (review N2, N4…
MaxGhenis Nov 3, 2026
d57d336
Merge main 1e8831901 into softmax-exact-cap-projection and re-pin
MaxGhenis Nov 13, 2026
9a89cf8
Merge main 68bbff774 into softmax-exact-cap-projection and re-pin
MaxGhenis Nov 13, 2026
03035da
Scope the precision the softmax cap step claims (review R1)
MaxGhenis Nov 13, 2026
6bb9c46
Refuse to package a softmax summary from before the exact cap step (r…
MaxGhenis Nov 13, 2026
f728a31
Pin the cap step's precision note to three inputs (review R1, second …
MaxGhenis Nov 14, 2026
bbbae3c
Keep a subnormal remainder's value in the softmax cap sort (review ro…
MaxGhenis Nov 14, 2026
03ee2ea
Say a subnormal remainder reaches the sort only up to rounding (revie…
MaxGhenis Nov 14, 2026
6544a01
Re-pin the solve.py digests after the subnormal-remainder fix (review…
MaxGhenis Nov 14, 2026
3a0b4f7
Bound subnormal-remainder errors in steps of 2**-1074 (review round 1…
MaxGhenis Nov 14, 2026
74238ac
Show sub-step weights in full in the bisection test's failure message
MaxGhenis Nov 14, 2026
1568979
Merge main 085672fa9 into softmax-exact-cap-projection and re-pin
MaxGhenis Nov 14, 2026
2c49e27
Test that refusing an old softmax summary leaves no release directory…
MaxGhenis Nov 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.d/calibrate-chi-square-l2-basis.added.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add two opt-in options to Adam calibration and the ACS local-area tool. `l2_basis="chi_square"` (`--l2-basis chi_square`) makes the `l2_lambda` penalty GREG's design-weighted chi-square distance `sum(d * (w / d - 1) ** 2) / sum(d)`, which pulls toward the design weights themselves; the historical record-weighted `mean((w / d) ** 2)`, whose mass-conserved optimum is `w ∝ d ** 2`, stays the default. `mass_parametrization="softmax"` (`--mass-parametrization softmax`) conserves mass through `w = total * softmax(log_w)`; the historical per-step uniform shift, still the default, can stall away from the constrained optimum when every record's gradient shares a sign (on the ACS local release it does not, and softmax's per-step cap rounds run out on most epochs there, which the solve counts). Defaults reproduce the previous solver's bytes. Results record both settings and `CalibrationResult.chi_square_distance`; the tool records them, with the softmax cap-exhaustion count, in its calibration summary and build manifest, names all three penalty flags in the manifest's refresh recipe, and refuses to resume a checkpoint solved under other settings. See docs/calibration-l2-basis.md.
Add two opt-in options to Adam calibration and the ACS local-area tool. `l2_basis="chi_square"` (`--l2-basis chi_square`) makes the `l2_lambda` penalty GREG's design-weighted chi-square distance `sum(d * (w / d - 1) ** 2) / sum(d)`, which pulls toward the design weights themselves; the historical record-weighted `mean((w / d) ** 2)`, whose mass-conserved optimum is `w ∝ d ** 2`, stays the default. `mass_parametrization="softmax"` (`--mass-parametrization softmax`) conserves mass through `w = total * softmax(log_w)`; the historical per-step uniform shift, still the default, can stall away from the constrained optimum when every record's gradient shares a sign (on the ACS local release it does not). Defaults reproduce the previous solver's bytes. Results record both settings and `CalibrationResult.chi_square_distance`; the tool records them in its calibration summary and build manifest, names all three penalty flags in the manifest's refresh recipe, and refuses to resume a checkpoint solved under other settings. See docs/calibration-l2-basis.md.
1 change: 1 addition & 0 deletions changelog.d/calibrate-softmax-exact-cap.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`mass_parametrization="softmax"` now projects the log-weights exactly onto the capped simplex after every Adam step: one common shift, then a clamp to each cap. Active-set rounds find the shift in float64, and a sort finishes it in log space if they run long or the uncapped weights underflow float64. It replaces a renormalize/clamp loop of at most 32 rounds, which ran out on most epochs of the ACS local release because of float32 rounding (the overshoot it left was float32-sized, measured in `experiments/us-acs-local-l2-basis-20260928/results/exact_cap.md`). Softmax solves record `options["iterate_selection_receipt"]["softmax_in_loop_max_cap_ratio"]`, the largest in-loop weight over its cap, in place of the exhaustion count, and the ACS local-area tool carries it in its calibration summary and build manifest, where every build now names that key in place of `softmax_cap_rounds_exhausted_epochs` (null under the default projection). The tool's package stage refuses a softmax calibration summary written before this change, which holds the old count and no ratio: calibrate that checkpoint again. The default `"projection"` parametrization is unchanged.
139 changes: 111 additions & 28 deletions docs/calibration-l2-basis.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,100 @@ The total holds by construction, and autograd hands Adam the gradient with its
component along the constraint already removed. For a smooth objective that
reduced gradient vanishes at the constrained optimum; the capped-MAPE loss has
kinks, so Adam still oscillates there on the scale of `lr`, as it does under
`mass="free"`. The ratio cap remains a per-step clamp, alternated with the
softmax-invariant renormalization for up to 32 rounds, plus the closing
float64 projection that both parametrizations share. It requires
`mass="conserve"` and no L0 gates.

**Known limitation: the cap rounds run out at production scale.** Each
renormalization lifts the clamped records back over the cap by a shrinking
amount, so the rounds converge geometrically but need not reach float32
exactness in 32. A step that runs out ends on a clamp, and its next forward
pass optimizes `total·softmax(log_w)` past the cap, by an amount that is not
recorded.
`options["iterate_selection_receipt"]["softmax_cap_rounds_exhausted_epochs"]`
counts those steps. On small problems it is rare. On the ACS local release it
is the normal state: 165-400 of the last 400 epochs in every run that records
it, including 400 at the share-0.5, `l2_lambda = 0.03` configuration on the
full surface and on one fold, and 400 in every share-0.9 run. Only the
closing projection makes the returned vector exact. The returned loss stays
within 0.3% of the last trajectory loss in every run that records the count,
but projection runs, which have no cap loop, show the same gap (0.01-0.33%), so
that says nothing about the overshoot; its size is not measured. An
exact capped-softmax step (water-filling the excess onto the uncapped records)
would remove the limitation. Until then, prefer `"projection"` at that scale,
where the stall does not bite (below).
`mass="free"`. After every step the log-weights are projected exactly onto
the capped simplex `{w : sum(w) = D, w <= cap * d}`, and the closing float64
projection that both parametrizations share makes the returned vector exact.
It requires `mass="conserve"` and no L0 gates.

**The per-step cap projection.** It is the Kullback-Leibler projection: one
common shift `s` for every log-weight, then a clamp to each log cap,
`log_w <- min(log_w + s, log(cap * d))`. Uncapped records keep their
relative weights, the direction the softmax cannot see, and only records
whose share would pass their caps are held at them. `s` solves
`sum(min(exp(log_w + s), cap * d)) = D`, whose left side is continuous and
nondecreasing in `s`. Active-set rounds find it: with `C` the records already
at their caps, the next shift solves
`sum(cap * d[C]) + exp(s) * sum(exp(log_w)[not C]) = D`. That shift is a lower
bound on the answer for every `C`, so `C` only grows, and a round that adds
no record is exact. If eight rounds pass without that, a sort over the
remaining records finishes it, which bounds the worst case at `O(n log n)`.
Both paths compute the shift in float64. The same bound keeps
`D - sum(cap * d[C])` at least `exp(s) * sum(exp(log_w)[not C])`, the
uncapped records' share, so when rounding takes it to zero or below, the
capped records' caps already hold `D`: the rounds stop at the current shift,
and the other records keep a share below float64 rounding of `D`. When the
uncapped weights sum below float64's normal range, the rounds hand over to
the sort, which sums them in log space, so a weight that underflows float64
still counts. By the same bound, a remainder `D - sum(cap * d[C])` below
that range comes, up to rounding, only with such a sum; the sort and the
rounds both take its logarithm as it is, so it still sets the shift. The
hand-off buys range, not digits: the shift is exact up to the float64
rounding of its sums, which grows with how far below `D` the uncapped
weights sit and, in the sort, with their number. On 1,588,854
records with weights the size a solve's are (log-weights 9 to 24 nats below
`D`'s), the rounds leave `D` within 1e-13 of itself and the sort within
1e-11. With the same number of uncapped weights 690 nats below `D`, each
still in float64's normal range, the rounds stay within 1e-12 and the sort
ends 3e-11 off. Where a million uncapped records share one subnormal weight
and their sum is still normal, either path leaves `D` about 1e-11 off. The
solver then rounds `log_w` to float32, up to 5e-7 in a weight, so no solve
resolves any of these. The solve records
`options["iterate_selection_receipt"]["softmax_in_loop_max_cap_ratio"]`, the
largest ratio of a realized in-loop weight to its float64 cap over every
forward pass and the closing iterate, before the closing projection.
`test_softmax_cap_projection.py` pins those precision figures on those three
inputs and, on up to 40 records, the projection for every drawn input,
including zero weights and zero caps drawn independently, a cap of exactly
1, and inputs where some records' caps meet the total while the rest sit
below float64 rounding of it or below float64's range. It conserves the
total, respects every cap, is idempotent and invariant to a constant added
to the log-weights, and moves an input already within its caps by the shift
alone. It also meets the Kullback-Leibler projection's KKT conditions,
equals a water-fill written from the definition in 60-digit decimal
arithmetic, and gives the same answer by its active-set and sorted paths,
including on an input built to need one round per record. Where the caps
leave a remainder below float64's normal range, it matches a decimal
bisection on the shift. Wherever the cap step that the full-scale
measurement below ran settles in its active-set rounds, with every nonzero
weight in float64's normal range, the test checks that the current step
returns the same shift and round count, bit for bit.

**What the projection replaced.** Before, each step renormalized and clamped
in a loop of at most 32 rounds. On the ACS local release the rounds ran out on
most epochs, and how far that left the in-loop weights past their caps was
not recorded. It has since been measured
(`experiments/us-acs-local-l2-basis-20260928/results/exact_cap.md` and
`results/exact_cap_float32.json`):

- **Why the loop ran out.** Each round's shift was `log(D)` in float64 minus a
float32 `logsumexp`. On a vector already within its caps that difference
does not reach zero. It bottoms out at the float32 rounding residual of
`log(D)` itself, 7.8e-8 here. That shift lifts the one to three capped
records with log caps below 2 in magnitude one float32 step over their caps,
the clamp puts them back, and the next round repeats it. On full-scale vectors
the projection had already made exact, the loop still ran out in 10 of 12
trials.
- **How far past the cap it was.** Not materially. Two full-scale
configurations whose earlier runs ran out were rerun under both steps: share
0.5 at `l2_lambda = 0.03`, and share 0.9 unpenalized. The largest in-loop
weight over its cap was 1 + 1.2e-5 and 1 + 8.7e-6 under the loop, and
1 + 9.0e-6 under the projection at both. The loop ran out on 713 and 705 of
800 steps. The projection settled in one to three rounds on every step and
took 12.7-22.5 ms a step, against the loop's 48.7-53.8 ms.
- **What sets that residual.** The float32 softmax. The projected
log-weights sit within their float32 log caps, but the solve realizes
`D * softmax(log_w)` with a float32 normalizer over 1.59M records, whose
total was off by up to 8.2e-6. The cap ratio exceeded that total error by
at most 6.1e-7. With a float64 normalizer on the same log-weights the largest
ratio was 1 + 4.9e-7, the float32 rounding of the log-weights themselves.
That decomposition covers only the projected vectors; the same softmax
plausibly sets the loop's residual, but no run measured it.
- **The solves.** National ESS agreed within 0.1% between the two steps
(21,834 against 21,835, and 93,609 against 93,598). At share 0.5 and
`l2_lambda = 0.03` the projection's final loss was 0.01899. Three loop runs
of that configuration gave 0.01910-0.01917, so the projection's loss is
0.6-0.9% lower, from one run. At share 0.9 the loss was 0.2% lower (0.03129
against 0.03137).

Evidence:

Expand Down Expand Up @@ -165,8 +236,10 @@ recalibrated from its own checkpoint (`experiments/us-acs-local-l2-basis-2026092
`l2_lambda` is not an equal-ESS comparison. At `0.03` the held-out
comparison is a toss-up: softmax has slightly lower capped error, projection
more held-out targets within 10% on both folds. Projection's training loss is
6% lower there, against 0.3% run-to-run variation. With that and the
cap-loop limitation above, projection is the recommended parametrization.
6% lower there, against 0.3% run-to-run variation, so projection is the
recommended parametrization. Rerun with the exact cap projection, softmax's
training loss at `0.03` is 0.01899 (one run), still 5% above projection's
0.01806.
- **Record basis.** The record basis at `0.1` lowers national ESS from 13,646
to 8,689, as its `w ∝ d ** 2` optimum predicts.
- **Chi-square basis.** The chi-square basis raises ESS smoothly with
Expand Down Expand Up @@ -200,7 +273,7 @@ result = calibrate(
l2_lambda=...,
l2_basis="chi_square",
# mass_parametrization="softmax" for problems where every target presses
# the same way; see the cap-loop limitation above.
# the same way (above).
)
result.options["l2_basis"], result.options["mass_parametrization"]
result.chi_square_distance, result.effective_sample_size
Expand All @@ -209,13 +282,23 @@ result.chi_square_distance, result.effective_sample_size
The ACS local-area tool takes the same settings as
`--l2-lambda`, `--l2-basis {record,chi_square}` and
`--mass-parametrization {projection,softmax}`. It records them, with the
realized chi-square distance, in `calibration_summary.json` and in the build
manifest's `calibration` block. Both join the tool's solver-settings stamp,
realized chi-square distance and, under softmax, the last epoch batch's
largest in-loop weight over its cap, in `calibration_summary.json` and in the
build manifest's `calibration` block. Both join the tool's solver-settings stamp,
so `--resume` and the already-complete shortcut refuse weights solved under
any other solver setting (cap, loss cap, `l2_lambda`, `l2_basis`,
`mass_parametrization`, seed, epoch batch); a stamp written before these two
options existed reads as the historical solve. The manifest's refresh recipe
carries the three flags whenever they differ from the historical solve.
The summary and the manifest name the ratio `softmax_in_loop_max_cap_ratio`;
it is null for a projection solve and for a softmax solve without a cap.
Before the exact cap projection, a softmax solve's summary recorded
`softmax_cap_rounds_exhausted_epochs` in its place, a count of epochs. The
two measure different things, so `--stage package` refuses a summary that
holds such a count and no ratio: its checkpoint was solved by the old cap
step and has to be calibrated again (`--stage calibrate` without `--resume`).
A summary whose old key is null (a projection solve) or absent packages as
before.
`calibrate_l0_refit` takes `l2_basis` / `refit_l2_basis`
and `refit_mass_parametrization`; `refit_l0_selection` and `static_aging` take
`l2_basis`.
Expand Down
16 changes: 8 additions & 8 deletions docs/evidence/spec-engine/us-f0-coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1642,13 +1642,13 @@
"compiler_ir.node_slices"
],
"expected": {
"map_sha256": "270cf6498f8a2977993f969d0703be88fb930499dab42741a2111f57ffec4266",
"protocol_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47"
"map_sha256": "8d0542f7b83f030772e6e53b5742d0f13bcad82325a4e9b66d5d999a3fbb5276",
"protocol_sha256": "3ab23e82779263dabe8da210de55ce7f12fdc0464e8145ca2c18649426b7f976"
},
"failures": [],
"observed": {
"map_sha256": "270cf6498f8a2977993f969d0703be88fb930499dab42741a2111f57ffec4266",
"protocol_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47"
"map_sha256": "8d0542f7b83f030772e6e53b5742d0f13bcad82325a4e9b66d5d999a3fbb5276",
"protocol_sha256": "3ab23e82779263dabe8da210de55ce7f12fdc0464e8145ca2c18649426b7f976"
},
"status": "covered"
},
Expand All @@ -1663,7 +1663,7 @@
"compiler_ir.seed_stream_map"
],
"expected": {
"implementation_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47",
"implementation_sha256": "3ab23e82779263dabe8da210de55ce7f12fdc0464e8145ca2c18649426b7f976",
"protocol": "legacy-v1",
"streams": [
"build_model",
Expand All @@ -1684,7 +1684,7 @@
},
"failures": [],
"observed": {
"implementation_sha256": "a696ad74bfa5743b63c65499e6f5a41ea913a96ca38a5e3b9882069284bfca47",
"implementation_sha256": "3ab23e82779263dabe8da210de55ce7f12fdc0464e8145ca2c18649426b7f976",
"protocol": "legacy-v1",
"streams": [
"build_model",
Expand Down Expand Up @@ -2585,7 +2585,7 @@
"country": "us",
"schema_id": "country_spec",
"schema_version": 1,
"spec_sha256": "bd526d8cf819e9f97fa46c5fe279c7b9ef4458b3e2d3498f823602f45e6a7575"
"spec_sha256": "fa75bd68f579fd7fb0dd0eed955c867415c251f11fc34087bbc24ae3a77a2a49"
}
},
"report_schema_version": 3,
Expand All @@ -2595,7 +2595,7 @@
"country": "us",
"schema_id": "country_spec",
"schema_version": 1,
"spec_sha256": "bd526d8cf819e9f97fa46c5fe279c7b9ef4458b3e2d3498f823602f45e6a7575"
"spec_sha256": "fa75bd68f579fd7fb0dd0eed955c867415c251f11fc34087bbc24ae3a77a2a49"
},
"status": "pass"
}
Loading
Loading