Skip to content

refactor(config): move config modules into nemo_gym/config - #5189

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/layout-config
Oct 30, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-config

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The first module move. The four modules that load and describe the run config move into a new nemo_gym/config/ package, at the bottom of the package order, so every later package has a stable place to import config from.

Where this PR sits

The stack lands bottom-up; each PR's base is the branch of the PR before it, so each diff shows only that PR's change.

flowchart LR
  compat["#5167<br/>Old import paths<br/>keep working"]
  linter["#5168<br/>import-linter<br/>layer contract"]
  prep["#5169<br/>Remove path and<br/>name couplings"]
  config["#5189<br/>Move config/"]
  utils["#5195<br/>Move utils/"]
  core["#5203<br/>Move core/"]
  client["#5206<br/>Move client/,<br/>start telemetry/"]
  trajectory["#5209<br/>Move trajectory/"]
  verification["#5210<br/>Move verification/"]
  metrics["#5211<br/>Move metrics/"]
  artifacts["#5212<br/>Move artifacts/"]
  srmods["#5214<br/>Move server_runtime/<br/>modules"]
  su["#5215<br/>Split server_utils"]
  model["#5224<br/>Move models/<br/>modules"]
  modelbase["#5225<br/>Split model<br/>call capture"]
  agents["#5228<br/>Move agents/"]
  data["#5229<br/>Move data/"]
  harbor["#5230<br/>Split the<br/>Harbor task CLI"]
  rollouts["#5231<br/>Move rollouts/"]
  rsplit["#5232<br/>Split the<br/>rollout collector"]
  testing["#5233<br/>Dissolve testing/"]
  orch["#5234<br/>Move orchestration/<br/>modules"]
  sup["#5235<br/>Split the<br/>server supervisor"]
  eval["#5244<br/>Move eval/"]
  env["#5298<br/>Move environment/<br/>registries"]
  cli["#5300<br/>Retire the<br/>cli_setup_command shim"]
  docs["#5385<br/>Describe the<br/>package layout"]
  owners["next<br/>CODEOWNERS:<br/>per-package groups"]
  remove["0.10.0<br/>Remove the<br/>old paths"]
  compat --> linter
  linter --> prep
  prep --> config
  config --> utils
  utils --> core
  core --> client
  client --> trajectory
  trajectory --> verification
  verification --> metrics
  metrics --> artifacts
  artifacts --> srmods
  srmods --> su
  su --> model
  model --> modelbase
  modelbase --> agents
  agents --> data
  data --> harbor
  harbor --> rollouts
  rollouts --> rsplit
  rsplit --> testing
  testing --> orch
  orch --> sup
  sup --> eval
  eval --> env
  env --> cli
  cli --> docs
  docs --> owners
  owners --> remove
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  classDef later fill:#f3f4f6,stroke:#9ca3af,color:#4b5563,stroke-dasharray: 4 3
  class config this
  class owners,remove later
Loading

Where the package sits

flowchart TD
  cli["cli/"]
  eval["eval/"]
  environment["environment/"]
  testing["testing/"]
  orchestration["orchestration/"]
  rollouts["rollouts/"]
  data["data/"]
  agents["agents/"]
  model["models/"]
  server_runtime["server_runtime/"]
  artifacts["artifacts/"]
  metrics["metrics/"]
  verification["verification/"]
  trajectory["trajectory/"]
  sandbox["sandbox/"]
  client["client/"]
  telemetry["telemetry/"]
  core["core/"]
  utils["utils/"]
  config["config/"]
  cli --> eval
  cli --> environment
  cli --> orchestration
  eval --> rollouts
  environment --> data
  testing --> rollouts
  orchestration --> data
  rollouts --> data
  rollouts --> agents
  rollouts --> model
  data --> server_runtime
  data --> artifacts
  agents --> server_runtime
  model --> server_runtime
  server_runtime --> metrics
  server_runtime --> verification
  server_runtime --> trajectory
  artifacts --> trajectory
  artifacts --> utils
  metrics --> utils
  verification --> sandbox
  trajectory --> core
  sandbox --> client
  client --> telemetry
  client --> utils
  telemetry --> core
  core --> config
  utils --> config
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  classDef done fill:#d1fae5,stroke:#047857,color:#1f2937
  classDef todo fill:#f3f4f6,stroke:#9ca3af,color:#4b5563
  class config this
  class cli,eval,environment,testing,orchestration,rollouts,data,agents,model,server_runtime,artifacts,metrics,verification,trajectory,sandbox,client,telemetry,core,utils todo
