Moving optimizer from CPU to GPU - PyTorch Forums
discuss.pytorch.org › t › moving-optimizer-from-cpuSep 13, 2020 · I have a model and an optimizer and I want to save it’s state dict as CPU tensors. Then I want to load those state dicts back on GPU. This seems straightforward to do for a model, but what’s the best way to do this for the optimizer? This is what my code looks like right now: model = ... optim = torch.optim.SGD(model.parameters(), momentum=0.1) model_state = model.state_dict() # Convert to ...