How To Use GPU with PyTorch - W&B
It's a common PyTorch practice to initialize a variable, usually named device that will hold the device we’re training on (CPU or GPU). device = …
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 ...