Ray throws GPUtil error "NameError: name ‘GPUtil’ is not defined" even though GPUtil is installed

How severe does this issue affect your experience of using Ray?

  • None: Just asking a question out of curiosity
  • Low: It annoys or frustrates me for a moment.
  • Medium: It contributes to significant difficulty to complete my task, but I can work around it.
  • High: It blocks me to complete my task.

Hi, while building a PPOConfig for a custom made environment on GPU I keep getting this error despite the fact that I have the package installed in my environment.
→ 278 gpu_list = GPUtil.getGPUs()
279 result = len(gpu_list)
280 elif sys.platform.startswith(“linux”):

NameError: name ‘GPUtil’ is not defined

Hi @maziarg ,

RLlib is not directly based on GPUtil, but ray itself is.
I suspect your code is from python/ray/_private/resource_spec.py.
I’m moving this to thread to Ray so you can get help there.

@ClarenceNg From skimming the code, maybe the if branch should rather be entered on if importlib.util.find_spec("GPUtil") is not None like further up?

Thank you @arturn, I am assuming that I have to wait for @ClarenceNg to check the issue right?

Will be @cade’s responsibility now :slight_smile:

I’m not familiar with find_spec, but you have a reasonable hypothesis @arturn. I think to confirm, could @maziarg run import importlib; print(importlib.util.find_spec("GPUtil")) from the same environment where the issue occurs to see what truthy value it seems to be returning?

Seems like we should wrap all interactions with GPUtil behind a single function in that file. Would deduplicate this kind of code and make it easier to test.