I have trained a model on GPU and i want to use it's weights for inference on CPU?

  1. all my weights and biases tensors are in net.parameters with device (cuda:0) , but i want to convert those tensors to cpu so that i can use it for inferencing.
    prediction snippet…
    prediction=network_instance(test)

  2. when we do optimizer.step() does it keep on updating the weights till the prediction is correct or it updates the weights for only a single backward pass.

You should use the model’s state_dict for saving and loading. Take a look at this tutorial. You can send all of your network’s parameters to the cpu just by doing model = model.cpu().

optimizer.step() only does a single backward pass.

1 Like