Loading

An arrow means "imports"; each package imports only packages below it. Yellow: created by this PR. Green: created by an earlier PR in the stack. Grey: still to come.

What moves

flowchart LR
  A["nemo_gym/config_types.py"] --> A2["nemo_gym/config/config_types.py"]
  B["nemo_gym/global_config.py"] --> B2["nemo_gym/config/global_config.py"]
  C["nemo_gym/secret_utils.py"] --> C2["nemo_gym/config/secret_utils.py"]
  D["nemo_gym/server_metadata.py"] --> D2["nemo_gym/config/server_metadata.py"]
  classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937
  class A2,B2,C2,D2 this
Loading

How to review

One commit. Its changes:

  1. Renames, with no content changes.

  2. Everything else:

    • the four moves recorded in nemo_gym/_moved_paths.py, shipping in 0.8.0;
    • every in-repo reference rewritten by python scripts/migrate_imports.py, then ruff check --select I --fix and ruff format;
    • by hand: the short module names in nemo_gym/__init__.py's lazy exports, the contract's config layer (now the nemo_gym.config package), and redirects in fern/docs.yml from the old library reference pages to the new ones, with and without the version slug (/main/, /v0.7.0/, ...).
  3. Tests of the moved modules move into tests/unit_tests/config/: test_global_config.py, test_config_types_help.py, and test_secret_utils.py. Two CLI test modules that import a test class from test_global_config.py follow it.

  4. Sandbox runners fall back to the old path. The AnySWE, CVDP, and Exa search runners, the AnyTerminal runner template, and harness_agent's runner run inside a sandbox against the nemo-gym its image, runtime archive, or prebuilt gym_source bundle installed, which can predate this move. They import from the new paths first and, when a nemo_gym module is missing, from the old ones:

flowchart LR
  R["Runner in the sandbox"] --> N{"from nemo_gym.config.config_types ..."}
  N -->|"imports"| OK["New layout"]
  N -->|"ModuleNotFoundError for nemo_gym.*"| O["from nemo_gym.config_types ...<br/># path before nemo_gym 0.8.0"]
  N -->|"any other missing module"| E["Error, as before"]
Loading

Each runner's fallback block was run against main's nemo_gym and this branch's: both import, and the new layout raises no deprecation warning. The import rewriter leaves the marked lines alone, so later PRs update only the new-layout imports.

The rewrite covers nemo_gym/, servers, benchmarks, tests, scripts, agent skills, mock.patch targets, CODEOWNERS paths, the import-linter contract, and the current docs. Docs for released versions keep the old paths. Code owners do not change.

Public API

This PR introduces package public APIs. nemo_gym/_public_api.py builds a package's __getattr__ and __dir__ from a _PUBLIC_API table in its __init__.py, which maps each public name to the submodule that defines it. A name's submodule loads on first use, so importing a package imports none of its submodules and adds no import edges. A TYPE_CHECKING block names the same imports for type checkers.

flowchart LR
  S["Code outside nemo_gym:<br/>from nemo_gym.config import ModelServerRef"] --> P["nemo_gym/config/__init__.py<br/>_PUBLIC_API: name to submodule"]
  P -->|"first use"| M["nemo_gym.config.config_types"]
  L["Code inside nemo_gym"] -->|"imports directly"| M
Loading
  • Each package exports the public names that non-test code outside nemo_gym/ imports from it: servers, benchmarks, scripts, and code samples in docs and skills. This PR gives config/ its public API, and the packages that exist before the reorganization (sandbox/, telemetry/) the names that code imports beyond their existing exports. Each later package PR adds its own package's and keeps the earlier ones current when names move.
  • Code outside nemo_gym/ and its tests (servers and their tests, benchmarks, scripts, and docs) imports those names from nemo_gym.<package>; templates held in strings, such as sandbox runner templates and the environment scaffold, follow. The library's tests under tests/ import from the module that defines each name, like code inside nemo_gym/, and a test checks this. A patch target names the module the code under test looks the name up in. Lines that sandbox runners keep for an older nemo-gym are left alone. scripts/migrate_imports.py writes this form for code outside nemo_gym/, and a test scans non-test code outside nemo_gym/ for exported names imported from a submodule.
  • A third-party class or function that a submodule imports is not exported, so OmegaConf is not part of nemo_gym.config. FastAPI's Body is the exception, in the agent and model packages: servers declare their endpoints with it next to the base classes.
  • Code inside nemo_gym/ imports submodules directly, never a public API, so the import-linter contract sees every dependency. AGENTS.md states the rule.
  • Tests check that each public name is the object its submodule defines and is listed in __all__ and dir(), and that each package's TYPE_CHECKING imports match its table. Importing a package in a fresh interpreter loads only what its existing eager exports need: four submodules for sandbox, none for the others. For every package and name, an unknown name raises AttributeError and a patch of the submodule shows through the package. A submodule that fails with AttributeError while it imports raises ImportError with the cause, rather than a bare cannot import name.

Validation

  • pytest -n 16 tests/unit_tests. The failures are the same on main at 5911d62 on this machine: the benchmark listing test and the Harbor run summary tests, which fail because this machine's hostname resolves to 127.0.1.1, and the Docker PTY tests for a PID file that is not a regular file.
  • The same suite with -W error for the four moved paths' warnings: same result, so nothing in the repo still imports an old path.
  • The compatibility tests from feat(compat): keep old import paths working across the package reorganization #5167 run against real entries, including NeMo RL's from nemo_gym import config_types and nemo_gym.global_config.
  • lint-imports; pre-commit run --all-files.
  • gym env test for resources_servers/example_single_tool_call and responses_api_agents/simple_agent, each in its own venv.

Rollout evidence: N/A. The modules move unchanged.

Compatibility

  • The four old paths work until 0.10.0, as the same module objects, with one warning each.
  • These modules now log under nemo_gym.config.*; a logging config on nemo_gym still covers them.
  • Open branches: run python scripts/migrate_imports.py <paths>.

Issue

Part of #5166.

@ananthsub
ananthsub added this pull request to stack #5170 October 28, 2026 16:24
@copy-pr-bot

copy-pr-bot Bot commented Oct 28, 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 added the area:config Hydra configuration, schemas, composition, and compatibility label Oct 28, 2026
@ananthsub ananthsub self-assigned this Oct 28, 2026
@ananthsub ananthsub changed the title ananthsub/layout config refactor(config): move config modules into nemo_gym/config Oct 28, 2026
@ananthsub
ananthsub force-pushed the ananthsub/layout-config branch from 4a80afc to 3d1c9bd Compare October 28, 2026 16:54
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the feature New capabilities, enhancements, or enablement work label Oct 28, 2026
@ananthsub
ananthsub force-pushed the ananthsub/layout-config branch 2 times, most recently from 4f87f8a to a697439 Compare October 28, 2026 17:45
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 17:47
@ananthsub
ananthsub requested a review from a team as a code owner October 28, 2026 17:47
@ananthsub
ananthsub requested a review from yaoyu-33 October 28, 2026 17:47
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 17:49
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 28, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHIP WITH CARE

One RISK: copied sandbox runners now require the host’s new package layout, although their guest runtimes can be provisioned independently. Existing baked images and runtime archives can therefore stop working after this host-only upgrade.

The three review topics and affected cross-component paths are complete. No additional qualifying findings were found. Static inspection only; tests were not executed.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@ananthsub
ananthsub force-pushed the ananthsub/layout-config branch from a697439 to 543f82a Compare October 28, 2026 19:01

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review summary

This PR moves config_types, global_config, secret_utils and server_metadata into nemo_gym/config/ and adds the lazy package public API helper (nemo_gym/_public_api.py). It gives public APIs to config/, sandbox/ and telemetry/, records the four moves for the #5167 compatibility layer, and rewrites every in-repo reference.

Verdict: SHIP WITH CARE. One risk: harness_agent's runner needs the same old-layout fallback as the other four sandbox runners (inline). The other comments are notes.

What we checked

  • The bulk rewrite is mechanical.
    • We compared syntax trees with the path mapping applied: 649 of the 671 files are pure import, patch-target or path swaps.
    • All 244 rewritten (module, name) bindings resolve to the same object as before.
    • Every from nemo_gym.{config,sandbox,telemetry} import X in the tree resolves.
    • Old dotted paths remain only where expected: the compat files, the redirects, the marked fallback lines, released docs and recorded rollout data.
  • Old paths still work. Each of the four old paths gives the same module object with one warning.
  • lint-imports keeps the contract, and all five renamed ignore_imports entries still match real imports.
  • Four runner fallbacks (AnySWE, CVDP, Exa search, AnyTerminal):
    • Each imports against both this PR's base tree and its head.
    • Each still raises on a missing module outside nemo_gym.
  • Unit tests: pytest tests/unit_tests -n 8 gives 12218 passed.
    • Every failure either also fails on the base tree or passes when rerun alone (missing optional deps, a local hostname issue, timing).
    • With the four moved-path warnings turned into errors, the same suite finds no old-path import.
  • Server tests: the suites for the touched runners and model servers pass where their dependencies are installed.
  • Rebase: the stack was rebased onto a newer main during the review. This PR's own diff did not change, and the comments point at d75db14.

Notes for other PRs in the stack (nothing to change here)

  • #5167, __spec__ after an old-path import. The alias loader leaves the real module's __spec__ set to the alias, because CPython's _init_module_attrs overwrites it.
    • So importlib.util.find_spec("nemo_gym.config.config_types").name returns the old name, and importlib.reload of the module does nothing.
    • Nothing in the repo reloads these modules. This PR is the first to fill MOVED_MODULES, so this is the first PR where it can happen.
  • #5167, attribute access without an import. import nemo_gym.server_utils; nemo_gym.global_config used to work through the transitive import. It now raises AttributeError, with no deprecation warning.
  • #5167, scripts/migrate_imports.py. It rewrites to submodule paths, so branches migrated with it will not follow the new public API rule (see the AGENTS.md comment).
  • Later moves:
    • harness_agent/agent_runner.py's openai_utils and server_utils imports will need the same fallback when those modules move.
    • _build_gym_tar's --exclude=data (app.py#L210) will drop nemo_gym/data/ from the auto tarball once #5229 moves modules there.

PR description: the Public API example from nemo_gym.config import ConfigError raises ImportError, because ConfigError is not in _PUBLIC_API. An exported name such as ModelServerRef would work.

Comment thread nemo_gym/_public_api.py Resolved
Comment thread nemo_gym/config/__init__.py Resolved
Comment thread AGENTS.md Resolved
Comment thread fern/docs.yml Resolved
yaoyu-33
yaoyu-33 previously approved these changes Oct 29, 2026

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving at d75db14. Please still add the old-layout fallback in harness_agent/agent_runner.py (#5189 (comment)) before this merges; the other comments are notes.

@ananthsub

Copy link
Copy Markdown
Contributor Author

On the notes for other PRs in the stack:

yaoyu-33
yaoyu-33 previously approved these changes Oct 29, 2026

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-approving at 7ddbf2b. harness_agent/agent_runner.py now falls back to the old paths for all three of its nemo_gym imports, which settles the remaining item from the earlier approval. Unit tests / Test failed in the harbor tests on Docker Hub's rate limit (HTTP 429 for ubuntu:24.04), not on this change.

Rename config_types.py, global_config.py, secret_utils.py, and
server_metadata.py into the new nemo_gym/config package without changing
their contents.

Record the four moves in nemo_gym/_moved_paths.py, so the old paths keep
working with a deprecation warning until 0.10.0, and update every in-
repo reference to the new paths.

The references were rewritten by scripts/migrate_imports.py, then sorted
and formatted with ruff. Two edits were made by hand: the short module
names in the lazy exports of nemo_gym/__init__.py, and the import-linter
contract, whose config layer is now the nemo_gym.config package. Docs
for released versions keep the old paths, which are correct for those
releases.

Move the tests of the modules that moved into nemo_gym/config into a
matching test package: test_global_config.py, test_config_types_help.py,
and test_secret_utils.py. test_global_config.py finds the repository
root one directory further up.

The AnySWE, CVDP and Exa search runners and the AnyTerminal runner
template run inside a sandbox against the nemo-gym its image or runtime
archive installed, which can predate this move. Import from the new
paths first and, when a nemo_gym module is missing, from the paths
before the reorganization, marked so the import rewriter keeps them. A
missing dependency other than nemo_gym still fails.

Regenerate the public API of each layout package that exists here from
what non-test code outside nemo_gym imports, and point code outside
nemo_gym, tests included, at nemo_gym.<package>.

Signed-off-by: Ananth Subramaniam <[email protected]>

This branch was previously deployed

1 inactive deployment
public — 8bc695a0 Deployed Oct 30, 2026 by copy-pr-bot[bot] via release / finalize / notify #8675
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:config Hydra configuration, schemas, composition, and compatibility feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants