Unexpected error:TypeError: sub(): argument 'other' (position 1) must be Tensor, not NoneType

Due to the limitations of the learning environment, it is necessary to write code to save the learning progress, load it, and resume learning. However, an error occurs and learning cannot be performed.

File "c:/Users/.../Desktop/PINN_ACSL/NN.py", line 531, in <module>
    optimizer.step(PINN.closure)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\optim\optimizer.py", line 140, in wrapper
    out = func(*args, **kwargs)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\optim\lbfgs.py", line 352, in step
    y = flat_grad.sub(prev_flat_grad)
TypeError: sub(): argument 'other' (position 1) must be Tensor, not NoneType

The optimizer used is torch.optim.LBFGS , and use torch.save(optimizer.state_dict(), PATH) for saving. optimizer.load_state_dict(torch.load(PATH)) is used for loading.