oxwhirl / smac

SMAC: The StarCraft Multi-Agent Challenge
MIT License
1.08k stars 228 forks source link

Prevent SC2 from consuming GPU memory #51

Closed douglasrizzo closed 4 years ago

douglasrizzo commented 4 years ago

Basically, it solves this problem https://github.com/deepmind/pysc2/issues/235 by telling SC2 that no rendering will be done, and so the SC2 process will not consume GPU memory.

This is a screenshot of nvidia-smi in a computer before I applied this patch:

image

Notice all the SC2_x64 processes. The image below is after I applied the patch:

image

GoingMyWay commented 4 years ago

@douglasrizzo Is it important? For SC2, is using GPU slower?

PaLeroy commented 4 years ago

@douglasrizzo Is is really important? For SC2, is using GPU slower?

Each sc2 process eating GPU memory, the number of parallel environments running is limited by your GPU VRAM.

xihuai18 commented 4 years ago

I wonder how to tell sc2 that no rendering will be done

xihuai18 commented 4 years ago

I wonder how to tell sc2 that no rendering will be done

I got it, go to /your/path/to/python/site-packages/pysc2/run_configs/platforms.py Change the code in line 186

def start(self, want_rgb=True, **kwargs):
       extra_args = kwargs.pop("extra_args", [])

to

def start(self, want_rgb=False, **kwargs):
      extra_args = kwargs.pop("extra_args", [])
douglasrizzo commented 4 years ago

@Leo-xh I think you can actually instantiate a run_config object in your code with want_rgb=True instead of changing pysc2 directly.

GoingMyWay commented 4 years ago

@douglasrizzo

Hi, actually, I am quite confused by the mechanism of SC2, if I run 8 parallel envs, will the SC2 spawn an SC2 daemon and 8 child process?

GoingMyWay commented 4 years ago

@douglasrizzo Is is really important? For SC2, is using GPU slower?

Each sc2 process eating GPU memory, the number of parallel environments running is limited by your GPU VRAM.

I see. That is a quite large overhead of GPU memory.

samvelyan commented 4 years ago

Thanks @douglasrizzo !

GoingMyWay commented 4 years ago

@douglasrizzo Great improvement for SMAC. May I ask you a question, for beginners, how to read the PySC2 code to grasp a deeper understanding of SC2? For me, PySC2 is really a black-box.

douglasrizzo commented 4 years ago

Tutorials and examples

Steven Brown's tutorials on how to create StarCraft II agents from scratch, without using reinforcement learning.

Chris Hoyean Song's tutorials include RL and DRL algorithms, but are a little outdated in regards to the PySC2 API.

Third-party libraries

Reaver: Modular Deep Reinforcement Learning Framework. Focused on StarCraft II. Supports Gym, Atari, and MuJoCo. Matches reference results. python-sc2: A StarCraft II API Client for Python 3

Online communities

@GoingMyWay

GoingMyWay commented 4 years ago

Tutorials and examples

Steven Brown's tutorials on how to create StarCraft II agents from scratch, without using reinforcement learning.

Chris Hoyean Song's tutorials include RL and DRL algorithms, but are a little outdated in regards to the PySC2 API.

Third-party libraries

Reaver: Modular Deep Reinforcement Learning Framework. Focused on StarCraft II. Supports Gym, Atari, and MuJoCo. Matches reference results. python-sc2: A StarCraft II API Client for Python 3

Online communities

@GoingMyWay

Really, really great! Thanks, hope I can contribute more to this community.