Skip to content

Add prompt config for templating - #861

Merged
bxyu-nvidia merged 7 commits into
mainfrom
georgea/prompt-config
Mar 11, 2026
Merged

bxyu-nvidia merged 7 commits into
mainfrom
georgea/prompt-config

Conversation

@gwarmstrong

Copy link
Copy Markdown
Contributor

Summary

Add YAML-based prompt templates that build responses_create_params.input on the fly during rollout collection or as a standalone materialization step. This enables you to sweep prompts without re-preparing JSONL data.

  • New module nemo_gym/prompt.py with PromptConfig (Pydantic-validated YAML schema), load_prompt_config (cached), fill_prompt, apply_prompt_to_row, validate_prompt_compatibility, and materialize_prompts
  • New CLI ng_materialize_prompts to bake prompts into JSONL offline
  • ng_collect_rollouts +prompt_config=<path> applies prompts at rollout time
  • Prompt configs are mutually exclusive with pre-baked responses_create_params.input — validated upfront across all rows before any work begins, with violating row indices reported
  • Relative paths resolve against PARENT_DIR (Gym root), consistent with config_paths resolution
  • Three example prompt configs in nemo_gym/prompt_configs/examples/ (minimal, math_cot, multi_field)

Usage

# Apply prompt at rollout time (no data re-preparation needed)
ng_collect_rollouts \
    +agent_name=my_agent \
    +input_jsonl_fpath=data/raw.jsonl \
    +output_jsonl_fpath=rollouts.jsonl \
    +prompt_config=nemo_gym/prompt_configs/examples/math_cot.yaml

# Or materialize prompts into JSONL for RL training
ng_materialize_prompts \
    +input_jsonl_fpath=data/raw.jsonl \
    +prompt_config=nemo_gym/prompt_configs/examples/math_cot.yaml \
    +output_jsonl_fpath=data/materialized.jsonl

Prompt YAML format

# system is optional
system: "Think step by step and put your final answer in \\boxed{{}}."
# user is required — {placeholders} are filled from data row fields
user: "{question}"

@gwarmstrong
gwarmstrong requested a review from a team as a code owner March 10, 2026 20:32
@copy-pr-bot

copy-pr-bot Bot commented Mar 10, 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.

@gwarmstrong
gwarmstrong force-pushed the georgea/prompt-config branch 2 times, most recently from 3e209fd to 6fa21a0 Compare March 10, 2026 20:47
Add YAML-based prompt templates that build responses_create_params.input
on the fly during rollout collection. Prompt templates are mutually
exclusive with pre-baked input values — validated upfront across all
rows with violating indices reported.

New module: nemo_gym/prompt.py
New CLI: ng_materialize_prompts
Integration: ng_collect_rollouts +prompt_config=<path>
Example configs in nemo_gym/prompt_configs/examples/
Relative paths resolve against PARENT_DIR, consistent with config_paths.
100% test coverage on nemo_gym/prompt.py.

Signed-off-by: George Armstrong <[email protected]>
@gwarmstrong
gwarmstrong force-pushed the georgea/prompt-config branch from 6fa21a0 to cc65cd1 Compare March 10, 2026 20:50
@gwarmstrong
gwarmstrong requested a review from bxyu-nvidia March 10, 2026 20:59

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.

can we avoid the example yamls here and instead turn this into a doc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the nemo_gym/prompt_configs/ directory entirely and added a new doc page at docs/data/prompt-config.md

Comment thread nemo_gym/rollout_collection.py Resolved
Comment thread pyproject.toml Outdated
ng_reinstall = "nemo_gym.cli:reinstall"

[tool.setuptools.package-data]
nemo_gym = ["prompt_configs/**/*.yaml"]

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.

after we remove the example yaml files, can we revert this pls

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@gwarmstrong
gwarmstrong requested a review from bxyu-nvidia March 11, 2026 23:27
Comment thread pyproject.toml Resolved
bxyu-nvidia
bxyu-nvidia previously approved these changes Mar 11, 2026
Signed-off-by: George Armstrong <[email protected]>
@bxyu-nvidia
bxyu-nvidia disabled auto-merge March 11, 2026 23:39
@bxyu-nvidia
bxyu-nvidia merged commit b9a50a5 into main Mar 11, 2026
5 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the georgea/prompt-config branch March 11, 2026 23:39
mahanfathi pushed a commit that referenced this pull request Mar 24, 2026
## Summary

