Make _array_types sentinels survive cloudpickle round-trip.#391
Merged
patrick-kidger merged 1 commit intoMay 24, 2026
Merged
Conversation
The three module-level `object()` sentinels in `_array_types` (`_any_dtype`, `_anonymous_dim`, `_anonymous_variadic_dim`) are stored on persisted jaxtyping types (`cls.dtypes`, `cls.dims`). cloudpickle serialises them by value, so on the receiving side they are fresh `object()` instances that no longer match the live module-global sentinel — breaking `is`-checks that downstream shape-check code relies on. The symptom for `_anonymous_variadic_dim` is an `AssertionError` in `_check_dims`; the other two sentinels fail similarly when isinstance() runs against a cloudpickled type. Replace each with a `__reduce__`-backed singleton class. The fourth `object()` sentinel in this file, `_not_made`, is transient factory output filtered before any type is built, so it doesn't suffer the same bug and is left alone. Three regression tests added in `test_serialisation.py`, one per sentinel, each round-tripping under both `pickle` and `cloudpickle` and asserting `isinstance` after the round-trip — the call path that actually trips the bug under `cloudpickle`. Bumps version 0.3.9 -> 0.3.10. Fixes patrick-kidger#390.
Owner
|
Thank you for the PR! Merged 🎉 |
3 tasks
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 three module-level
object()sentinels in_array_types(_any_dtype,_anonymous_dim,_anonymous_variadic_dim) are stored on persisted jaxtyping types (cls.dtypes,cls.dims). cloudpickle serialises them by value, so on the receiving side they are freshobject()instances that no longer match the live module-global sentinel — breakingis-checks that downstream shape-check code relies on. The symptom for_anonymous_variadic_dimis anAssertionErrorin_check_dims; the other two sentinels fail similarly when isinstance() runs against a cloudpickled type.Replace each with a
__reduce__-backed singleton class. The fourthobject()sentinel in this file,_not_made, is transient factory output filtered before any type is built, so it doesn't suffer the same bug and is left alone.Three regression tests added in
test_serialisation.py, one per sentinel, each round-tripping under bothpickleandcloudpickleand assertingisinstanceafter the round-trip — the call path that actually trips the bug undercloudpickle.Bumps version 0.3.9 -> 0.3.10.
Fixes #390.