How to choose pytorch

Hy, thanks for accepting me with you
i am trying to write a code with python witch detect objects in images, and i am confused if i should use cpu pytorch or gpu pytorch,
i have a computer i7 , 8 cores, with 12 G in my RAM
and a GPU card GeForce GTX 750 Ti with 2G memory
i would like to tel you that the data set is very large and i am looking for the speediest way to run my code.

Without any details, it’s difficult to tell for sure. Processing on GPU is of course much faster but the 2GB might be a bottleneck. The problem is less the dataset size – you can always reduce the batch size – but the complexity of your network, i.e., the number of (trainable) parameters.

I would just give it a try. Install PyTorch with GPU support, create and test your network with a small sample dataset on the CPU (any error messages are usually more helpful compared to GPU). If this seems to work, try to move it on the GPU to see if it works and how the performance looks like.

The good thing is that moving the network and the data onto the GPU is very easy with PyTorch, so you don’t loose anything here.

tank you for your reply, i will try, but can you tel me how to move network between GPU and CPU
have you any documentation please

There are different methods. That’s how I do it:

First, check if the GPU is available, otherwise fall back to CPU (I only have 1 GPU so I can fix it to “cuda:0”)

device = torch.device("cuda:0" if use_cuda else "cpu")

For the network model:

model = MyCoolModel(...)

For the data

test_tensor = torch.ones(32)

You only have to make sure that all your data and the model are moved to the same device. I common error is that the model is on the GPU but the current batch (still) on the CPU. Having basically the .to(device) at your model and all the tensors should take care of that.

tank you very much,
excuse me because i am novice in programming, but one last question: if i install pytorch cpu how can i chose between: pytorch cpu_0 or cpu_1 or cpu_2

As far as I know, there’s only “cpu” as device. But PyTorch seems to support parallelism on the CPU; have a look at this thread, for example.

1 Like