Load_state_dict does not work.Help needed for copying models

Hello I am currently on pytorch version 1.8.0, and I tried to do a basic copy of two models.

This doesn’t work and the error I get is:
Expected type ‘OrderedDict[str, Tensor]’, got ‘Dict[str, Tensor]’ instead.
I have scoured the internet for an answer to this but to no avail.Please help me.

EDIT: I have checked all my previous programs and everywhere the load_state_dict method has broken.So basically this has broken over 13 to 14 of my programs. Please check this fast.

you need to do


When did this change? I have been using Actor1.load_state_dict(Actor2.state_dict()) for months now.

I am not sure I have always had to to it this way.


I an not sure why you actually need to do it this way. This is just a typing issue that you should ignore and just use Actor1.load_state_dict(Actor2.state_dict()).

I opened an issue here to fix this: Typing issue on state_dict/load_state_dict · Issue #55302 · pytorch/pytorch · GitHub