Skip to content

refactor(models): rename token ID capture to token capture - #5533

Open
ananthsub wants to merge 1 commit into
ananthsub/renamed-config-keysfrom
ananthsub/token-capture-rename
Open

ananthsub wants to merge 1 commit into
ananthsub/renamed-config-keysfrom
ananthsub/token-capture-rename

Conversation

@ananthsub

@ananthsub ananthsub commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #5628, which adds the renamed-key mechanism; its base is ananthsub/renamed-config-keys, and it lands after #5628. Part of the nemo_gym/ reorganization tracked in #5166.

What changed and why

#5225 renamed the token capture package and its classes, but kept the config keys, a field on each server config, and many messages spelled token_id_capture. That left one feature with two names. This PR renames the rest to "token capture", and keeps every old name working until nemo_gym 0.10.0.

Old New Where
token_id_capture token_capture Run-wide config block, TokenCaptureConfig field, and TOKEN_CAPTURE_BLOCK's value
token_id_capture token_capture Agent opt-in flag on BaseResponsesAPIAgentConfig
token_id_capture_non_generating_requests token_capture_non_generating_requests Model server config field
_token_id_capture_enabled _token_capture_enabled Private agent helper; renamed without an alias

Configs under benchmarks/ and responses_api_agents/, the current docs, and the tests use the new names. The frozen fern/versions/v* pages are unchanged. The external agent harnesses guide gains a note about the old names.

Compatibility

Config keys

