Capturing and restoring layer weight norms called ``data.float().norm()``,
which allocates a float32 copy of the entire weight to produce one scalar.
The copy is unconditional, so no offload plan, device map, or allocator
setting avoids it, and for a large-vocabulary LM head it is gigabytes.
Add ``frobenius_norm_bounded`` beside the module's other bounded-scratch
contracts and route the four norm reductions in ``_capture_layer_weight_norms``
and ``_restore_layer_weight_norms`` through it. It splits the largest axis
until a chunk's float32 scratch fits the budget, accumulates sums of squares
in float64, and takes one square root. Storage already at least as wide as
float32 reduces in place, so widening never allocates for it.
Measured on a [152064, 5120] float16 weight, reducing scratch from a
multiple of the weight to a multiple of the budget:
budget 4 MB 16 MB 64 MB
scratch 12 MB 38 MB 96 MB
The whole-weight promotion cost 2971 MB for the same reduction. Scratch is
now a function of the budget, not of the weight.
The folded post-norm branch is left alone: folding materializes a full
writer copy by construction, so bounding its norm would require changing
the fold itself.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Finiteness checks reduce to scalars, the LoRA delta buffer is reused, and
norm restoration validates scaled extrema before rescaling in place, so the
admitted memory bounds hold without changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>