Skip to content

[BugFix] Seed batched native MuJoCo workers distinctly - #4208

Merged
vmoens merged 1 commit into
mainfrom
mujoco-batched-seed
Sep 4, 2026
Merged

[BugFix] Seed batched native MuJoCo workers distinctly#4208
vmoens merged 1 commit into
mainfrom
mujoco-batched-seed

Conversation

@vmoens

@vmoens vmoens commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Description

MujocoEnv(num_envs=N, seed=s, backend="mujoco") builds one worker per env through _MujocoMeta from the same kwargs, so every SerialEnv / ParallelEnv worker was seeded with s and replayed the same reset noise (and, for MicroDuckEnv, the same velocity command at every reset). Each worker now receives its own seed through create_env_kwargs, derived from the requested seed with torchrl._utils.seed_generator (the same chain EnvBase.set_seed walks across a batch), so the batch stays reproducible for a given seed and a later set_seed produces the same assignment. seed=None was unaffected.

Found while writing the MicroDuckTask docstring example in #4204: four envs built with seed=0 all drew the same command.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTION guide (required)
  • I have updated the tests accordingly (required for a bug fix or a new feature).

Validation

test_native_batched_workers_draw_distinct_reset_noise (serial and parallel) asserts that two workers built from one seed reset to different observations and that two envs built from the same seed reset identically; it fails on main and passes with the fix.

🤖 Generated with Claude Code

@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4208

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 4a30c44 with merge base 573d8dd (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 3, 2026
@github-actions github-actions Bot added Environments Adds or modifies an environment wrapper BugFix labels Sep 3, 2026
MujocoEnv(num_envs=N, seed=s, backend="mujoco") built every SerialEnv or
ParallelEnv worker from the same kwargs, so all workers shared one RNG
stream and drew identical reset noise (and, for subclasses, identical
commands). Derive one seed per worker with torchrl._utils.seed_generator,
the chain EnvBase.set_seed uses across a batch, and pass it through
create_env_kwargs, so each worker gets its own seed while a given seed
stays reproducible.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@vmoens
vmoens force-pushed the mujoco-batched-seed branch from 162e29f to 4a30c44 Compare September 3, 2026 10:26
@vmoens
vmoens merged commit 12da2ba into main Sep 4, 2026
131 of 132 checks passed
@vmoens
vmoens deleted the mujoco-batched-seed branch September 4, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BugFix CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Environments Adds or modifies an environment wrapper

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant