Cloudpickle interaction: TypeError: cannot pickle 'weakref.ReferenceType' object
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by reproducing the example with cloudpickle, jaxtyping, and typeguard, then inspect the decorator entry point in jaxtyping/_decorator.py around line 71. Compare pickling the decorated function with the unwrapped function; done means the decorated function can be serialized without the weakref.ReferenceType error while preserving the reported behavior.
Written by the indexing model from the issue text.
Description
This code:
# pip install cloudpickle jaxtyping typeguard
import cloudpickle
from jaxtyping import jaxtyped
import typeguard
def typed(function):
return jaxtyped(function, typechecker=typeguard.typechecked)
@typed
def f():
return 1
def unwrapped_f():
return 2
# This will succeed
pickled_unwrapped = cloudpickle.dumps(unwrapped_f)
print("Successfully pickled unwrapped_f")
# This will fail
try:
pickled_f = cloudpickle.dumps(f)
except Exception as e:
print(f"\nFailed to pickle decorated function f:\n{type(e).__name__}: {e}")
Prints out this:
[...]/lib/python3.13/site-packages/jaxtyping/_decorator.py:71: InstrumentationWarning: instrumentor did not find the target function -- not typechecking __main__.f
return typechecker(fn)
Successfully pickled unwrapped_f
Failed to pickle decorated function f:
TypeError: cannot pickle 'weakref.ReferenceType' object
Showing that jaxtyping doesn't interact well with cloudpickle :(
CC @JoshEngels @jkramar
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 96
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from patrick-kidger/jaxtyping
-
question
Difficulty 4/5 3-5 days Newbie friendliness 30/100
patrick-kidger/jaxtyping#384 · 2 comments ·
-
question
Difficulty 5/5 Over a week Newbie friendliness 25/100
patrick-kidger/jaxtyping#383 · 1 comment · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
patrick-kidger/jaxtyping#378 ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
patrick-kidger/jaxtyping#377 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
patrick-kidger/jaxtyping#375 · 1 comment ·
All issues in patrick-kidger/jaxtyping
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100