Skip to content

feat(nemo-gym): define shard configuration - #3369

Merged
terrykong merged 3 commits into
mainfrom
ansubramania/gym-shards/schema
Sep 16, 2026
Merged

terrykong merged 3 commits into
mainfrom
ansubramania/gym-shards/schema

Conversation

@ananthsub

@ananthsub ananthsub commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Defines the configuration used to split one NeMo-Gym stack across several Ray actors. This PR validates and composes shard configurations but does not create multiple actors yet.

nemo_rl/environments/nemo_gym_shards.py adds:

  • ShardSpec, which describes one named configuration slice, its inherited entries, explicit overrides, replicas, CPU allocation, and optional port range.
  • ShardPlan, which describes shared entries, shared overrides, duplicate-entry allowances, and placement settings for the complete stack.
  • parse_shard_plan(), which validates shard ownership and preserves the unchanged unsharded fallback.
  • apply_shard_overlay(), which composes the Gym configuration for one shard.
  • apply_shard_log_dir(), which gives each shard instance a separate log directory.

A one-shard plan automatically owns unclaimed entries. A multi-shard plan must assign each Gym entry exactly once through inherited_overlays or common_inherited_overlays. Missing, duplicate, and unknown claims fail with the resolved entry inventory. NeMo RL integration settings such as effort_levels and tokenizer_config are excluded from that inventory.

Configuration precedence is deterministic: inherited values, then common_overrides, then shard-specific overrides. A non-null top-level config_paths value is rejected because each path must belong to a specific shard. Explicit port ranges use Gym's inclusive bounds and must stay within ports 1 through 65535.

Example

env:
  nemo_gym:
    common_inherited_overlays:
      - policy_model
    allowed_duplicate_entries:
      - policy_model
    shards:
      - name: tools
        inherited_overlays:
          - code_gen
        config_paths:
          - resources_servers/workplace_assistant/configs/workplace_assistant.yaml
      - name: judged
        inherited_overlays:
          - math_with_judge
        config_paths:
          - resources_servers/math_with_judge/configs/math_with_judge.yaml

Stack

This PR depends on #3633. Multi-actor creation follows in #3371.

@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.

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from ffc2c2c to 301cbcc Compare August 13, 2026 21:44
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 301cbcc to 9ef1e54 Compare August 13, 2026 22:04
@ananthsub
ananthsub changed the base branch from ansubramania/gym-shards/lifetime to ansubramania/gym-shards/introspection August 13, 2026 22:10
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 9ef1e54 to b6f7775 Compare August 13, 2026 22:14
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from b6f7775 to 487f9d5 Compare August 14, 2026 17:07
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 487f9d5 to 5c010da Compare August 31, 2026 18:02
@ananthsub
ananthsub marked this pull request as ready for review August 31, 2026 18:11
@ananthsub
ananthsub requested review from a team as code owners August 31, 2026 18:11
@copy-pr-bot

copy-pr-bot Bot commented Aug 31, 2026

Copy link
Copy Markdown

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

Contributors can view more details about this message here.

@ananthsub ananthsub changed the title feat(nemo-gym): add the shard config schema feat(nemo-gym): define shard configuration Aug 31, 2026
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 5c010da to 931fe8f Compare September 1, 2026 06:26
@ananthsub ananthsub added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Sep 1, 2026
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 931fe8f

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 931fe8f to f85f21b Compare September 1, 2026 17:42
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test f85f21b

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from f85f21b to b6bdd33 Compare September 2, 2026 05:50
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test b6bdd33

1 similar comment
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test b6bdd33

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 0cf7db7 to 2354403 Compare September 9, 2026 05:25
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 2354403

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 2354403 to 44371c5 Compare September 9, 2026 22:03
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 44371c5

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from 44371c5 to 56dbaad Compare September 11, 2026 00:37
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test 56dbaad

terrykong
terrykong previously approved these changes Sep 11, 2026

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All nine comments are addressed. I checked each one against the current head (56dbaad) rather than going by the replies:

  • The per-shard port range now reaches the actor — build_nemo_gym_config pops the range off the Gym dict and passes it as a NemoGymConfig field, so _spinup reads a populated field instead of falling back to 5000-5999.
  • parse_shard_plan raises when sharding keys appear with no shards block, naming the stray keys.
  • SHARD_SPEC_KEYS and SHARDING_CONFIG_KEYS both derive from their dataclasses, so neither can drift again.
  • allowed_duplicate_entries goes through _as_string_set like its sibling lists.
  • Both override layers reject config_paths and reject entries another shard claims.
  • The find_gym_config_entries docstring and the stripped-keys comment now describe what the code actually does.
  • The module is in pyrefly.toml and passes — pyrefly 0.24.2 reports 0 errors on it.
  • total_instances is gone.

I also ran it: 50 unit tests pass, up from 40. Since the new guards exist because I asked for them, I checked they do not reject anything legitimate — tuning a commonly-inherited entry through common_overrides, a shard tuning the entry it claims, defining a brand-new shared entry, a plain setting, the single-shard auto-claim, and the unsharded path are all still accepted. The four mistake shapes are rejected with messages that name the fix.

Two notes, neither blocking. CI was triggered at this head a few minutes ago and has not finished, so the approval is on the code, not on a green run. And this is stacked on #3633, so it cannot reach main until the PRs below it land.

Generated by Claude Code

stacked auto-merge was automatically disabled September 11, 2026 23:27

Pull Request is not mergeable

stacked auto-merge was automatically disabled September 11, 2026 23:54

Pull Request is not mergeable

@terrykong
terrykong force-pushed the ansubramania/gym-shards/schema branch from 56dbaad to 5ba4a41 Compare September 11, 2026 23:55
Base automatically changed from ansubramania/gym-shards/introspection to main September 12, 2026 22:07
@terrykong
terrykong force-pushed the ansubramania/gym-shards/schema branch from 5ba4a41 to c00cba1 Compare September 12, 2026 22:07
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test c00cba1

@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from c00cba1 to e1949da Compare September 14, 2026 16:46
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test e1949da

@ananthsub
ananthsub requested a review from terrykong September 14, 2026 16:47
Add env.nemo_gym.shards, common_overrides, and allowed_duplicate_entries,
with validation and per-shard config composition. Actor creation remains in a
later layer; sharded configs fail during setup until that factory is present.

Reject top-level config paths and Gym entry overlays when shards are declared
because their owning shard is ambiguous. Remove NeMo-RL-only sharding keys
before forwarding the merged config to Gym.

Add per-instance log-directory suffixing alongside the schema so actors that
host the same server names do not append to the same files.

Signed-off-by: Ananth Subramaniam <[email protected]>
Keep inherited Gym entry values in their parent recipe while assigning each
entry to a shard explicitly. Single-shard plans claim all remaining entries
automatically because their scope is unambiguous.

Signed-off-by: Ananth Subramaniam <[email protected]>
Keep dict-shaped rollout and tokenizer settings out of the Gym server-entry
inventory because NeMo RL consumes them separately.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ansubramania/gym-shards/schema branch from e1949da to cd2a29d Compare September 15, 2026 06:59
@ananthsub

Copy link
Copy Markdown
Contributor Author

/ok to test cd2a29d

@terrykong
terrykong merged commit 806e9d1 into main Sep 16, 2026
149 of 151 checks passed
@terrykong
terrykong deleted the ansubramania/gym-shards/schema branch September 16, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants