Skip to content

Conversation

@drl-test
Copy link

@drl-test drl-test commented Dec 13, 2025

Implements PoolVecEnv, which is suitable for training RL algorithms with a large batch size.

Motivation and Context

For cases where large batch sizes are needed, currently SB3 provides two VecEnv:

  • DummyVecEnv: fully utilize the capabilities of a multi-core system, leading to slow performance.
  • SubprocVecEnv: 1. Simulating a large(e.g., 128) number of envs use too many sub-processes and may cause OOM error, 2. subprocess-related overhead (e.g., context switches or message communications) when spawning many subprocesses.

A solution should exist that both supports large batch size and use multi-core capabilities. Although the third-party solution Envpool is suitable for this, it's C++ based. This necessitates rewriting the implementation of each environment in C++, making it less flexible when environments are already implemented in Python.

Description

PoolVecEnv is implemented here which runs N envs in M workers (M is user specified and less or equal than CPU cores).

the current implementation is bucket-base, which dispatches an (approx) equal number of envs to each subprocess. Further optimization may utilize something like threadpool when Python's new non-GIL feature is stable and extensively used.

Benchmarks

Setup: Intel.E5-2697 + 128GB Mem

(FPS is the total steps of all envs per second)

  • Test1: CartPole-V1
    image

  • Test2: HumanoidStandup-v5
    image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

  • I've read the CONTRIBUTION guide (required)
  • I have updated the changelog accordingly (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have opened an associated PR on the SB3-Contrib repository (if necessary)
  • I have opened an associated PR on the RL-Zoo3 repository (if necessary)
  • I have reformatted the code using make format (required)
  • I have checked the codestyle using make check-codestyle and make lint (required)
  • I have ensured make pytest and make type both pass. (required)
  • I have checked that the documentation builds using make doc (required)

Note: You can run most of the checks using make commit-checks.

@drl-test drl-test marked this pull request as ready for review December 14, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant