Repository navigation
refactor(config): move config modules into nemo_gym/config - #5189
Conversation
|
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. |
4a80afc to
3d1c9bd
Compare
4f87f8a to
a697439
Compare
svcnvidia-nemo-ci
left a comment
There was a problem hiding this comment.
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.
a697439 to
543f82a
Compare
15a4860 to
116b97b
Compare
116b97b to
11e0fe1
Compare
yaoyu-33
left a comment
There was a problem hiding this comment.
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 Xin 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-importskeeps the contract, and all five renamedignore_importsentries 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 8gives 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
mainduring the review. This PR's own diff did not change, and the comments point atd75db14.
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_attrsoverwrites it.- So
importlib.util.find_spec("nemo_gym.config.config_types").namereturns the old name, andimportlib.reloadof 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.
- So
- #5167, attribute access without an import.
import nemo_gym.server_utils; nemo_gym.global_configused to work through the transitive import. It now raisesAttributeError, 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 theAGENTS.mdcomment). - Later moves:
harness_agent/agent_runner.py'sopenai_utilsandserver_utilsimports will need the same fallback when those modules move._build_gym_tar's--exclude=data(app.py#L210) will dropnemo_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.
yaoyu-33
left a comment
There was a problem hiding this comment.
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.
|
On the notes for other PRs in the stack:
|
yaoyu-33
left a comment
There was a problem hiding this comment.
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]>
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.
Where the package sits
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
How to review
One commit. Its changes:
Renames, with no content changes.
Everything else:
nemo_gym/_moved_paths.py, shipping in 0.8.0;python scripts/migrate_imports.py, thenruff check --select I --fixandruff format;nemo_gym/__init__.py's lazy exports, the contract's config layer (now thenemo_gym.configpackage), and redirects infern/docs.ymlfrom the old library reference pages to the new ones, with and without the version slug (/main/,/v0.7.0/, ...).Tests of the moved modules move into
tests/unit_tests/config/:test_global_config.py,test_config_types_help.py, andtest_secret_utils.py. Two CLI test modules that import a test class fromtest_global_config.pyfollow it.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_sourcebundle installed, which can predate this move. They import from the new paths first and, when anemo_gymmodule 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"]Each runner's fallback block was run against
main'snemo_gymand 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.patchtargets, 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.pybuilds a package's__getattr__and__dir__from a_PUBLIC_APItable 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. ATYPE_CHECKINGblock names the same imports for type checkers.nemo_gym/imports from it: servers, benchmarks, scripts, and code samples in docs and skills. This PR givesconfig/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.nemo_gym/and its tests (servers and their tests, benchmarks, scripts, and docs) imports those names fromnemo_gym.<package>; templates held in strings, such as sandbox runner templates and the environment scaffold, follow. The library's tests undertests/import from the module that defines each name, like code insidenemo_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.pywrites this form for code outsidenemo_gym/, and a test scans non-test code outsidenemo_gym/for exported names imported from a submodule.OmegaConfis not part ofnemo_gym.config. FastAPI'sBodyis the exception, in the agent and model packages: servers declare their endpoints with it next to the base classes.nemo_gym/imports submodules directly, never a public API, so the import-linter contract sees every dependency.AGENTS.mdstates the rule.__all__anddir(), and that each package'sTYPE_CHECKINGimports match its table. Importing a package in a fresh interpreter loads only what its existing eager exports need: four submodules forsandbox, none for the others. For every package and name, an unknown name raisesAttributeErrorand a patch of the submodule shows through the package. A submodule that fails withAttributeErrorwhile it imports raisesImportErrorwith the cause, rather than a barecannot import name.Validation
pytest -n 16 tests/unit_tests. The failures are the same onmainat 5911d62 on this machine: the benchmark listing test and the Harbor run summary tests, which fail because this machine's hostname resolves to127.0.1.1, and the Docker PTY tests for a PID file that is not a regular file.-W errorfor the four moved paths' warnings: same result, so nothing in the repo still imports an old path.from nemo_gym import config_typesandnemo_gym.global_config.lint-imports;pre-commit run --all-files.gym env testforresources_servers/example_single_tool_callandresponses_api_agents/simple_agent, each in its own venv.Rollout evidence: N/A. The modules move unchanged.
Compatibility
nemo_gym.config.*; a logging config onnemo_gymstill covers them.python scripts/migrate_imports.py <paths>.Issue
Part of #5166.