Skip to content

fix(priors): avoid RecursionError when moving MultivariateNormalPrior to device - #2

Draft
castor639 wants to merge 1 commit into
mainfrom
mvn-prior-cuda-recursion
Draft

fix(priors): avoid RecursionError when moving MultivariateNormalPrior to device#2
castor639 wants to merge 1 commit into
mainfrom
mvn-prior-cuda-recursion

Conversation

@castor639

@castor639 castor639 commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses the MultivariateNormalPrior RecursionError reported in cornellius-gp#2679 (device / .cuda() path).

Prior.__setattr__ evaluated hasattr(self, name) before checking for the buffered-attribute prefix. For torch.distributions lazy properties such as covariance_matrix, that hasattr re-enters the lazy property getter, which caches via setattr, causing infinite recursion after .cuda() / .to() / .cpu() clears and recomputes those properties.

This PR:

  • Checks BUFFERED_PREFIX before hasattr in Prior.__setattr__
  • Clears MVN lazy properties in to(), consistent with existing cuda() / cpu()
  • Adds a CPU unit test that covers the device-move + lazy-property access path (no CUDA required)

Out of scope: LKJPrior / HalfCauchyPrior GPU failures from cornellius-gp#2679 are left for cornellius-gp#2581, as noted by the reporter.

Upstream: Opening against cornellius-gp/gpytorch returned 403. Prefer:
cornellius-gp/gpytorch@main...castor639:gpytorch:mvn-prior-cuda-recursion

Test plan

  • python -m unittest test.priors.test_multivariate_normal_prior
  • python -m unittest discover -s test/priors/
  • GPU: test_multivariate_normal_prior_to_gpu when CUDA is available
Open in Web Open in Cursor 

@cursor
cursor Bot force-pushed the mvn-prior-cuda-recursion branch from 9012e44 to 9cf32ae Compare August 29, 2026 17:16
…evice

Check BUFFERED_PREFIX before hasattr in Prior.__setattr__ so torch
lazy_property caching (e.g. covariance_matrix) does not re-enter.
Also clear MVN lazy properties in to(), matching cuda()/cpu().
@cursor
cursor Bot force-pushed the mvn-prior-cuda-recursion branch from 9cf32ae to 5e6fa38 Compare August 29, 2026 17:16
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.

1 participant