bioFAM / mofapy2

Multi-omics factor analysis v2
https://biofam.github.io/MOFA2/
GNU Lesser General Public License v3.0
34 stars 28 forks source link

Change default GPU device #9

Closed martinrohbeck closed 9 months ago

martinrohbeck commented 2 years ago

Hey there,

since many machines are multi-gpu machines these days it would be great to be able to specify the GPU device when running mofa. Currently the code is inevitably executed on GPU device 0 when the user sets gpu_mode=True.

The easiest way to change this is by running

import cupy as cp
cp.cuda.Device(gpu_device).use()

I'd say it is most intuitive to provide an extra argument, e.g., gpu_device: int, to the set_train_options() function here, and execute the command from above after the cupy import here .

If you think this is helpful for you, I'm happy to provide a PR - if you prefer another way to integrate this (e.g., using env variables), let me know.

gtca commented 2 years ago

Thanks, @martinrohbeck, specifying a desired device as a training argument seems to be transparent enough. That will also allow us to easily reuse it in R (https://github.com/bioFAM/MOFA2/issues/103). Surely a PR is welcome. :)