Skip to content

Make linear operators pickleable#124

Merged
gpleiss merged 3 commits intocornellius-gp:mainfrom
kayween:memorize-qualname
Feb 17, 2026
Merged

Make linear operators pickleable#124
gpleiss merged 3 commits intocornellius-gp:mainfrom
kayween:memorize-qualname

Conversation

@kayween
Copy link
Collaborator

@kayween kayween commented Feb 17, 2026

Context

This PR aims to fix cornellius-gp/gpytorch#2717

The recent changes in GPyTorch v1.15 make variational models not pickle-able anymore. After digging around, it seems that the root cause lies in linear operators, as linear operators are not pickle-able in the first place. See here for a code snippet.

This PR

Claude suggested that the issue is caused by the @cache decorator. By default, the cache uses the original unwrapped function in the dictionary key; see here. But pickle looks up the function by the qualified name, which points to the wrapped function. This eventually causes a check failure in pickle dumps. This PR fixes this by using the qualified name (a string) in the dictionary key.

P.S. There is still a test failure in the kernel linear operator, which is likely caused by lambda functions.

kayween and others added 3 commits February 16, 2026 21:47
Replace lambda in defaultdict with a module-level function so that
num_nonbatch_dimensions can be pickled.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Member

@gpleiss gpleiss left a comment

Choose a reason for hiding this comment

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

LGTM!

@gpleiss gpleiss merged commit b0a4312 into cornellius-gp:main Feb 17, 2026
4 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.

[Bug] Can't pickle function CholLinearOperator.to_dense

2 participants