Hi,
I have a saved model that I’m trying to load.
The training was initially done over the GPU.
When I load it to the GPU, it works fine. However, when I load it to the CPU, sometimes it works and sometimes it doesn’t (I have some Nan values).
I’m using the following functions to save and load the model,
def save_checkpoint(model, epoch, opt, save_path):
    model_out_path = os.path.join(save_path, "model_epoch_{}.pth".format(epoch))
    if opt.cuda:
        model_file = model.module.__class__.__module__
        model_class = model.module.__class__.__name__
        model_state = model.module.state_dict()
    else:
        model_file = model.__class__.__module__
        model_class = model.__class__.__name__
        model_state = model.state_dict()

    state = {"epoch": epoch,
             "model_state": model_state,
             "opt": opt,
             "args": sys.argv,
             "model_file": model_file,
             "model_class": model_class}

    # check path status
    if not os.path.exists("model/"):
        os.makedirs("model/")

    # save model
    torch.save(state, model_out_path)
    print("Checkpoint saved to {}".format(model_out_path))


def load_checkpoint(path, **extra_params):
    if 'iscuda' in extra_params:
        iscuda = extra_params.pop('iscuda')
    else:
        iscuda = True
    if iscuda:
        dict = torch.load(path, map_location='cuda')
    else:
        dict = torch.load(path, map_location='cpu')
    print(dict["model_file"])
    print(dict["model_class"])
    md = importlib.import_module(dict["model_file"])
    if extra_params:
        model = eval("md.{}".format(dict["model_class"]))(**extra_params)
    else:
        model = eval("md.{}".format(dict["model_class"]))()
    model.load_state_dict(dict["model_state"])
    return model, dict["epoch"], dict