Fix predict() blowing up when called twice with different grids#2
Merged
JonasTurnwald merged 1 commit intoApr 14, 2026
Merged
Conversation
_maybe_prepare_inference never checked if w_pred changed between calls, so calling predict() a second time with a different grid would reuse the cached OpKer from the first call and blow up or give wrong results. Now we store w_pred alongside OpKer and compare before reusing.
JonasTurnwald
approved these changes
Apr 14, 2026
Owner
JonasTurnwald
left a comment
There was a problem hiding this comment.
Another important catch, thanks a lot! Interesting that this hasn’t come up before.
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.
What broke
_maybe_prepare_inferencecachedOpKeron the firstpredict()call but never checked whether the next call used a differentw_pred. So if you did:The second call reused
OpKerfromgrid_A. Depending on grid sizes this either crashes with a shape mismatch or silently gives garbage.What changed
Now we stash
w_prednext toOpKerin the cache dict and compare it before reusing. If the grid changed, we recompute. Thats it.Test
Added
test_predict_different_w_pred-- calls predict twice on the same model with two different grids and checks both reconstructions land within the error band. Without the fix this crashes immediately.