ML4GLand / EUGENe

Elucidating the Utility of Genomic Elements with Neural Nets
MIT License
61 stars 4 forks source link

how to use CPU for testing purposes. #39

Open brian-arnold opened 9 months ago

brian-arnold commented 9 months ago

Hello! Thank you for this incredibly well-documented tool!

I'm trying to get familiar with your software using my own personal computer that doesn't have a GPU (or rather has a MAC GPU which I know can be specified with device = torch.device("mps")), and I keep getting the following exception:

MisconfigurationException: Trainer(devices=0) value is not a valid input using cpu accelerator.

I received this message for the basic usage tutorial and also trying the DeepSTARR model. How would I use your API to allow the model to use CPU for testing purposes?

Thank you! Brian

adamklie commented 9 months ago

Hey Brian!

Thanks so much for raising this issue. This has to do with the fact that PyTorch Lightning changed the trainer API in their 2.0.0 release. I'll have a permanent fix for this shortly, but for now you should be able to train on a CPU by running settings.gpus = "auto" right before training. You can also pass in gpus = "auto" to the train.fit_sequence_module function.

For running on your MAC GPU, can you send me the output of running the following via the command line:

 python -m torch.utils.collect_env
brian-arnold commented 9 months ago

Amazing! Thanks!

And as for using MAC GPU, I was able to get torch to use it for some other software using device = torch.device("mps"), but as for the output of python -m torch.utils.collect_env:

(eugene) bjarnold@PU-D732CVM0JX eugene % python -m torch.utils.collect_env
Collecting environment information...
PyTorch version: 2.1.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 14.1 (x86_64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.0.40.1)
CMake version: Could not collect
Libc version: N/A

Python version: 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:52:10)  [Clang 15.0.7 ] (64-bit runtime)
Python platform: macOS-14.1-x86_64-i386-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Apple M2 Max

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.5
[pip3] pytorch-lightning==2.1.0
[pip3] torch==2.1.0
[pip3] torchinfo==1.8.0
[pip3] torchmetrics==1.2.0
[conda] numpy                     1.23.5                   pypi_0    pypi
[conda] pytorch-lightning         2.1.0                    pypi_0    pypi
[conda] torch                     2.1.0                    pypi_0    pypi
[conda] torchinfo                 1.8.0                    pypi_0    pypi
[conda] torchmetrics              1.2.0                    pypi_0    pypi
adamklie commented 9 months ago

Ok gotchya, yea EUGENe isn't very sophisticated with it's detection of devices. If the output of torch.cuda.is_available() is False, it will assume no GPU is available.

From a quick look, it seems like PyTorch Lightning needs to be told the accelerator is "mps". So right now, I'm not sure you could run the train or eval module methods with it, but I'll add support for this. Happy to give you a workaround if you need to use MPS for the time being.