Repository navigation
refactor(core): move shared definitions into nemo_gym/core - #5203
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. |
b6ff053 to
abef69e
Compare
abef69e to
dda10ab
Compare
3a5bb65 to
7a253cf
Compare
|
Something went wrong on our side and the automatic retries didn't recover — please try again. (ref: |
4dedd69 to
8bf3ff4
Compare
8bf3ff4 to
3ca1363
Compare
3ca1363 to
d7efc8e
Compare
yaoyu-33
left a comment
There was a problem hiding this comment.
Thanks for laying this split out so carefully; the description made a 633-file diff easy to check. We reviewed this PR's own commit (base f99cdf08b1, head 29c432b0a5).
Verdict: SHIP. No blockers or risks. The inline comments are small NOTEs: one missing old-path name, a few stale "lives in openai_utils.py" pointers, two third-party names routed through nemo_gym.core, and one test that does not pin its map entry.
What we checked
- The 613 rewritten
.pyfiles are AST-identical to base apart from imports, and all 1,998 rewritten import bindings resolve to the same objects as before. - The three split modules lose and duplicate nothing. The only body change is the declared function-level config import in
maybe_rollout_id_from_run_body, and the import cycle it avoids is real. - Every moved pydantic model has a byte-identical JSON schema, and objects pickled under the old class paths load at this head.
- Every base name of
openai_utils,rollout_correlation,episode_typesandfailure_kindsstill resolves at its old path to the same object, exceptTypedDict(inline). - The five sandbox runners keep their old-path fallbacks and still import against a tree without
nemo_gym.core. Every touched server installs nemo-gym from the same checkout or wheel. lint-importspasses with 19 ignores. The split test files hold the same 373 test IDs. The full unit suite shows no failures caused by this PR, including with moved-pathDeprecationWarnings turned into errors.- CI: the red
Unit tests / Testis 11 Harbor tests hitting Docker Hub "Too Many Requests" forubuntu:24.04. The kilocode conformance probe fails the same way on #5189, #5195 and #5206. Neither comes from this PR.
PR description
-
[PROCESS] #5166 asks each split PR to list the patches that stop taking effect, and #5195 has a "Which patches still work" section. This PR splits three modules but lists none. Worth adding:
- Rebinding a moved name through its old module no longer reaches the code that uses it, e.g.
nemo_gym.rollout_correlation.ROLLOUT_ID_PATTERNornemo_gym.openai_utils.RESPONSES_TO_TRAIN. Mutating the shared object in place still works. from nemo_gym.openai_utils import *now yields 37 names instead of 290, withoutNeMoGymResponse.- The
failure_kindslogger is now namednemo_gym.core.failure_kinds.
We found no user of any of these in Gym or in NeMo RL main.
- Rebinding a moved name through its old module no longer reaches the code that uses it, e.g.
Stack-wide, not for this PR
- The star-import shrinks because
moved_names_getattr(#5167) defines no__dir__or__all__. Adding them there would let star-imports reach__getattr__and warn. - No test pins the
_LAZY_EXPORTStargets innemo_gym/__init__.pyto the module that defines each name: a stale entry still passes, because the old path serves the same object. A check that each name is invars()of the module it names would cover it, in whichever PR next edits that map. migrate_importsrewrites only whole-module paths in text. Later split PRs will leave file-path mentions like the ones flagged here, so a grep for the old file name is worth a step in each.
Rename openai_utils.py to core/responses_api_types.py, rollout_correlation.py to core/episode.py, and failure_kinds.py into core/, without changing their contents. Move back out of the renamed files, unchanged, what does not belong in core: the OpenAI client into a new openai_utils.py, and the rollout prefix middleware into a new rollout_correlation.py. Move EpisodeId, TaskId, and _CAPTURE_KEY_ATTEMPT from episode_types.py into core/episode.py. Each old module imports back what it uses and serves the rest through __getattr__ with a deprecation warning, including the openai and pydantic names that code imported through openai_utils. core/episode.py imports four config key names inside maybe_rollout_id_from_run_body, their only user: at module level the import would close a cycle, because global_config imports feature modules that import episode_types. Record the moves in nemo_gym/_moved_paths.py, which gains a helper for listing many names at once, and rewrite in-repo references with scripts/migrate_imports.py. By hand: the lazy exports in nemo_gym/__init__.py, the lazy-import map in base_responses_api_model.py and its test, a test that read three type aliases through the openai_utils module object, and the import-linter contract, whose core layer is the nemo_gym.core package and whose middleware module joins the server runtime group; six exceptions this resolves are removed. Move the tests of the code that moved into nemo_gym/core into a matching test package. test_failure_kinds.py moves whole. test_openai_utils.py becomes core/test_responses_api_types.py, and its client tests, with the fixture that pins their retry jitter, stay in test_openai_utils.py. The EpisodeId and TaskId tests move from test_episode_types.py into core/test_episode.py. test_rollout_correlation.py stays: it checks rollout IDs end to end through the servers, and moves with server_runtime. rollout_correlation still imports ROLLOUT_ID_PATTERN and rollout_context, and episode_types still imports EpisodeId and TaskId, so the names kept resolving without an entry. Record them in MOVED_NAMES so the import rewriter moves in-repo imports to nemo_gym.core.episode and their removal from the old modules is tracked like the other moved names. 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
Moves the definitions every package and every environment shares into a new
nemo_gym/core/package, just aboveconfig/: the Responses API and Chat Completions types, episode identity, and failure kinds. These are the most imported names in Gym and in NeMo RL, so this PR is the biggest compatibility surface of the reorganization.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
Three files are split. Each keeps the part that belongs to a later package, which moves with that package.
flowchart LR subgraph OA["openai_utils.py today"] T["Responses API and Chat Completions types"] CL["NeMoGymAsyncOpenAI client and retries"] end subgraph RC["rollout_correlation.py today"] E["Current-episode tracking and capture keys"] MW["RolloutContextMiddleware and the routed path"] end subgraph ET["episode_types.py today"] ID["EpisodeId and TaskId"] REQ["Environment server request and response types"] end F["failure_kinds.py"] --> F2["core/failure_kinds.py"] T --> T2["core/responses_api_types.py"] E --> E2["core/episode.py"] ID --> E2 CL --> CL2["openai_utils.py<br/>moves to model/ later"] MW --> MW2["rollout_correlation.py<br/>moves to server_runtime/ later"] REQ --> REQ2["episode_types.py<br/>moves to server_runtime/ in #5214,<br/>then to core/ in #5536"] classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937 class F2,T2,E2 thisThe two large parts are git renames, so history follows them:
openai_utils.pybecomescore/responses_api_types.pyandrollout_correlation.pybecomescore/episode.py. The parts that stay behind are recreated at the old paths.What stays importable from the old paths
flowchart LR O["from nemo_gym.openai_utils import X"] --> Q{"X is the client?"} Q -->|"yes"| C["Defined there"] Q -->|"no: a Gym type, or an openai or pydantic name it imported"| W["Warn once, return X from<br/>nemo_gym.core.responses_api_types"] classDef this fill:#fde68a,stroke:#b45309,stroke-width:2px,color:#1f2937 class W thisopenai_utils.pydefined or imported from outside the standard library resolves at the old path, including OpenAI SDK types such asReasoningthat code imported through it.rollout_correlation.pyandepisode_types.pydo the same for the names that left them.How to review
One commit. Its changes:
Renames, with no content changes.
Everything else:
openai_utils.py, the middleware into a newrollout_correlation.py.EpisodeId,TaskId, and_CAPTURE_KEY_ATTEMPTmove fromepisode_types.pyintocore/episode.py.core/episode.pyimports four config key names insidemaybe_rollout_id_from_run_body, its only user. At module level that import would close a cycle:global_configimports feature modules that importepisode_types, which now importscore/episode.py.nemo_gym/_moved_paths.py, which gains a small helper for listing many names at once.scripts/migrate_imports.py.nemo_gym/__init__.py, a lazy-import map inbase_responses_api_model.pyand its test, a test that read three type aliases through theopenai_utilsmodule object, the contract's core layer (now thenemo_gym.corepackage, with the middleware module moved to the server runtime group), and a redirect infern/docs.ymlfor the movedfailure_kindslibrary reference page.Tests move into
tests/unit_tests/core/, split the same way as the code:test_failure_kinds.pymoves whole;test_openai_utils.pybecomescore/test_responses_api_types.py, and its client tests, with the fixture that pins their retry jitter, stay intest_openai_utils.py;EpisodeIdandTaskIdtests move fromtest_episode_types.pyintocore/test_episode.py;test_rollout_correlation.pystays: it checks rollout IDs end to end through the servers, and moves withserver_runtime/.No test is added or dropped: each split file pair holds exactly the tests of the original.
Record the names the old modules still import.
rollout_correlation.pystill importsROLLOUT_ID_PATTERNandrollout_context, andepisode_types.pystill importsEpisodeIdandTaskId, so those names resolved at the old paths without an entry. Recording them inMOVED_NAMESlets the import rewriter move in-repo imports tonemo_gym.core.episodeand tracks their removal like every other moved name.History of split files
The repository squash-merges, so this PR lands as one commit. Whole-module moves still show as renames. A split file does not: its old path stays with less in it, so the new file starts its own history.
git blame -C -C <new file>follows the moved lines back to the old file, andgit log --followdoes not.Public API
Every layout package that exists after this PR has a lazy public API in its
__init__.py: the names non-test code outsidenemo_gym/imports from it (servers, benchmarks, scripts, and code samples in docs and skills), each served from the submodule that defines it on first use. Code outsidenemo_gym/and its tests (servers and their tests, benchmarks, scripts, and docs) imports those names fromnemo_gym.<package>, so later moves inside a package leave it alone. Code insidenemo_gym/, and the library's tests undertests/, import from the module that defines each name, so the import-linter contract sees every dependency and a test reads what it patches. A patch target names the module the code under test looks the name up in.AGENTS.mdstates the rule.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 every moved path and name so far: same result.lint-imports, with 19 exceptions now: the Responses API types no longer point up the order.gym env testforresponses_api_models/openai_model,responses_api_models/vllm_model,responses_api_agents/simple_agent,resources_servers/example_single_tool_call, andenvironment_servers/harbor.pre-commit run --all-files.Rollout evidence: N/A. The code moves unchanged.
Compatibility
nemo_gym.rollout_correlation.ROLLOUT_ID_PATTERNornemo_gym.openai_utils.RESPONSES_TO_TRAIN, no longer reaches the code that uses it. Patch the new module; mutating the shared object in place still works.from nemo_gym.openai_utils import *now yields only the namesopenai_utilsstill defines or imports, without the moved types such asNeMoGymResponse.failure_kindsnow logs undernemo_gym.core.failure_kinds.python scripts/migrate_imports.py <paths>.Issue
Part of #5166.