Cuda is recognized but the gpu is not running.

Hi, I am running my scripts on CPU and not on GPU, although it recognizes cuda when I run my scripts.

What can it be? is it wrongly set CUDA_HOME?

Is CUDA supported by this system? True
CUDA version: 11.3
ID of current CUDA device: 0
Name of current CUDA device: NVIDIA A10

Could you describe your use case and issue a bit more, please?
Are you seeing any errors, did you make sure to move the model and inputs to the device etc.?

Of course! in case I am not explaining myself well please let me know! I am not an expert in the subject, I am learning.

I don’t see any error in the output of my script, it makes me the perfect calculations but in cpu and not in gpu.
I attach my script in case you identify my error.


from __future__ import print_function
from import read
from import write
from import MDLogger
from import Trajectory
from ase.optimize import BFGS
from ase import units
import torch
import torchani

import os
import numpy as np

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)

calculator = torchani.models.ANI2x().ase()

#funcion que minimiza E y devuelve el valor
def mincalc_E_ani(lig):
    atoms = read(lig)
    opt = BFGS(atoms),steps=500)
    write('xyz/'%lig, atoms,'xyz')
    return E,E0

#funcion que encuentra el minimo local energia de un ligando (antes era global)
def enc_min_glob(lig):
#ligandos = [ligand[:-4] for ligand in os.listdir('ligands_filt') if (ligand[-4:] == '.pdb' and '.rand' not in ligand)]

os.system('mkdir energies2')


for lig in listaligandos.readlines():
    if not os.path.isfile('energies2/%s.ene'%lig):
        a = enc_min_glob(lig)

Thanks for the code. You’ve never transferred any data to the GPU, so it’s expected that the default device (CPU) will be used.
Move the model as well as the inputs to the GPU via:

x =

and the GPU should be used.

I modified the following:

calculator = torchani.models.ANI2x().ase()
calculator =‘cuda’)

and I get the following error:

ttributeError: ‘Calculator’ object has no attribute ‘to’

What can it be?

You need to call to('cuda') on an nn.Module object, while calculator seems to be a Calculator object created by TorchANI. Based on these docs I guess something like'cuda') might work.

Looks like it would be working! but …

RuntimeError: I expected all tensors to be on the same device, but it found at least two devices, cuda:0 and cpu!

what would I miss to move to gpu? sorry for so much trouble!

This error is raised if some tensors are on the GPU while others are still on the CPU. Based on your current changes I would guess you’ve properly moved the model with its parameters to the GPU while the input tensors might still be on the CPU. If so, move them via x ='cuda') before passing them to the model.