Skip to content

refactor(nemo-gym): centralize the gym actor factory - #3367

Draft
ananthsub wants to merge 1 commit into
mainfrom
ansubramania/gym-shards/factory
Draft

refactor(nemo-gym): centralize the gym actor factory#3367
ananthsub wants to merge 1 commit into
mainfrom
ansubramania/gym-shards/factory

Conversation

@ananthsub

@ananthsub ananthsub commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

Moves the construction of the NemoGym Ray actor into a single factory, so the three places that start one no longer each carry their own copy of the setup logic.

nemo_rl/algorithms/grpo.py, nemo_rl/algorithms/distillation.py, and nemo_rl/algorithms/single_controller_utils/setup.py each built the actor's config inline. The three copies had already drifted: they split NeMo-RL-only keys out of the gym config differently, and they disagreed about the uv cache and venv directories and about router replay. Adding anything to the actor's setup meant finding and editing all three.

This PR adds two functions to nemo_rl/environments/nemo_gym.py:

  • build_nemo_gym_config(...) assembles the config the actor receives: it separates the keys NeMo-RL owns from the ones it forwards to Gym, resolves the uv cache and venv directories, and applies the router replay settings.
  • spinup_nemo_gym_actor(...) creates the actor with the right runtime environment and scheduling, then spins it up.

All three call sites now call the factory with keyword arguments. Behavior is unchanged: this is a refactor, and the resulting actor config is the same one the previous inline code produced.

The detailed assertions about config assembly moved from tests/unit/algorithms/test_distillation.py (where they only covered the distillation copy) to tests/unit/environments/test_nemo_gym_utils.py, where they cover the shared factory.

This is the first of eight stacked PRs adding actor sharding to NeMo-Gym. It is a prerequisite rather than a feature: the later PRs need one place to change.

Issues

None.

Usage

No user-facing change. Configs and command lines are unaffected.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • Verified with a 10-step async-GRPO workplace_assistant run on 2 GPUs. Validation accuracy is bit-identical to the pre-change baseline on that fixture, which is the signal that the refactor did not alter config assembly.

The NemoGym actor was constructed in three places (grpo.setup,
distillation.setup, single_controller_utils.setup) that had drifted apart,
each forgetting a different field:

- single_controller never passed use_fastokens or routed_experts_dtype
- distillation never passed require_routed_experts
- grpo and single_controller built runtime_env inline and set VIRTUAL_ENV to
  the *interpreter path* rather than the venv root

Collapse all three onto spinup_nemo_gym_actor(), split out
build_nemo_gym_config() so the config split (NeMo-RL knobs vs Gym's global
config) is testable on its own, and use the shared make_actor_runtime_env()
helper, which resolves VIRTUAL_ENV correctly. This makes the actor-creation
path a single place to extend for multi-actor sharding.

Distillation keeps require_routed_experts off: it never configures vLLM to
emit routed experts, so requiring them would fail every rollout.

The construction assertions that lived in the distillation tests move to the
factory's own test module, where they cover all three callers at once.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

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