I have been working on tracking down an issue in fastai’s library that involves not being able to export a learner. I have partially tracked down the cause of the issue which is what brings me here.
This is the line of code that is partially causing the object to be unpicklable: pytorch/torch/nn/modules/module.py at 53f462c506286edae673ef76f7b0bedc6279ff2b · pytorch/pytorch · GitHub
The cause of this is that Module is wrapped in double quotes Optional["Module"]
and my question is whether this is intentional and if so, what does it mean to have the class in double quotes like this?
I have tried looking through the PEPs that are related to typing, but didn’t really find anything that explained this but basically since torch v1.13.x, this has cause exporting to break in fastai because this is being added to __annotations__
and then fastai is using functools.update_wrapper
to copy certain hidden object attributes to the instance of the class so instead of __annotations__
being hidden in the background, it gets added to __dict__
where pickle tries to export it, but isn’t able to because the type gets converted to typing.Optional[ForwardRef('Module')]
which is non-pickleable once you dig down into it.
My thought is that maybe this is unintentially a string and it should actually be Module
instead of "Module"
in the type hints which would be ideal for me, but only a good suggestion if the current double-quotes weren’t intentional.
Thank you for your time,
KevinB