Remove TorchScript helpers from linear CG - #134
Merged
Merged
Conversation
kayween
approved these changes
Sep 11, 2026
kayween
left a comment
Collaborator
There was a problem hiding this comment.
It seems good to me to remove torch.jit.script given that it's already deprecated a long time ago.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
torch.jit.scripthelpers fromlinear_cgWhy
The helpers were introduced as TorchScript-only optimization boundaries. Replacing them with
torch.compile, as proposed in #129, adds substantial first-call compilation overhead and shape-specialization costs for small fragments inside a Python loop. The default preconditioner already implements the unpreconditioned behavior by cloning the residual, so both branches can share the same update code without either compilation mechanism.This also removes the
torch.jit.scriptdeprecation warning emitted when importinglinear_operatoron recent PyTorch versions.Correctness
The consolidated loop preserves the existing CG update order. A new float64 parity test compares a Jacobi-preconditioned solve with
torch.linalg.solveand verifies that the supplied preconditioner is used repeatedly. Temporarily reversing the residual-update sign caused this test to fail, confirming that it detects an incorrect update.Test plan
ufmton both changed filespython -m flake8 -j 1 linear_operator/utils/linear_cg.py test/utils/test_linear_cg.pypython -m pytest test/utils/test_linear_cg.py test/functions/test_inv_quad_logdet.py test/operators/test_added_diag_linear_operator.py test/operators/test_low_rank_root_added_diag_linear_operator.py -xvs(403 passed)python -Wd -c "import linear_operator"(no TorchScript deprecation warning)