Jingkang50 / OpenOOD

Benchmarking Generalized Out-of-Distribution Detection
MIT License
858 stars 108 forks source link

How dose the GPU for this project work? #128

Closed yangengineering closed 1 year ago

yangengineering commented 1 year ago

Thanks for your great work. I am trying to learn how does this project work. But I do not understand that whether this work uses CPU and GPU together or not. If yes, I want to ask where does the code show the work used the GPU, Imean that people usually use the GPU by the exemple " loss_fn = loss_fn.cuda()" . besides, if I want to use two pieces of Gpu of a machine, only I need to change the num_gpu=2? thank you

yangengineering commented 1 year ago

and I delete the content of srun because our remote server is a machine but when I use this project, I notied that the gpu did not work and the cpu work actively.

zjysteven commented 1 year ago

@yangengineering Sorry for the late reply.

The network being pushed to GPU is done here https://github.com/Jingkang50/OpenOOD/blob/70f5d449315c7009ed43f9e5ffb011b993500580/openood/networks/utils.py#L394-L399

If you are using more than 1 GPUs, OpenOOD relies on DistributedDataParallel for parallelism, as can be seen here https://github.com/Jingkang50/OpenOOD/blob/70f5d449315c7009ed43f9e5ffb011b993500580/openood/utils/launch.py#L69-L82

And yes, I believe all you need to do is specify num_gpu=2 in the arguments. Basically the GPUs are handled by OpenOOD inherently, and you don't need to worry about it elsewhere. In our experiments we haven't really had any issues with GPUs.

Hope this is helpful. Closing for now, but feel free to reopen if you have further issues.