Add YAML-based prompt templates that build
`responses_create_params.input` on the fly during rollout collection or
as a standalone materialization step. This enables you to sweep prompts
without re-preparing JSONL data.

- New module `nemo_gym/prompt.py` with `PromptConfig`
(Pydantic-validated YAML schema), `load_prompt_config` (cached),
`fill_prompt`, `apply_prompt_to_row`, `validate_prompt_compatibility`,
and `materialize_prompts`
- New CLI `ng_materialize_prompts` to bake prompts into JSONL offline
- `ng_collect_rollouts +prompt_config=<path>` applies prompts at rollout
time
- Prompt configs are mutually exclusive with pre-baked
`responses_create_params.input` — validated upfront across all rows
before any work begins, with violating row indices reported
- Relative paths resolve against `PARENT_DIR` (Gym root), consistent
with `config_paths` resolution
- Three example prompt configs in `nemo_gym/prompt_configs/examples/`
(minimal, math_cot, multi_field)


### Usage

```bash
# Apply prompt at rollout time (no data re-preparation needed)
ng_collect_rollouts \
    +agent_name=my_agent \
    +input_jsonl_fpath=data/raw.jsonl \
    +output_jsonl_fpath=rollouts.jsonl \
    +prompt_config=nemo_gym/prompt_configs/examples/math_cot.yaml

# Or materialize prompts into JSONL for RL training
ng_materialize_prompts \
    +input_jsonl_fpath=data/raw.jsonl \
    +prompt_config=nemo_gym/prompt_configs/examples/math_cot.yaml \
    +output_jsonl_fpath=data/materialized.jsonl
```

### Prompt YAML format

```yaml
# system is optional
system: "Think step by step and put your final answer in \\boxed{{}}."
# user is required — {placeholders} are filled from data row fields
user: "{question}"
```

---------

Signed-off-by: George Armstrong <[email protected]>
jsw-zorro pushed a commit to niletron/Gym that referenced this pull request Apr 7, 2026
## Summary

Add YAML-based prompt templates that build
`responses_create_params.input` on the fly during rollout collection or
as a standalone materialization step. This enables you to sweep prompts
without re-preparing JSONL data.

- New module `nemo_gym/prompt.py` with `PromptConfig`
(Pydantic-validated YAML schema), `load_prompt_config` (cached),
`fill_prompt`, `apply_prompt_to_row`, `validate_prompt_compatibility`,
and `materialize_prompts`
- New CLI `ng_materialize_prompts` to bake prompts into JSONL offline
- `ng_collect_rollouts +prompt_config=<path>` applies prompts at rollout
time
- Prompt configs are mutually exclusive with pre-baked
`responses_create_params.input` — validated upfront across all rows
before any work begins, with violating row indices reported
- Relative paths resolve against `PARENT_DIR` (Gym root), consistent
with `config_paths` resolution
- Three example prompt configs in `nemo_gym/prompt_configs/examples/`
(minimal, math_cot, multi_field)


### Usage

```bash
# Apply prompt at rollout time (no data re-preparation needed)
ng_collect_rollouts \
    +agent_name=my_agent \
    +input_jsonl_fpath=data/raw.jsonl \
    +output_jsonl_fpath=rollouts.jsonl \
    +prompt_config=nemo_gym/prompt_configs/examples/math_cot.yaml

# Or materialize prompts into JSONL for RL training
ng_materialize_prompts \
    +input_jsonl_fpath=data/raw.jsonl \
    +prompt_config=nemo_gym/prompt_configs/examples/math_cot.yaml \
    +output_jsonl_fpath=data/materialized.jsonl
```

### Prompt YAML format

```yaml
# system is optional
system: "Think step by step and put your final answer in \\boxed{{}}."
# user is required — {placeholders} are filled from data row fields
user: "{question}"
```

---------

Signed-off-by: George Armstrong <[email protected]>
khazic pushed a commit to khazic/Gym-lao that referenced this pull request Oct 13, 2026
…DIA-NeMo#4538)

## What does this PR do?

The `gym eval run` example in `resources_servers/ifbench/README.md` now
runs. It passed
`--prompt-config benchmarks/ifbench/prompts/default.yaml` together with
`--input resources_servers/ifbench/data/example.jsonl`, but every
example row already carries
`responses_create_params.input`. `validate_prompt_compatibility`
(`nemo_gym/prompt.py:76-86`)
rejects that combination on purpose, so the documented command failed on
all five rows before any
generation.

