Skip to content

Widen center-invariant norms before computing squared deviations - #776

Merged
KevinMusgrave merged 3 commits into
KevinMusgrave:masterfrom
Afloat16:fix/center-invariant-precision
Nov 8, 2026
Merged

KevinMusgrave merged 3 commits into
KevinMusgrave:masterfrom
Afloat16:fix/center-invariant-precision

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Problem

CenterInvariantRegularizer computes norms and squared deviations in the input dtype. For bfloat16 centers [16, 0] and [17, 0], this gives 64 instead of the reference loss 68.0625. Float16 norms around 300 also overflow when squared, before the final centered loss is computed.

Changes

Promote low-precision centers before computing their norms and retain float32 through reduction. Float32/float64 inputs and custom Lp norms retain their existing behavior. Tests check the squared-norm variance and its analytic gradient against float64 references; the integration test reference now also uses float64.

The component documentation, numerical rationale, and unreleased notes describe the behavior.

Validation

  • Python 3.12.14 and PyTorch 2.15.0+cpu.
  • TEST_DEVICE=cpu TEST_DTYPES=float32,float64,bfloat16 OMP_NUM_THREADS=1 python -m pytest tests/regularizers/test_center_invariant_regularizer.py -q: 10 passed.
  • Ruff lint/format checks and git diff --check passed.

The checksum-verified pinned Code Polishy 0.31.10 commands were attempted. check --git-changes is blocked by an unavailable policy-owned CPython 3.12 interpreter/security providers. test --changed --base 0db540f1b8adb0f65ea91075ee1625e13176758b could not start the declared suites because the repository-specific .venv/bin/uv is absent. The direct focused tests below ran in the available Python/PyTorch environment; these results do not constitute a pass of the complete locked verification gates. Float16 execution is also blocked on this host by RuntimeError: Failed to initialize cpuinfo!; its parameterized cases are retained for supported CI hosts.

@Afloat16

Afloat16 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer rerun the cancelled macOS job for current head eb5fd2494b3bb7bb41c9baa0bd8a22c096ff2c75? GitHub reports that no hosted runner acquired the job, together with macOS ARM64 capacity notices. No test steps started; the other six jobs passed.

Exercise overflow both before reduction and in the final scalar, with float64 value and gradient references. The focused four-dtype suite passes 21 tests. The policy check is blocked by the pre-existing expired certifi assessment; shared verification will be completed after its re-assessment.
@KevinMusgrave
KevinMusgrave merged commit bdff3c6 into KevinMusgrave:master Nov 8, 2026
13 of 14 checks passed
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.

2 participants