It is strange, I can’t reproduce your error using deepcopy. I am not sure, it may be python version or even system dependent
import copy
import torch
import torch.nn as nn

X = torch.rand(2, 10)
y = torch.tensor([[0,1], [1,0]], dtype=torch.float32)

m = nn.Linear(10, 2)
opt = torch.optim.SGD(m.parameters(), lr=0.1)

m_state = copy.deepcopy(m.state_dict())
state = opt.state_dict()

crit = nn.BCEWithLogitsLoss()

for i in range(5):
    if i == 2:
        # load
        m.load_state_dict(m_state)
        opt = torch.optim.SGD(m.parameters(), lr=0.1)
        opt.load_state_dict(state)
    opt.zero_grad()
    out = m(X)
    loss = crit(y, out)
    loss.backward()
    opt.step()
    # save
    m_state = copy.deepcopy(m.state_dict())
    state = opt.state_dict()

Perhaps, as error suggest you can get rid off all deepcopy calls.