Can we have a cleaner way of utilizing GPUs?
According to this [1]
from mxnet import npx
npx.set_np()
num_gpus = npx.num_gpus()
ctx = [mx.gpu(i) for i in range(num_gpus)] if num_gpus > 0 else [mx.cpu()]
Equivalent in PyTorch would be
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
To make this easier for first time user of MXNet or (PyTorch user migrating to MXNet)
Can we have 2 changes
mx.gpu().is_available()Benefit - Adding this API would save user 3 lines of code and using npx.num_gpus() >1 is a round-about way of saying cuda.is_available()
Created a discussion on discuss forum for the same [2]
mx.gpu(all_gpus=True)Benefit - Adding all_gpus parameter is convenient than [mx.gpu(i) for i in range(num_gpus)]
I think it would be better to introduce a separate function called mxnet.all_gpus(): List[mxnet.Context], instead of adding a parameter to mxnet.gpu. This way, the return type of mxnet.gpu will remain mxnet.Context, instead of becoming Union[mxnet.Context, List[mxnet.Context]].
@ChaiBapchya @nickguletskii There's one function in d2l-en that could be a possible reference.
Most helpful comment
I think it would be better to introduce a separate function called
mxnet.all_gpus(): List[mxnet.Context], instead of adding a parameter tomxnet.gpu. This way, the return type ofmxnet.gpuwill remainmxnet.Context, instead of becomingUnion[mxnet.Context, List[mxnet.Context]].