Skip to content

refactor(models): move the model clients, converters and token capture into nemo_gym/models - #5224

Merged
ananthsub merged 1 commit into
mainfrom
ananthsub/layout-model
Nov 2, 2026
Merged

ananthsub merged 1 commit into
mainfrom
ananthsub/layout-model

Conversation

@ananthsub

@ananthsub ananthsub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Moves the model clients, converters, and streaming helpers, and token ID capture, into nemo_gym/models/, the package that #5214 started with the checkpoint model-server modules. base_responses_api_model.py moves in the next PR, where its model call capture is split out.

The token capture classes, the config block constant and the module-level helpers follow the new package name: token_id_capture becomes token_capture in those Python names. Config keys, pydantic field names and messages keep token_id_capture, as #5166 promises, so configs and NeMo RL recipes do not change. The old Python names keep resolving until 0.10.0, with a warning.

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 model 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 model this
  class config,utils,core,telemetry,client,trajectory,verification,metrics,artifacts,server_runtime done
  class cli,eval,environment,testing,orchestration,rollouts,data,agents,sandbox 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

Whole modules, unchanged:

Old path New path
nemo_gym/openai_utils.py nemo_gym/models/openai_utils.py
nemo_gym/anthropic_utils.py nemo_gym/models/anthropic_utils.py
nemo_gym/anthropic_converter.py nemo_gym/models/anthropic_converter.py
nemo_gym/responses_converter.py nemo_gym/models/chat_completions_converter.py
nemo_gym/chat_streaming.py nemo_gym/models/chat_streaming.py
nemo_gym/responses_streaming.py nemo_gym/models/responses_streaming.py
nemo_gym/token_id_capture/ nemo_gym/models/token_capture/

Names follow the package

Before After
TokenIdCaptureConfig, TokenIdCaptureSettings TokenCaptureConfig, TokenCaptureSettings
TOKEN_ID_CAPTURE_BLOCK (value "token_id_capture", unchanged) TOKEN_CAPTURE_BLOCK
token_id_capture_config, token_id_capture_enabled_for_agent, token_id_capture_dirs_from_config token_capture_config, token_capture_enabled_for_agent, token_capture_dirs_from_config

Unchanged: the token_id_capture config block, the per-server token_id_capture flag, the model server's token_id_capture_non_generating_requests key, the pydantic fields and attributes of the same names, and every message that names those keys.

Each old name resolves at every old module path that defined or imported it, through MOVED_NAMES in nemo_gym/_moved_paths.py, with a warning. A package's public API also serves names that moved out of it, so from nemo_gym.config import TOKEN_ID_CAPTURE_BLOCK keeps working. The recorded import surface checks every old name.

How to review

One commit. Its changes:

  1. Renames, with no content changes.
  2. Everything else:
    • The moves are recorded in MOVED_MODULES in nemo_gym/_moved_paths.py.
    • In-repo references are rewritten by scripts/migrate_imports.py.
    • The contract's models layer becomes the nemo_gym.models package.
    • fern/docs.yml redirects the old library reference pages to the new ones, including every token_id_capture submodule page.
    • openai_utils.py still serves the Responses API types refactor(core): move shared definitions into nemo_gym/core #5203 moved to core/; those names keep resolving at both of its paths.
    • The renames in the table above, across the library, servers and docs, and the old names described there.
    • nemo_gym/_public_api.py: a package's public API falls back to MOVED_NAMES for a name it no longer exports, so an old name imported through a package resolves with a warning.
    • tests/unit_tests/server_runtime/test_mcp_auto_exposure.py imported four names through nemo_gym.server_utils, which refactor(server_runtime): split server_utils into the server runtime package #5215 left alone because a comment sat inside the parenthesized import; it now imports them from their defining modules.
    • A test's assertion message names chat_completions_converter.py, the converter's new file name.
    • By hand: the NeMoGymAsyncOpenAI lazy export, the secrets scan's exclusion of the staging golden vectors, which still named the old directory, the golden-vectors package-data pattern in pyproject.toml (written relative to the nemo_gym package, so the rewriter's path pass does not see it; the package-data test catches it), and the contract's model layer, which is nemo_gym.models next to base_responses_api_model until that module moves.
  3. Tests: the client, converter, and token capture tests move into tests/unit_tests/models/. test_responses_converter.py becomes test_chat_completions_converter.py with its module, and test_token_id_capture.py becomes test_token_capture.py. New tests check that every old name resolves at every old path to its renamed object with a warning, including through a package's public API, and that the config key and field names keep their spelling. They pass in any order and with the moved-path warnings turned into errors.

Public API

Every layout package that exists after this PR has a lazy public API in its __init__.py: the names code outside nemo_gym/ imports from it (servers and their tests, benchmarks, scripts, and code samples in docs and skills), plus every name it already exported, each served from the submodule that defines it on first use. Code outside nemo_gym/ and its tests (servers and their tests, benchmarks, scripts, and docs) imports those names from nemo_gym.<package>, so later moves inside a package leave it alone. Code inside nemo_gym/, and the library's tests under tests/, 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.md states the rule.