#5628 adds nemo_gym/config/renamed_keys.py, which moves each old key to its new name. This PR registers the token capture keys there: the run-wide block in RENAMED_TOP_LEVEL_KEYS, and the agent flag and model declarations in RENAMED_SERVER_INSTANCE_KEYS. Two places use them:

  • The config parser. After every merge, GlobalConfigDictParser.parse (through feat(config): accept renamed config keys and arguments under their old names #5628's rename step) renames the run-wide block, each agent instance's flag, and each model instance's declarations. This covers YAML configs, Hydra command line overrides, held agent overrides, and a framework's initial_global_config_dict (NeMo RL sets token_id_capture there). Server processes get the parsed config, so code that reads the config dict directly sees only the new keys.
  • The Pydantic configs. TokenCaptureConfig, BaseResponsesAPIAgentConfig, and BaseResponsesAPIModelConfig accept the old keys when they are built directly. This matters most for TokenCaptureConfig, which ignores extra keys: without this, a block under its old name would silently turn capture off. token_capture_enabled_for_agent also reads an agent flag under its old key, for frameworks that pass it an unparsed dict.

Each moved key emits a DeprecationWarning and logs a warning. Both name the new key and its full config path, for example Config key 'policy_model.responses_api_models.vllm_model.token_id_capture_non_generating_requests' was renamed 'policy_model.responses_api_models.vllm_model.token_capture_non_generating_requests'. The log line is there because Python hides DeprecationWarning outside __main__, so a config author would not otherwise see it. The parser renames each config source before merging them, so when an old key and its new key come from different sources (say a config file and the command line), the usual precedence decides. If one source sets both to the same value, the config loads and still warns. If one source sets them to different values, loading fails with ConflictingRenamedKeyError, which names both paths and says which one to remove.

Saved and exported configs

Secret masking in saved and exported configs (hide_secrets_in_container) treats any key containing token as a secret, but keeps the root token capture block's settings visible. It recognized only token_id_capture, so after the rename it would have masked the whole token_capture block, including enabled and sink. It now recognizes the block under either key. Its secret-shaped children are still masked.

Python names

The old field names stay readable as deprecated, read-only attributes on the three config classes, and each read warns. TokenIdCaptureConfig, TokenIdCaptureSettings, token_id_capture_enabled_for_agent, token_id_capture_dirs_from_config, TOKEN_ID_CAPTURE_BLOCK, and the nemo_gym.token_id_capture module paths already resolve through nemo_gym/_moved_paths.py from #5225. This PR does not touch _moved_paths.py or import_surface.json, so it cannot conflict with the other renames that edit them.

TOKEN_CAPTURE_BLOCK (and its old alias TOKEN_ID_CAPTURE_BLOCK) now holds "token_capture". Code that writes a config with this constant writes the new key. Code that hard-codes the string "token_id_capture" still works and gets the warning.

Data keys

No rollout output key changes. Rollout rows already use _ng_token_capture. nemo_gym_token_id_captures was only an example capture directory in docs, and it is now nemo_gym_token_captures. Neither NeMo RL (checked at acbf7ef) nor the rest of the repo reads a token capture output key under the old name.

One stored format does depend on these keys: the config digest in a run's resume manifest. The digest covers server settings and the capture block, so renaming the keys would have changed it and refused --resume for every run saved before the upgrade. The resume identity still spells these keys the old way, so a config with the new keys gives the same digest that the code before this change gave for the old keys.

For NeMo RL

Nothing breaks. When NeMo RL moves to the new key, rollout_checkpoint.py should also exclude env.**.token_capture from its identity, alongside env.**.token_id_capture.

Validation

  • pre-commit run on every touched file passes.
  • Touched core unit tests, tests/unit_tests/test_moved_paths.py, tests/unit_tests/config/test_global_config.py, and the import-linter coverage test pass: pytest -n 16 <touched test files> tests/unit_tests/test_moved_paths.py tests/unit_tests/config/test_global_config.py tests/unit_tests/test_import_linter_coverage.py.
  • tests/unit_tests/test_public_api_facades.py passes after rebasing onto main.
  • lint-imports keeps its contract.
  • Secret masking tests check the block's settings stay visible under both keys. Without the masking fix, they and the live export tests that read the saved config fail.
  • The edited tests in vllm_model, claude_code_agent, anyterminal_agent, opencode_agent, and opencode_sandboxed_agent pass after the rebase. The other edited server tests are left to CI.

New tests check that:

  • an initial config, a YAML config, and a command line override that use the old keys parse to the same config as the new keys;
  • a command line override under the old key still overrides an old key in a config file;
  • conflicting old and new values in one source fail for the block, the agent flag, and the model declarations, while equal values load;
  • a new key in a higher-precedence source overrides an old key in a lower one;
  • each Pydantic config accepts its old key and still serves its old attribute, with a warning;
  • token_capture_enabled_for_agent honors an old agent flag in an unparsed dict;
  • for both spellings, the resume digest equals the one the code before this change computed.

Each compatibility path was checked by removing its shim and rerunning its tests. All removals made their tests fail: each of the three key registrations, the three validators, the three deprecated attributes, the raw agent flag read, and the two parts of the resume identity spelling. The pinned digest came from running the code before this change on the old-key config.

Rollout evidence

One real smoke rollout per spelling: example_single_tool_call with simple_agent against Qwen2.5-0.5B-Instruct, served by vLLM 0.29.0 (Gym's pin). Five tasks, temperature 0, concurrency 1, return_token_id_information: true. Each config sets the run-wide block (enabled, dir, delta_records), the agent opt-in (not all_agents, so capture depended on the renamed agent flag), and a model server declaration. One config uses the old keys and the other the new ones.

Old keys New keys
Rename warnings logged 3 (block, agent flag, model declarations) 0
Masked rollouts / capture errors 0 / 0 0 / 0
Capture snapshots frozen, rebuilt, and retired 5 5
Resolved config token_capture keys token_capture keys
Resume manifest digest 2aa1522b… 2aa1522b…

On every task, the rebuilt responses' prompt_token_ids, generation_token_ids, and generation_log_probs are identical between the two runs: one task with two model calls and four with one, 172 to 232 prompt tokens per call. An earlier pair at the default concurrency matched on every token ID, but log probabilities differed on two tasks, which fits vLLM batching noise. The serial runs above remove that variable.

@ananthsub ananthsub added area:model Model servers, inference providers, and model adapters area:config Hydra configuration, schemas, composition, and compatibility labels Nov 3, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 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.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

@ananthsub
ananthsub force-pushed the ananthsub/token-capture-rename branch from 847367b to 40b850d Compare November 4, 2026 20:44
@ananthsub
ananthsub changed the base branch from main to ananthsub/renamed-config-keys November 4, 2026 20:44
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Nov 4, 2026
@ananthsub
ananthsub force-pushed the ananthsub/renamed-config-keys branch from 7f1cdc1 to 2b971d4 Compare November 4, 2026 22:42
@ananthsub
ananthsub force-pushed the ananthsub/token-capture-rename branch from 40b850d to d4286e3 Compare November 4, 2026 23:06
@ananthsub
ananthsub force-pushed the ananthsub/renamed-config-keys branch from 2b971d4 to 8db168e Compare November 5, 2026 06:15
The token capture package and its classes were renamed, but the config
keys, a field on each server config, and several messages still said
token_id_capture. Rename the rest so one name covers the feature.

- The run-wide block token_id_capture is now token_capture, the agent
  flag token_id_capture is now token_capture, and the model server's
  token_id_capture_non_generating_requests is now
  token_capture_non_generating_requests.
- Old keys keep working until nemo_gym 0.10.0. The config parser moves
  each old key to its new name wherever it came from (a config file,
  the command line, or a framework's initial config), and the Pydantic
  configs accept the old names when built directly. Each moved key
  logs a warning and emits a DeprecationWarning that names the new key.
  Setting an old key and its new key to different values is an error.
- The old field names stay readable as deprecated attributes on
  TokenCaptureConfig and on the agent and model server configs.
- The resume identity of a run still spells these keys the old way, so
  a run saved before the rename resumes after it.
- Saved and exported configs keep the token capture block's settings
  visible under either key; secret masking no longer hides the block
  because its new name contains "token".
- The private agent helper _token_id_capture_enabled is now
  _token_capture_enabled.
- Configs, docs, and tests use the new names.

Signed-off-by: Ananth Subramaniam <[email protected]>
@ananthsub
ananthsub force-pushed the ananthsub/token-capture-rename branch from d4286e3 to dfa989e Compare November 5, 2026 06:17
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 6, 2026 22:07
@svcnvidia-nemo-ci svcnvidia-nemo-ci added support User questions, support, or maintenance requests blocked Work cannot move forward until an external dependency is cleared labels Nov 7, 2026

This branch was previously deployed

1 inactive deployment
public — dfa989ea Deployed Nov 5, 2026 by copy-pr-bot[bot] via release / finalize / notify #10258
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 area:model Model servers, inference providers, and model adapters blocked Work cannot move forward until an external dependency is cleared sla:triage-overdue Review assignment is over the one-business-day SLA support User questions, support, or maintenance requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants