Skip to content

fix(ns_tools): apply the generic/math prompt in prepare_dataset.py - #5335

Merged
weijiac0619 merged 3 commits into
mainfrom
qiaochuz/nvb-6847514-ns-tools-transformers
Nov 2, 2026
Merged

weijiac0619 merged 3 commits into
mainfrom
qiaochuz/nvb-6847514-ns-tools-transformers

Conversation

@qiaochuz-nv

Copy link
Copy Markdown
Contributor

What does this PR do?

The ns_tools README command that regenerates the comp-math data now runs and writes the generic/math prompt into
every row. Before this change it either failed at import (No module named 'transformers') or, with transformers
installed, logged a warning per row and silently wrote the raw problem with no prompt.

Fixes NVBug 6847514. Fixes #4520. Linear GYM-1045.

Cause

prepare_dataset.py read its prompt with nemo_skills.prompt.utils.load_config. Since #1078 (c7ab4eac8) the server
installs the nemo-skills-tools subpackage instead of the full nemo-skills package, and that subpackage has neither
of the two things this script relied on:

  • nemo_skills/prompt/utils.py:25 imports transformers.AutoTokenizer at module scope, but tools/requirements.txt
    does not declare transformers (the full package's core/requirements.txt does).
  • tools/pyproject.toml builds the wheel from .. with include-package-data = true but has no MANIFEST.in, so no
    prompt YAMLs are shipped (the full package ships them through the root MANIFEST.in). This is the same at the pinned
    da85a881 and on Skills main, so bumping the pin does not help.

prepare_dataset.py:201-203 caught every exception from loading the prompt, logged a warning and returned the problem
unchanged.

Fix

  • Copy Skills' nemo_skills/prompt/config/generic/math.yaml (unchanged below a provenance header) to
    resources_servers/ns_tools/prompts/generic/math.yaml, as physics_judge and ugphysics_judge do for their Skills
    judge prompts.
  • Load it with Gym's own nemo_gym.prompt.load_prompt_config. That removes the nemo_skills.prompt.utils import, so
    transformers is not needed at all; the server venv stays as it is.
  • Load the prompt once, before any output is written, and let a missing or malformed config fail the run. A path
    ending in .yaml still selects another prompt.
  • README: name the shipped file (data/compmath_test.jsonl; compmath_prepared.jsonl does not exist) and the server
    venv the script needs.

Not chosen: adding transformers to requirements.txt fixes only the import, still leaves the YAMLs missing, and adds
a large dependency only to read one YAML file. Fixing the Skills packaging upstream is still worth doing, but this
server cannot wait on a Skills release to work.

Before the fix

Gym 99594f29e (main), venv built from resources_servers/ns_tools/requirements.txt, source
comp-math-24-25/test.txt from Skills da85a881 (256 rows):

resources_servers/ns_tools/.venv/bin/python resources_servers/ns_tools/prepare_dataset.py \
    --input /path/to/nemo_skills/dataset/comp-math-24-25/test.txt \
    --output resources_servers/ns_tools/data/compmath_test.jsonl \
    --prompt_config generic/math \
    --tools nemo_skills.mcp.servers.python_tool::DirectPythonTool \
    --verifier_type math_with_judge
Traceback (most recent call last):
  File "resources_servers/ns_tools/prepare_dataset.py", line 47, in <module>
    from nemo_skills.prompt.utils import load_config
  File ".venv/lib/python3.13/site-packages/nemo_skills/prompt/utils.py", line 25, in <module>
    from transformers import AutoTokenizer
ModuleNotFoundError: No module named 'transformers'

Same command after uv pip install transformers (exit 0, but 256 warnings and no prompt in any row):

INFO - Prompt config: generic/math
WARNING - Could not load prompt config 'generic/math': [Errno 2] No such file or directory: '.venv/lib/python3.13/site-packages/nemo_skills/prompt/config/generic/math.yaml'. Using raw problem.
...
INFO - Processed 256 samples -> resources_servers/ns_tools/data/compmath_test.jsonl

First row's user message: 'Find the sum of all integer bases $b>9$ for which $17_b$ ...'

After the fix

Gym dd93030a7 (this branch), same venv (no transformers), same command:

INFO - Prompt config: generic/math
INFO - Loaded 1 tools: ['stateful_python_code_exec']
INFO - No system prompt in config
INFO - Processed 256 samples -> resources_servers/ns_tools/data/compmath_test.jsonl

First row's user message: 'Solve the following math problem. Make sure to put the answer (and only answer) inside \\boxed{}.\n\nFind the sum of all integer bases ...'

All 256 rows equal the shipped data/compmath_test.jsonl except the tool description: the shipped rows say the
Python tool times out after 120 s, while the pinned DirectPythonTool and configs/ns_tools.yaml
(exec_timeout_s: 10) give 10 s. Both values date from #571; this PR does not change either.

Validation

  • QA testcase ns_tools, case "README preparation preserves all 256 original comp-math tasks using pinned Skills tools"
    (run with the server venv that gym env test --resources-server ns_tools builds): before (5911d628c) FAIL at
    "original preparation CLI runs" (ModuleNotFoundError: transformers), after PASS (256/256 rows, generic/math
    prompt applied). Neither the script nor nemo_gym/prompt.py changed between 5911d628c and 99594f29e; the
    README command above was rerun on both.
  • resources_servers/ns_tools/tests in a venv built from requirements.txt (no transformers): 23 passed (20 existing,
    3 new). The new tests run the README command and compare with the shipped rows, check that a missing prompt config
    fails before any output is written, and check that a .yaml path is used as given. On main the first two fail in
    the same venv with transformers added (raw problem; exit 0 on a missing config).
  • pre-commit run --all-files: passed.
  • Rollout evidence: N/A. This changes offline data preparation only; the server, agent and verifier are unchanged.

Compatibility

  • --prompt_config names now resolve under resources_servers/ns_tools/prompts/ (only generic/math is shipped).
    Other Skills names, such as llama3-instruct/math, never loaded with the pinned package either; pass a .yaml path
    for them.
  • A missing or malformed prompt config now stops the script with an error instead of writing raw problems.
  • No new dependencies.

🤖 Generated with Claude Code

@qiaochuz-nv qiaochuz-nv added bug Something isn't working QA_fix Fix implemented by a QA team member area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers needs-review PR is ready for code review and waiting on a reviewer complexity:low Localized change in one scope with a small, straightforward review surface labels Oct 29, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@qiaochuz-nv
qiaochuz-nv requested a review from yaoyu-33 October 29, 2026 21:57
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test dd93030

@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 — no correctness concerns found; one non-blocking provenance NOTE.

Reviewed all four changed files and traced prompt loading, prepared-row contracts, downstream verification, and component-test integration. The preparation script applies the shipped template without importing Skills’ prompt utilities, while missing or structurally malformed configs fail before output is opened.

Tests were inspected, not executed, in this read-only review.

Note: formal approval is not available for this request, so this review is posted as a comment only.

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

@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test f9a17da

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

Thanks for the thorough write-up and the before/after evidence. The fix does what it says. With the README command and the server venv (no transformers), all 256 comp-math rows come out equal to the shipped data/compmath_test.jsonl. The only difference is the tool timeout description, which the PR body already calls out. The vendored YAML body is byte-identical to Skills da85a881. All 23 ns_tools tests pass locally, and the 3 new ones fail on main as described.

There are two non-blocking notes inline. Both are on the custom-YAML route that the README now documents; the default generic/math path is unaffected:

  • A template error, such as an unknown placeholder or a stray brace, fails only after the output file has been truncated.
  • The system template is written without formatting, so Skills prompts that have a system message get doubled braces.

A possible follow-up, not for this PR: the shipped rows tell the model the Python tool times out after 120 s, but configs/ns_tools.yaml enforces 10 s.

qiaochuz-nv and others added 2 commits October 30, 2026 08:32
The README command for regenerating the comp-math data failed in two ways:

- It exited at import with `ModuleNotFoundError: No module named 'transformers'`.
  prepare_dataset.py used `nemo_skills.prompt.utils.load_config`, and that module
  imports transformers at module scope; neither requirements.txt nor
  nemo-skills-tools declares it.
- With transformers installed, it still could not load `generic/math`: the pinned
  nemo-skills-tools package (tools/pyproject.toml, no MANIFEST.in, same on Skills
  main) ships no prompt YAMLs. A broad `except` logged a warning per row and wrote
  the raw problem, so the data silently lost its prompt.

Load the prompt with Gym's own `nemo_gym.prompt.load_prompt_config` from a copy of
the Skills generic/math.yaml (da85a881, Apache-2.0) in prompts/, as physics_judge
does for its Skills judge prompt. That drops the transformers import entirely. Load
it once, before any output is written, and let a missing or malformed config fail
the run. A path ending in .yaml still selects another prompt.

The README now names the shipped file (data/compmath_test.jsonl, not
compmath_prepared.jsonl) and the server venv the script needs.

Fixes NVBug 6847514 (GitHub #4520).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
List resources_servers/ns_tools/prompts/generic/math.yaml in the vendored-components
inventory with its upstream revision and license, as CONTRIBUTING.md requires for
vendored third-party files. Addresses review feedback on this PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
yaoyu-33
yaoyu-33 previously approved these changes Oct 30, 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.

LGTM. The two inline notes are optional hardening for custom prompt YAMLs and can go in this PR or a follow-up.

@yaoyu-33 yaoyu-33 added ready-to-merge PR is approved, current, and waiting for final CI or merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Oct 30, 2026
…iting

Review feedback on the custom-YAML route the README documents:

- The system template was written unformatted, so a Skills prompt with a system
  message (for example qwen3/math-cot-think) wrote `\boxed{{}}` into every row.
  It is now filled with the same values as the user template, as Skills'
  Prompt.fill and Gym's fill_prompt do.
- A template that loads but cannot be filled (an unknown placeholder such as
  `{question}`, or a stray brace) failed on the first row, after the output file
  had been truncated. Both templates are now filled once before the output is
  opened, so the existing file is left as it was.

The README names the placeholders the templates can use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: qiaochuz <[email protected]>
@qiaochuz-nv
qiaochuz-nv force-pushed the qiaochuz/nvb-6847514-ns-tools-transformers branch from f9a17da to 5f8ad6b Compare October 30, 2026 15:49
@qiaochuz-nv

Copy link
Copy Markdown
Contributor Author

/ok to test 5f8ad6b

@github-actions

Copy link
Copy Markdown
Contributor

@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-reviewed at 5f8ad6b. Both notes are addressed:

  • build_input_messages fills system with the same values as user. A Skills prompt with a system message no longer writes \boxed{{}} into the rows.
  • main fills both templates once before it opens the output. A bad placeholder now fails without truncating the existing file, and test_template_error_fails_before_the_existing_output_is_truncated checks exactly that.

generic/math has no system message, so the 256 shipped rows are unchanged. CI is green except kilocode conformance probes, a non-blocking check that fails the same way on other PRs.

LGTM.

@weijiac0619
weijiac0619 added this pull request to the merge queue Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41495287481

Merged via the queue into main with commit e9cb5c3 Nov 2, 2026
55 of 58 checks passed
@weijiac0619
weijiac0619 deleted the qiaochuz/nvb-6847514-ns-tools-transformers branch November 2, 2026 18:38

This branch was previously deployed

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

Labels

area:environment Individual environments, benchmarks, verifiers, and environment-specific resources servers bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface QA_fix Fix implemented by a QA team member 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.

[NVBug 6847514] Declare transformers (and ship prompt YAMLs) so ns_tools prepare_dataset runs

4 participants