pytorch when do I need to use `.to(device)` on a model or tensor?
It is necessary to have both the model, and the data on the same device, either CPU or GPU, for the model to process data. Data on CPU and model on GPU, or vice-versa, will result in a Runtime error. You can set a variable device to cuda if it’s available, else it will be … Read more