Skip to content

Refactor: extract shared EigendecompositionBasedShampooKroneckerFactorsUnwrapped base class#261

Open
runame wants to merge 1 commit into
facebookresearch:mainfrom
runame:pr1/eigendecomposition-base-class
Open

Refactor: extract shared EigendecompositionBasedShampooKroneckerFactorsUnwrapped base class#261
runame wants to merge 1 commit into
facebookresearch:mainfrom
runame:pr1/eigendecomposition-base-class

Conversation

@runame
Copy link
Copy Markdown
Contributor

@runame runame commented May 7, 2026

Summary

  • Extract a new EigendecompositionBasedShampooKroneckerFactorsUnwrapped base class that unifies shared eigendecomposition logic between EigendecomposedShampooKroneckerFactorsUnwrapped and EigenvalueCorrectedShampooKroneckerFactorsUnwrapped.
  • Shared logic: factor_matrices_eigenvectors field, _amortized_computation method, and __post_init__ assertion. Eigenvalue inclusion is controlled by field presence (hasattr(self, "factor_matrices_eigenvalues")).
  • Net reduction of ~40 lines by eliminating duplicated eigendecomposition code.

Stack

This PR is part of a stack adding per-factor eigenvalue correction to Distributed Shampoo:

  1. This PR — extract shared base class
  2. KL outer product refactor (next PR in stack)
  3. Per-factor eigenvalue correction (implementation + tests)
  4. Eigenvalue EMA over per-step outer products

Test plan

  • Existing tests pass (distributed_shampoo/tests/, distributed_shampoo/preconditioner/tests/)
  • mypy clean (make type-check)
  • ruff clean
  • No new tests needed — pure refactor with no behavior change.

Generated with Claude Code

…rsUnwrapped base class

Consolidate duplicated eigendecomposition logic from EigendecomposedShampooKroneckerFactorsUnwrapped
and EigenvalueCorrectedShampooKroneckerFactorsUnwrapped into a shared base class. The base class
provides _perform_eigendecomposition and _amortized_computation, with subclass behavior controlled
via hasattr checks on field presence.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented May 12, 2026

@hjmshi has imported this pull request. If you are a Meta employee, you can view this in D104874447.

Copy link
Copy Markdown
Contributor

@wz337 wz337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants