Skip to content

Apply the CG preconditioner to the initial residual - #155

Merged
SamDuffield merged 1 commit into
normal-computing-oss:mainfrom
keshtib07-ghost:fix/cg-initial-preconditioner
Nov 13, 2026
Merged

SamDuffield merged 1 commit into
normal-computing-oss:mainfrom
keshtib07-ghost:fix/cg-initial-preconditioner

Conversation

@keshtib07-ghost

Copy link
Copy Markdown
Contributor

Fixes #154.

cg starts with the raw residual as its search direction, then applies M only on subsequent iterations. Initialize z0 and p0 with M(r0) so the preconditioner is used from the first step.

The regression uses an exact inverse preconditioner for a diagonal positive-definite system. It should solve the system in one iteration. Eight cases cover tensor and dictionary parameters, zero and nonzero initial guesses, and damping. All eight fail on main and pass with the fix. The M docstring now clarifies its role.

Validation on Python 3.12.14 and PyTorch 2.15.0+cpu:

  • pytest tests/test_utils.py tests/test_tree_utils.py -q: 35 passed.
  • Repository-wide Ruff lint and format checks passed with the pinned version 0.13.1.
  • git diff --check passed.

The full sampling suite is still running locally; a full-suite pass is not claimed.

Fixes normal-computing-oss#154.

Signed-off-by: Keshav Tibrewal <keshav.tibrewal@iitgn.ac.in>

@SamDuffield SamDuffield left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ooops! Good spot and thanks for the fix

@SamDuffield
SamDuffield merged commit 1143aa7 into normal-computing-oss:main Nov 13, 2026
2 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.

cg skips the preconditioner when initializing the search direction

2 participants