Train model with CPU only (using Python)

I am doing this tutorial: Quickstart — OpenNMT-py documentation and I got stuck on Step 2. I created that file toy_en_de.yaml and I added the following part of the code to it.

src_vocab: toy-ende/run/example.vocab.src
tgt_vocab: toy-ende/run/example.vocab.tgt

world_size: 1
gpu_ranks: [0]

save_model: toy-ende/run/model
save_checkpoint_steps: 500
train_steps: 1000
valid_steps: 500

I have installed PyTorch (conda install pytorch==1.6.0 torchvision==0.7.0 cpuonly -c pytorch).

The problem occurs if I run the following command: onmt_train -config toy_en_de.yaml. I got error: AttributeError: module ‘torch_.C’ has no attribute ‘_cuda_setDevice’.
The mistake is probably that the .yaml file is written to use GPU. So I would need to rewrite it if only the CPU is used.

I used cuda before, but I got another error: AssertionError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed driver from…

Yeah, I don’t have NVIDIA card so I must use only CPU on it. So can someone help me modify .yaml file use CPU only.

Dear Martin,

These lines are for GPU; delete them and try again:

world_size: 1
gpu_ranks: [0]

However, you can also use Google Colab, which offers you one GPU. Check this notebook.

All the best,
Yasmin

1 Like