Fixes NVBug [6783016](https://nvbugspro.nvidia.com/bug/6783016) (Jira
NMGYM-57).

### Cause

`example.jsonl` is pre-rendered, and the README asked Gym to render the
prompt a second time. The
mismatch dates from NVIDIA-NeMo#999, which added IFBench with pre-rendered rows and
an `ng_collect_rollouts
+prompt_config=...` example after the validation (NVIDIA-NeMo#861) already existed.
NVIDIA-NeMo#1630 carried the flag
over into the `gym eval run` form.

### Fix

Remove `--prompt-config` (and the trailing `\` before it) from the
README command. The data and the
validation stay as they are:

- `example.jsonl` must keep `input`: it is the `type: example` dataset
of `ifbench_simple_agent`
(`resources_servers/ifbench/configs/ifbench.yaml`), which has no prompt
config.
- The model input does not change. For all five rows (ids 0, 79, 172,
260, 262) the shipped `input`
is exactly `[{"role": "user", "content": <prompt>}]`, which is what
`default.yaml`
  (`user: "{prompt}"`) renders.
- The `--benchmark ifbench` path is unaffected:
`benchmarks/ifbench/prepare.py` writes rows without
`input`, matching the `prompt_config` in
`benchmarks/ifbench/config.yaml`.

### Before the fix

Gym `eed77e195` (main), the README command against the README's `gym env
start --benchmark ifbench --model-type openai_model`:

```bash
gym eval run --no-serve \
    --agent ifbench_benchmark_simple_agent \
    --input resources_servers/ifbench/data/example.jsonl \
    --output /tmp/ifbench_rollouts.jsonl \
    --num-repeats 1 \
    --max-output-tokens 4096 \
    --temperature 0.0 \
    --prompt-config benchmarks/ifbench/prompts/default.yaml
```

```text
Using prompt config: benchmarks/ifbench/prompts/default.yaml
Reading rows: 5it [00:00, 53773.13it/s]
Traceback (most recent call last):
  ...
  File ".../nemo_gym/rollout_collection.py", in _preprocess_rows_from_config
    validate_prompt_compatibility([row for _, _, row in raw_rows], prompt_cfg)
  File ".../nemo_gym/prompt.py", line 83, in validate_prompt_compatibility
    raise ValueError(
ValueError: Some rows have responses_create_params.input but prompt_config is also specified. These are mutually exclusive. Use one or the other. Violating rows: [0, 1, 2, 3, 4]
  exit 1 in 3.0s
```

### After the fix

Gym `07b4ac277` (this branch), the README command as now documented,
same environment:

```bash
gym eval run --no-serve \
    --agent ifbench_benchmark_simple_agent \
    --input resources_servers/ifbench/data/example.jsonl \
    --output /tmp/ifbench_rollouts.jsonl \
    --num-repeats 1 \
    --max-output-tokens 4096 \
    --temperature 0.0
```

```text
  exit 0 in 36.3s
5 rollout rows with unique identities
every row carries responses_create_params/response/reward and a resp_* id
materialized and rollout identity sets match (5 pairs)
failures sidecar present (0 rows)
ifbench_benchmark_simple_agent: mean/reward 0.4 agrees with persisted rollouts
ifbench_benchmark_simple_agent: key_metrics is a subset of agent_metrics
```

### Validation

- QA testcase `testcases/environments/ifbench.py` (nmfw_tests), which
runs the README's own
  commands with a live `openai_model` backend on an H100 host:
  - before, Gym `eed77e195`: 0/1 passed (the `ValueError` above);
- after, Gym `07b4ac277`: 1/1 passed — five real generations, verify
results recomputed
independently, and twelve strict/loose/fractional/binary scoring
controls.
- Locally (macOS, Python 3.13.14): the README command without
`--prompt-config` reads all five rows
  and gets past preprocessing; with it, the same `ValueError`.
- `pre-commit run --all-files`: passed.
- `pytest tests/unit_tests/test_fern_docs_links.py
tests/unit_tests/test_cli_main.py`: 243 passed.
- Rollout evidence: N/A beyond the QA run above — documentation-only
change.

### Compatibility

None. Documentation only; no code, config, or data changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: qiaochuz <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants