isayevlab / Auto3D_pkg

Auto3D generates low-energy conformers from SMILES/SDF
MIT License
146 stars 32 forks source link

Question about geometry optimization #41

Open Colin-CompChem opened 1 year ago

Colin-CompChem commented 1 year ago

Hi,

I was wondering how the opt_geometry function is supposed to work with GPU? When I run it even with cuda available and right GPU index number it seems to run mainly on parallelized CPU. Is it supposed to be like this or am I missing something?

LiuCMU commented 1 year ago

Hi Colin,

opt_geometry should be able to use GPU. Could you show me how you called the function (i.e. the arguments that you passed to the function)?

Just in case could you verify that your GPU by runningnvidia-smi in your terminal. Besides, there are different PyTorch implementations, some of which only works for CPU. You could check you PyTorch installation with conda list pytorch.

Colin-CompChem commented 1 year ago

Hi Liu,

Sure, first everything works correctly when I did a classical 3D generation as shown in the notebook: root = os.path.dirname(os.path.dirname(os.path.abspath("file")))

if name == "main": path = os.path.join(root, "test.smi") args = options(path, k=1, use_gpu=True) #specify the parameters for Auto3D out = main(args) #main acceps the parameters and run Auto3D print(out)

This one runs on GPU.

But when I do opt_geometry, also in a notebook: path = os.path.join(root, "test_no_opt.sdf") optimized = opt_geometry(path, model_name="AIMNET", opt_tol=0.002, gpu_idx=0) print(optimized) It does not seem to work on GPU but on all my CPUs. I also tried different gpu_idx withotu success. I am monitoring my GPU using nvtop.

I have pytorch 2.0.0 (I constructed a new environment for Auto3D as in your instructions in the main page).

Thanks

LiuCMU commented 1 year ago

Thanks for the informative feedback!

For the opt_geometry function, the device is defined as follows: https://github.com/isayevlab/Auto3D_pkg/blob/04c10df24ec37754fd8aab9fcc5d2a7018b174cd/src/Auto3D/ASE/geometry.py#L126-L129

In the same notebook, could you try torch.cuda.is_available(), does it return True or False?

I tested the example file geometry_optimization.ipynb, it runed on GPU. The interesting observatino was that the optimization/GPU process finishes quickly, so I only observe GPU utilization at the beginning.

Colin-CompChem commented 1 year ago

It does return True.

But maybe then it is as you said, because I only observe like a small utilization of the GPU, a small peak for 1 sec and only at 5 to 10% and after that, all my CPU (48) are totally used 100% for like 30 sec per molecules.

Therefore it is faster for me to optimize with another computer with more CPUs than with one with a GPU, does that make sense?

Thanks,

Colin

LiuCMU commented 1 year ago

Hi Colin,

I tried to reproduce the situatino with the following file: 100mols.txt

My GPU utilization is about 8-9% percent and about 4 CPUs are being used (There are 12 CPUs in my machine). I was expecting 1 CPU to be occupied, let alone 48 CPUs in your case. I need to take a closer look to find other process that are using CPUs. Thanks for the feedback!

I would still suggest you to use a machine with GPU. Inferencing on GPU is at least 10 times faster than on CPUs.

Best, Zhen