Validation

  • pytest -n 16 tests/unit_tests, also with -W error for the moved paths. The only failures are environment-specific and unrelated to the move: this machine's hostname resolves to 127.0.1.1, which the sandbox host check refuses (the Harbor run summary tests and the benchmark listing test), and two Docker PTY tests.
  • The public API test fails without the public API's fallback to MOVED_NAMES.
  • lint-imports.
  • pre-commit run on the changed files.
  • Server and agent tests run in CI.

Rollout evidence: N/A. The modules move unchanged, and the renamed Python names keep resolving at their old paths.

Compatibility

  • Old paths work until 0.10.0, with one warning each, and give the same module objects.
  • The old Python names work until 0.10.0, with a warning; see above. Config keys do not change.
  • Logger names follow the module path, so these modules now log under nemo_gym.models.*. A logging config set 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 20:54
@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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added area:model Model servers, inference providers, and model adapters feature New capabilities, enhancements, or enablement work labels Oct 28, 2026

Copy link
Copy Markdown
Contributor

Something went wrong on our side and the automatic retries didn't recover — please try again. (ref: github:ba9be640-d311-11f1-8fe6-f969413e0f1f)

@ananthsub
ananthsub force-pushed the ananthsub/layout-model branch from 5cb4839 to 230d80f Compare October 28, 2026 21:24
@ananthsub ananthsub changed the title ananthsub/layout model refactor(model): move the model clients, converters and token capture into nemo_gym/model Oct 28, 2026
@ananthsub
ananthsub requested a review from yaoyu-33 October 28, 2026 21:27
@ananthsub ananthsub added area:core Shared APIs, servers, telemetry, health, and registries needs-review PR is ready for code review and waiting on a reviewer labels Oct 28, 2026
@ananthsub
ananthsub marked this pull request as ready for review October 28, 2026 21:27
@ananthsub
ananthsub requested a review from a team as a code owner October 28, 2026 21:27
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 28, 2026 21:27
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

@ananthsub
ananthsub force-pushed the ananthsub/layout-model branch from 230d80f to eb762f0 Compare October 28, 2026 21:56
@ananthsub ananthsub changed the title refactor(model): move the model clients, converters and token capture into nemo_gym/model refactor(models): move the model clients, converters and token capture into nemo_gym/models Oct 28, 2026
@ananthsub
ananthsub force-pushed the ananthsub/layout-model branch from 5354c31 to fdece53 Compare October 29, 2026 14:19
@ananthsub
ananthsub force-pushed the ananthsub/layout-model branch from fdece53 to 04aa4d6 Compare October 29, 2026 15:14
@ananthsub
ananthsub force-pushed the ananthsub/layout-model branch from 04aa4d6 to 6011d8d Compare October 29, 2026 15:51
@ananthsub
ananthsub removed this pull request from stack #5170 October 29, 2026 15:55
@ananthsub
ananthsub added this pull request to stack #5319 October 29, 2026 15:56

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

Verdict: SHIP WITH CARE. Reviewed at 704bed5405a7 (base 250da81e). There are no blockers, 1 risk and 8 notes inline, plus one process question below.

The package move itself is clean. All 55 renamed files are identical to the base apart from imports. Every rewritten import resolves to the same object as before, and every old module path, including each token_id_capture submodule, still resolves with one warning. importlib.resources still reads the golden vectors through the old path and from a built wheel. Thanks for the careful layering and the redirect work.

Two notes are small leftovers from the move: the docs redirects and one assertion message. The rest come from the token_id_capture → token_capture rename that the latest push added. The loader rewrites old config keys, and the module-level names are served through MOVED_NAMES. The gaps are what sits around those two paths:

  • old attribute names (RISK);
  • raw dict readers;
  • interpolations;
  • the nemo_gym.config facade.

Resolved since the earlier head: .secrets.baseline now excludes the new golden_vectors.json path, and secrets-detector passes.

Process: the rename's scope. #5166 says config keys, CLI commands, server configs and output files "do not change". This push renames config keys and public pydantic fields, and adds a config rewrite layer. That also grows the PR from 129 to 187 files. Would you consider landing the move here and the identifier and config-key rename in its own PR, with NeMo RL coordinated? Otherwise, could #5166's compatibility list be amended to cover the rename? A cheaper middle ground would keep the config keys and rename only the Python identifiers through MOVED_NAMES. That would remove most of the inline notes.

