Repository navigation
Conversation
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.
The default
LinearOperator._bilinear_derivativedetaches every representation tensor and callsautograd.gradwithoutcreate_graph. Operators that inherit this fallback consequently lose representation-input higher derivatives. For example,kron(Diag(ones(4)), Root(a) + Diag(0.06 * ones(2))).to_dense().sin().sum()has the correct first derivative with respect toa, but that derivative is detached despitecreate_graph=True. The equivalent densetorch.kronexpression has a nonzero Hessian. Correlated multitask likelihood covariance materialization is one affected use case.This repair retains the existing detached ordinary-backward path. When the caller requests a derivative graph, it builds independent view nodes for differentiable representation tensors and requests graph construction from the nested autograd call. The views are important: simply reusing the original tensors would include unwanted paths through dependent left/right vectors or through another representation tensor when computing a partial derivative. The resulting partial derivatives remain connected to all original tensors for subsequent backward passes.
Tests include:
The unmodified source fails eight new CPU/CUDA subcases. The repaired representative operator suites (Kronecker, concatenation, triangular, added-diagonal, sum and the new fallback regressions) pass 968 tests and ten subcases on Torch 2.13 CPU/CUDA, and 968 tests and five subcases on Torch 2.14.1 CPU. Formatting, Flake8 and
git diff --checkpass.Related analytic specializations are proposed separately in #152 and #153. This change fixes the remaining general fallback and does not depend on either PR. Prepared with assistance from OpenAI Codex; the source reproductions and validation described above were executed locally.