question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SubprocVecEnv performance compared to gym.vector.async_vector_env

See original GitHub issue

Hi,

I’m trying to use SubProcVecEnv to create a vectorized environment and use it in my own PPO implementation. I have a couple of questions about the performance of this vectorization and hyperparameters.

I have a 28 cores CPU on my system and an RTX 2080Ti GPU. When I use gym.vector.async_vector_env to create vectorized envs, it is 3 to 6 times faster than SubProcVecEnv from stable_baselines3.

In SubProcVecEnv, when I set the number of threads using torch.set_num_threads(28) all the cores are involved but again it is almost two times slower than using torch.set_num_threads(10).

I also did all the comparisons by creating 100 parallel envs. I’m not sure how would I set this number of envs and torch number of threads. I think this slower performance compared to gym.vector.async_vector_env is because of the bad hyperparameters I used.

What are the parameters I can use to get the best performance? which parameters are the most important ones?

Thank you

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
araffincommented, Jul 25, 2020

The overhead comes from inter-process communication, which is super-slow if the environments are fast and data is small. Edit: One should bear in mind multiple envs has other effects than sample speed alone. More environments -> more samples from different states of the environment -> better estimation of the expectations. Generally one should see stabler learning with more environments, but not necessarily more sample efficient.

We have a tutorial about that 😉 See notebook 3: https://github.com/araffin/rl-tutorial-jnrr19#content

1reaction
Miffylicommented, Jul 27, 2020

Yes, using more environments (with same n_step -> more samples) is expected to result in stabler and/or faster learning, sometimes even in terms of env steps. I tried to look for a paper that had experiments on this very topic but can not find it for the life of me. Closest thing I have to share is the OpenAI Dota 2 paper, where in Figure 5 they compare different batch sizes.

The training times should be minuscule and only have a real effect on training speed if you can reach thousands of FPS with your environment (e.g. basic control tasks).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vectorized Environments - Stable Baselines - Read the Docs
An abstract asynchronous, vectorized environment. Parameters: num_envs – (int) the number of environments; observation_space – (Gym Space) the observation ...
Read more >
Vectorized Environments — Gym 0.20.0 documentation
gym.vector.AsyncVectorEnv , where the sub-environments are executed in parallel using multiprocessing. This creates one process per sub-environment.
Read more >
Vectorising your environments - Gym Documentation
SyncVectorEnv (for sequential execution), or gym.vector.AsyncVectorEnv (for parallel execution, with multiprocessing). These vectorized environments take as ...
Read more >
SubprocVecEnv not working with Custom Env (Stable Baselines
Check this sample code: import numpy as np import gym from baselines.common.vec_env.subproc_vec_env import SubprocVecEnv env_name ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found