Cross-PR and cross-repo items (not for this PR)
  • NeMo RL, for its migration PR (checked at RL 6e68b179):
    • tests/unit/environments/test_nemo_gym_utils.py:456 reads TokenIdCaptureConfig.model_validate(...).token_id_capture, which now raises AttributeError (see the inline risk).
    • nemo_rl/algorithms/single_controller_utils/rollout_checkpoint.py:123 leaves only env.**.token_id_capture out of the resume fingerprint, so a recipe migrated to token_capture changes it.
    • nemo_rl/environments/nemo_gym.py:1040 still injects initial_global_config_dict["token_id_capture"], and :1049 still names nemo_gym.token_id_capture.lineage:FileLineageStore. Both work, with a warning on every run. A user who also sets token_capture in the same initial dict gets the loader's "both set" ConfigError.
  • tau2: responses_api_agents/tau2/requirements.txt pins the tau2 fork by branch (bxyu/nemo_gym_stable). Its src/tau2/utils/llm_utils.py:43 imports nemo_gym.openai_utils, which works through the alias now and breaks at 0.10.0. It could go on the #5166 checklist.
  • #5215: tests/unit_tests/server_runtime/test_mcp_auto_exposure.py:62 imports nemo_gym.server_utils, so that file fails to collect under -W 'error:nemo_gym.:DeprecationWarning'`. The same happens at the base.
Validation
  • CI at 704bed54: green. The only failure is the non-blocking kilocode harness-conformance job, which fails the same way on the base.
  • Unit suite, run locally: no failures caused by this PR. The failing IDs are environment-specific and fail the same way on the base tree. With -W 'error:nemo_gym.:DeprecationWarning'`, the only new failure is the inline test note.
  • lint-imports: kept. The packaging and moved-path tests pass.
  • Moved test IDs: 1143 at the base and 1143 at the head, all present.
  • Token capture: golden_vectors.json is byte-identical, and the recomputed digests match the base. Record fields, route paths, digest domains and env var names are unchanged.
  • Mutation checks: the claims hold that the new compat tests fail with the config rewrite turned off and with the field aliases removed.
  • Sandbox runner fallbacks: checked in both directions against old and new bundles. All touched servers install nemo-gym from the local checkout.
  • Not verified: GPU paths and real sandboxes.

Comment thread nemo_gym/models/token_capture/config.py Resolved
Comment thread nemo_gym/models/token_capture/config.py Resolved
Comment thread nemo_gym/config/global_config.py Resolved
Comment thread nemo_gym/config/__init__.py Resolved
Comment thread fern/docs.yml Resolved
@ananthsub

Copy link
Copy Markdown
Contributor Author

Thanks for the review. On the scope question, I took the middle ground you suggested: this PR now renames only the Python names (TokenIdCaptureConfig, TokenIdCaptureSettings, TOKEN_ID_CAPTURE_BLOCK and the three module-level helpers). Config keys, pydantic field names and messages keep token_id_capture, as #5166 promises. The config rewrite layer and the field aliases are gone, and the old Python names resolve at their old paths through MOVED_NAMES. The description is updated to match.

On the cross-repository items:

  • NeMo RL: with the keys and fields unchanged, test_nemo_gym_utils.py:456 reading .token_id_capture works again, the resume fingerprint's env.**.token_id_capture entry still matches, and nemo_gym.py injecting the token_id_capture block runs without a warning. Its nemo_gym.token_id_capture.lineage:FileLineageStore string still loads through the old module path, with the module's deprecation warning, until 0.10.0.
  • refactor(server_runtime): split server_utils into the server runtime package #5215's test_mcp_auto_exposure.py: the rewriter left its parenthesized nemo_gym.server_utils import alone because of the comment inside it. The next push of this PR imports the four names from their defining modules, and the file passes with nemo_gym deprecation warnings turned into errors.
  • tau2: agreed, the pinned fork's nemo_gym.openai_utils import needs updating before 0.10.0; it belongs on Reorganize nemo_gym into layered packages with per-package reviewer groups #5166's checklist.

…e into nemo_gym/models

openai_utils.py, anthropic_utils.py, anthropic_converter.py,
chat_streaming.py and responses_streaming.py move as they are,
responses_converter.py becomes models/chat_completions_converter.py, and
the token_id_capture package becomes models/token_capture.

The Python names follow the package: TokenIdCaptureConfig,
TokenIdCaptureSettings, TOKEN_ID_CAPTURE_BLOCK, token_id_capture_config,
token_id_capture_enabled_for_agent and token_id_capture_dirs_from_config
become their token_capture spellings. The old names resolve at every old
module path that defined or imported them, through MOVED_NAMES, with a
warning, until 0.10.0. Config keys, pydantic field names and messages
keep the token_id_capture spelling, so configs do not change.

Record the seven moves in MOVED_MODULES (token_id_capture as a package),
rewrite in-repo references with scripts/migrate_imports.py, point the
NeMoGymAsyncOpenAI lazy export, the golden-vectors package-data pattern
and the secrets scan exclusion at the new paths, make the contract's
model layer the nemo_gym.models package next to base_responses_api_model
until that module moves, and redirect the old library reference pages,
including each token_id_capture submodule page, in fern/docs.yml.

Regenerate the public API of each layout package that exists here from
what code outside the library imports. Code outside nemo_gym and its
tests imports from nemo_gym.<package>; the library's tests import from
the module that defines each name.

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

This branch was previously deployed

1 inactive deployment
public — 5985d0a5 Deployed Nov 2, 2026 by copy-pr-bot[bot] via release / finalize / notify #9312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Shared APIs, servers, telemetry, health, and registries area:model Model servers, inference providers, and model adapters feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants