# RLLib: How to parallelize learning different scenarios correctly?

**URL:** https://discuss.ray.io/t/rllib-how-to-parallelize-learning-different-scenarios-correctly/23228
**Category:** RLlib
**Created:** [October 1, 2025, 3:22pm UTC](https://discuss.ray.io/t/rllib-how-to-parallelize-learning-different-scenarios-correctly/23228 "2025-10-01T15:22:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hoopwoop](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/hoopwoop/32/8283_2.png) [@hoopwoop](https://discuss.ray.io/u/hoopwoop)
#### Post date: [October 1, 2025, 3:22pm UTC](https://discuss.ray.io/t/rllib-how-to-parallelize-learning-different-scenarios-correctly/23228/1 "2025-10-01T15:22:07Z")

</div>

I want to know how to parallelize the learning to learn a fixed scenario in each env correctly. I now use on\_environment\_created() in Rllibcallback to assign different scenarios to different env\_runners (each runner runs 1 env). So the assignment is like following, runner1 always runs scenario1, runner2 always runs scenario2, etc… And it assigns based on env\_runner.worker\_index. Is this the correct way of doing it or there’s better way, e.g. use connector or etc…?

Thanks

Ray Ver 2.44.1  
use multiagent PPO

---

<div class="post-metadata">

### Author: ![RunLLM](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/runllm/32/8249_2.png) [@RunLLM](https://discuss.ray.io/u/RunLLM)
#### Post date: [October 1, 2025, 3:22pm UTC](https://discuss.ray.io/t/rllib-how-to-parallelize-learning-different-scenarios-correctly/23228/2 "2025-10-01T15:22:37Z")

</div>

Yes, assigning different scenarios to each env\_runner based on `env_runner.worker_index` is a correct and recommended approach in RLlib. The `env_config` passed to each environment instance includes `worker_index`, which you can use to select the scenario for that environment. This is documented in the official RLlib environment guide, which shows how to use `config.worker_index` to customize each environment instance, ensuring each EnvRunner always runs its assigned scenario. Using a connector is not necessary for this use case; the current method is standard and efficient for scenario assignment in parallelized training setups, including multi-agent PPO.

For example, you can implement this by customizing your environment’s constructor to select the scenario based on `config.worker_index`, as shown in the RLlib documentation:

```python
class EnvDependingOnWorkerAndVectorIndex(gym.Env):
    def __init__ (self, config):
        scenario = choose_scenario_for(config.worker_index)
        # Initialize env with scenario

```

Sources:

- [RLlib Environments — worker\_index usage](https://github.com/ray-project/ray/blob/releases/2.44.1/doc/source/rllib/rllib-env.rst)
- [Discourse: Rollout worker index with ExternalEnv](https://discuss.ray.io/t/rollout-worker-index-with-externalenv/813)

Hint: Mention @RunLLM in the post for followups.
