Skip to content

Add human-eval benchmark and resource server - #1201

Merged
bxyu-nvidia merged 5 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/migrate-gym-human-eval
May 7, 2026
Merged

bxyu-nvidia merged 5 commits into
NVIDIA-NeMo:mainfrom
gwarmstrong:georgea/migrate-gym-human-eval

Conversation

@gwarmstrong

Copy link
Copy Markdown
Contributor

Add human-eval benchmark and resource server

Summary

Migrates the HumanEval+ benchmark (164 Python function-completion tasks)
from NeMo Skills into Gym. Uses execution-based verification against
EvalPlus's bundled base + plus tests, matching the Skills eval_evalplus
evaluator's per-task semantics. The new evalplus resource server is
parameterised by dataset: humaneval | mbpp so MBPP+ can be added later
as a data-only follow-up benchmark.

Includes

  • resources_servers/evalplus/ — execution-based code-completion server
    • evalplus_integration/runner.py: Ray-remote wrapper around
      evalplus.evaluate.check_correctness, parameterised by dataset.
      runtime_env mirrors code_gen/lcb_integration (worker uses the
      server's venv, server dir on PYTHONPATH for the package-less
      integration module).
    • Code extraction: last-fence + strict-mode (matches Skills'
      preprocess_code byte-for-byte). <think>...</think> reasoning
      preambles are not stripped here — start vLLM with
      --reasoning-parser <name> so the extractor sees clean output.
    • verify() prepends problem["prompt"] to body-only completions
      (mirrors evalplus.evaluate.evaluate()'s completion-style fallback
      that check_correctness itself does not perform).
  • benchmarks/human_eval/ — benchmark dataset binding
    • Data source: HumanEval+ via evalplus.data.get_human_eval_plus()
      (164 tasks, MIT license).

Validated against NeMo Skills

Per-task verifier (deterministic, EvalPlus base + plus tests) | 4 rollouts/task
| temperature=1.0, top_p=0.95, top_k=20 | nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16:

====================================================================================
EvalPlus | 4 rollouts/task | T=1.0 top_p=0.95 top_k=20 | Nemotron-3-Nano-30B-A3B-BF16
====================================================================================
Metric                                    Skills        Gym       Delta
-----------------------------------------------------------------------
pass@1[avg-of-4] passing_base_tests       81.55%       79.88%     -1.68%
pass@1[avg-of-4] passing_plus_tests       76.37%       75.30%     -1.07%
pass@4           passing_base_tests       98.78%       98.17%     -0.61%
pass@4           passing_plus_tests       94.51%       93.90%     -0.61%
no_answer rate                              ~0%        0.15%      +0.15%
truncated rollouts (≥16380 tokens)        1 / 656     1 / 656         0

Brings NeMo-Skills' human-eval evaluation into NeMo-Gym. The new
`evalplus` resource server is parameterized by `dataset:
humaneval | mbpp` so MBPP+ can be added later as a data-only migration.

What's here:

- `resources_servers/evalplus/` (new)
    * `app.py`: SimpleResourcesServer that wraps EvalPlus's
      `check_correctness` via Ray. Returns two named scores —
      `passing_base_tests` and `passing_plus_tests` — used for
      pass@k / majority@k. Reward = 1.0 iff plus passes.
    * `evalplus_integration/runner.py`: Ray-remote wrapper for
      per-task base + plus checks. Mirrors the runtime_env pattern
      used by `code_gen/lcb_integration`.
    * `extract_code_strict`: last-fence + strict-mode code extractor
      matching Skills' `preprocess_code` semantics. Reasoning
      preambles are expected to be stripped upstream by vLLM's
      `--reasoning-parser`.
    * Unit tests cover code extraction, verify() success/fail/no-code/
      missing-task-id paths, and metrics aggregation. Dataset +
      expected_output and Ray remote are mocked so tests don't touch
      EvalPlus or Hugging Face.
- `benchmarks/human_eval/` (new)
    * `prepare.py` mirrors Skills' transform: 4-space -> tab in `prompt`,
      drops large `base_input`/`plus_input` arrays (re-fetched at eval
      time by EvalPlus). Asserts 164 problems for upstream-drift safety.
    * `prompts/default.yaml`: character-for-character port of Skills'
      `generic/codegen.yaml`.
    * `config.yaml` chains to the `evalplus` server with
      `dataset: humaneval`.

Verification matches Skills' `eval_evalplus` evaluator (in
`nemo_skills/evaluation/evaluator/code.py`) which calls
`evalplus.evaluate.evaluate(...)` and reads back `base_status` /
`plus_status` per task.

Signed-off-by: gwarmstrong <[email protected]>
The verify() path was passing the model's extracted code straight to
`evalplus.evaluate.check_correctness`, which (unlike the high-level
`evalplus.evaluate.evaluate`) does NOT prepend `problem["prompt"]` to
completion-style samples. When the model emits just the function body
(or the body wrapped in a redundant `def` without `from typing import`
imports), check_correctness exec'd the candidate without imports and
hit NameError on the type annotations, returning ("fail", []).

Fix: replicate the prepend logic that evalplus.evaluate.evaluate uses for
JSONL rows that have `completion` instead of `solution`:

    solution = (
        sample["solution"]
        if "solution" in sample
        else problems[task_id]["prompt"] + sample["completion"]
    )

We additionally guard against double-prepending if the model already
included the prompt verbatim, mirroring evalplus's `startswith` check
in check_correctness's caller.

Verified locally: the same `mean_absolute_deviation` body-only completion
that returned base="fail", plus="fail" with empty details before now
returns base="pass", plus="pass" with 3 base tests run.

Adds two tests:
  * test_verify_prepends_prompt_when_missing: body-only completion gets
    prefix added before going to check_correctness.
  * test_verify_does_not_double_prepend: full-prompt completion is
    passed through unchanged.

Without this fix, the HumanEval+ Skills-vs-Gym parity run on aws-iad
showed Gym pass@1 ~10pp below Skills (71% vs 82% base), with 162/164
tasks disagreeing per-task. Skills hits this code path through
`evaluate(...)`'s prepend; check_correctness on its own does not.

Signed-off-by: gwarmstrong <[email protected]>
- test_falls_back_to_generic_fence asserted the rfind-based extractor
  recovers `z=3` from a single generic fence pair. With rfind, the
  closing fence is the "last" ``` and nothing follows it, so strict
  mode returns "" — matching Skills' preprocess_code byte-for-byte.
  Test now asserts "" with a comment explaining the rfind semantics.

- Adds three coverage fillers:
    - TestLoadDatasetAndExpected covers the humaneval / mbpp /
      unsupported-dataset forks of _load_dataset_and_expected by
      mocking evalplus.{data,evaluate}.
    - TestRunnerImport.test_runner_body_with_mocked_evalplus calls
      the @ray.remote function's underlying Python via _function and
      verifies the (status, details) -> dict mapping. evalplus.
      evaluate is mocked so no subprocess execution.

Coverage: 81% -> 98% (app 98%, runner 100%, only line 278's
`if __name__ == "__main__"` and one branch in get_key_metrics
remain uncovered — both standard exclusions).

Signed-off-by: gwarmstrong <[email protected]>
- data/example_metrics.json: produced by ng_prepare_data
  +mode=example_validation against example.jsonl. 5 examples,
  schema validated.
- data/example_rollouts.jsonl: 5 rollouts (one per HumanEval/0..4)
  derived from a real Gym run of this server (commit 0259f39 with
  the dict-literal top_k=20 override). All five pass base + plus
  tests on the actual model output, exercising the verifier's
  extract -> Ray check_correctness -> base/plus status path
  end-to-end. responses_create_params.input substituted with
  example.jsonl's baked content so the snapshot matches what
  ng_collect_rollouts against example.jsonl would produce.

Signed-off-by: gwarmstrong <[email protected]>
The prepared JSONL stores raw `question` rows with no
`responses_create_params.input`, and ng_collect_rollouts (unlike ng_run)
does not pick up the `prompt_config:` field on the dataset entry in
config.yaml. Without the override, the documented command crashes at
nemo_gym/rollout_collection.py:_preprocess_rows_from_config with
KeyError: 'responses_create_params'. Add the override to the README's
quickstart so the block is copy-paste runnable.

Signed-off-by: gwarmstrong <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Apr 30, 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.

@bxyu-nvidia
bxyu-nvidia merged commit 3bbe185 into NVIDIA-NeMo:main May 7, 2026
5 checks passed
bxyu-nvidia pushed a commit that referenced this pull request May 8, 2026
# Add mbpp benchmark

## Summary

Migrates the MBPP+ benchmark (378 Python function-completion tasks)
from NeMo Skills into Gym as a data-only follow-up to the HumanEval+
migration (#1201). Reuses the `evalplus` resource server unchanged —
its `dataset: humaneval | mbpp` knob was already in place — so this
PR adds only the new `benchmarks/mbpp/` directory.

## Includes

- `benchmarks/mbpp/` — benchmark dataset binding
  - Data source: MBPP+ via `evalplus.data.get_mbpp_plus()`
    (378 tasks, MIT license).
- `prepare.py` mirrors NeMo-Skills'
`nemo_skills/dataset/mbpp/prepare.py`:
    same `evalplus` source, same per-row `prompt.replace("    ", "\t")`
    (Skills comment: "models like tabs more than spaces"), drops
    `base_input` / `plus_input` (re-fetched at eval time by EvalPlus).
  - `prompts/default.yaml` is character-for-character identical to
    Skills' `nemo_skills/prompt/config/generic/codegen.yaml`.
  - `config.yaml` inherits the `evalplus` resource server with
    `dataset: mbpp`; reuses the `evalplus_simple_agent` configuration.

## Validation (data-only / Mode 2)

Skills-vs-Gym prepare-output parity, run on the same `evalplus==0.3.1`
upstream:

```
Skills file: nemo_skills/dataset/mbpp/test.jsonl
Gym file:    benchmarks/mbpp/data/mbpp_benchmark.jsonl

Row count:   378 (Skills)  ==  378 (Gym)
Field-level mismatches across 378 rows on the 4 retained fields
(question, entry_point, canonical_solution, task_id):  0
```

Documented schema rename: Skills' top-level `task_id` is moved into
`verifier_metadata.task_id` to match the `evalplus` resource server's
verifier contract; Skills' extra informational fields (`assertion`,
`atol`, `contract`, `prompt`) are dropped (not consumed by either
evaluator). This mirrors the schema convention adopted in the
`benchmarks/human_eval/` sibling.

The `evalplus` resource server's existing test suite (24 tests,
including `TestLoadDatasetAndExpected.test_mbpp_path`) continues to
pass without modification.

## Licensing

MBPP+ is MIT-licensed (https://github.com/evalplus/evalplus).

Signed-off-by: gwarmstrong <[email protected]>
bxyu-nvidia pushed a commit that referenced this pull request May 8, 2026
…1258)

# Add human-eval-infilling (FIM) benchmark

## Summary

- Migrates the
[HumanEval-Infilling](https://github.com/openai/human-eval-infilling)
(Bavarian et al., 2022) Code Fill-in-the-Middle benchmark from NeMo
Skills (`nemo_skills/dataset/human-eval-infilling`) into NeMo Gym.
- Adds a small new resource server, `code_fim`, that splices `prefix +
completion + suffix + test` and runs the spliced program via
`human_eval_infilling.execution.check_correctness` (the same library
Skills uses at evaluation time). The server is independent of the
existing `evalplus` server — `evalplus` handles function-completion
(HumanEval+, MBPP+); `code_fim` handles fill-in-the-middle, which has a
different data shape (`prefix` / `suffix` / `test` / `entry_point`
instead of `prompt` / `entry_point` / `test`).
- Adds the `human_eval_infilling` benchmark dir, which inherits from
`code_fim` and ships data + prompt + prepare script for the three
default difficulty levels (`single_line` / `multi_line` /
`random_span`). Default benchmark variant is `random_span` (matches
Skills' `EVAL_SPLIT`).

Follow-up to the EvalPlus-server / HumanEval+ migration (#1201). All
changes are additive — `resources_servers/evalplus/` is untouched.

## Files added

- `benchmarks/human_eval_infilling/`
- `config.yaml` — agent + resource-server config, `_inherit_from:
code_fim`
- `prepare.py` — fetches the three splits via
`human_eval_infilling.data.read_problems(...)` (the upstream `.jsonl.gz`
files; the HF mirror at `loubnabnl/humaneval_infilling` is a
script-based dataset and is no longer compatible with modern `datasets`
versions, but the gz files are content-equivalent)
- `prompts/default.yaml` — char-for-char copy of Skills'
`nemo_skills/prompt/config/generic/fim.yaml`
  - `README.md`, `__init__.py`
- `resources_servers/code_fim/`
- `app.py` — FastAPI / Ray verifier with last-fence + strict-mode code
extraction (matches Skills' `preprocess_code` with
`strip_whitespace=False`), Skills' `remove_overlap` postprocessing, and
a thin Ray-remote wrapper around
`human_eval_infilling.execution.check_correctness`
- `human_eval_infilling_integration/runner.py` — Ray-remote shim,
mirrors the pattern in
`resources_servers/evalplus/evalplus_integration/runner.py`
- `configs/code_fim.yaml`, `tests/test_app.py` (30 tests, all passing),
`data/example.jsonl` + `example_rollouts.jsonl` + `example_metrics.json`
for CI, `pyproject.toml`, `README.md`

## Skills → Gym component mapping

| Skills component | Skills location | Gym location |
|------------------|-----------------|--------------|
| Dataset definition |
`nemo_skills/dataset/human-eval-infilling/__init__.py`
(`METRICS_TYPE=human_eval_infilling`, `EVAL_SPLIT=random_span`) |
`benchmarks/human_eval_infilling/config.yaml` |
| Data preparation |
`nemo_skills/dataset/human-eval-infilling/prepare.py` |
`benchmarks/human_eval_infilling/prepare.py` |
| Prompt template | `nemo_skills/prompt/config/generic/fim.yaml` |
`benchmarks/human_eval_infilling/prompts/default.yaml` (char-for-char) |
| Code extraction (`preprocess_code`, last-fence + strict +
`strip_whitespace=False`) |
`nemo_skills/evaluation/evaluator/code.py::preprocess_code` | `code_fim`
server's `extract_code_strict` |
| Boundary cleanup (`remove_overlap` against prefix and suffix, drop one
leading `\n`) |
`nemo_skills/evaluation/evaluator/code.py::eval_human_eval_infilling`
(`postprocess_code`) | `code_fim` server's `postprocess_completion` |
| Verification | `human_eval_infilling.evaluate.evaluate(...)` |
`code_fim` server's Ray-remote `check_correctness` |
| Metrics class (`HumanEvalInfillingMetrics`, pass@k on `passed`) |
`nemo_skills/evaluation/metrics/code_metrics.py` | `code_fim` server's
`compute_metrics` (uses `compute_pass_majority_metrics` with
`accuracy=passed`) |

## Data parity (Skills vs Gym)

`prepare.py` produces JSONLs whose per-row fields match Skills
byte-for-byte for every shared `task_id` across all three default
splits. Verified via `compare_prepare.py`:

| Split | Tasks | Gym tasks | Common | Field mismatches | Row-order
match |

|----------------|-------|-----------|--------|------------------|-----------------|
| `single_line` | 1033 | 1033 | 1033 | 0 | yes |
| `multi_line` | 5815 | 5815 | 5815 | 0 | yes |
| `random_span` | 1640 | 1640 | 1640 | 0 | yes |

The compared fields are the ones Skills writes: `prefix`, `suffix`,
`canonical_solution`, `language`, `split`, `comment_delimiter`. Gym
additionally writes a `verifier_metadata.task_id` field (= top-level
`task_id`) so the resource server can look up `entry_point` + `test` at
verify time without bloating the on-disk JSONL.

## Verification details (parity with Skills)

The Gym verifier mirrors Skills' `eval_human_eval_infilling`
step-for-step:

1. **Code extraction** — strip `<think>...</think>`, take the LAST
fenced block (preferring ` ```python ` over ` ``` `), strict mode (no
closer → empty), no `.strip()` (FIM uses `strip_whitespace=False` in
Skills since indentation is significant for the spliced program).
2. **Drop one leading `\n`** — LLMs emit ` ```python\n<fill>``` `, so
the literal newline is part of the fence formatting and not the
completion.
3. **`remove_overlap(prefix, completion, "following")`** — strips a tail
of `prefix` that the model re-emits at the head of its completion.
Whitespace-only overlaps without a newline are skipped, matching Skills.
4. **`remove_overlap(completion, suffix, "preceding")`** — symmetric:
strips a head of `suffix` that the model re-emits at the tail.
5. **Run** — Ray-remote call to
`human_eval_infilling.execution.check_correctness(problem, completion,
timeout=3.0)`. The check program executed by the upstream library is
`prefix + completion + suffix + "\n" + test + "\n" +
check(entry_point)`, the same program Skills' evaluator runs.

## Why a new `code_fim` server, not extending `evalplus`?

The `evalplus` server on the base branch handles function-completion
benchmarks (HumanEval+, MBPP+) by feeding `prompt + completion` into
`evalplus.evaluate.check_correctness` against base + plus tests. FIM is
structurally different:

- input is `prefix` + `suffix` (not just `prompt`),
- the spliced program must be `prefix + completion + suffix + test`,
- there are no "plus" tests — a single `passed` verdict per task,
- the sandboxed runner is
`human_eval_infilling.execution.check_correctness` (a different
package), not `evalplus.evaluate.check_correctness`.

A new directory keeps `evalplus`'s server logic, schemas, and tests
untouched, which keeps the parallel MBPP migration that stacks on the
same base branch unaffected.

## End-to-end smoke test

Ran `ng_run` + `ng_collect_rollouts` against
`https://integrate.api.nvidia.com/v1` with
`nvidia/nvidia-nemotron-nano-9b-v2` on the 5-row
`resources_servers/code_fim/data/example.jsonl`:

- 4/5 rollouts produced non-empty `output_text`
- 4/5 had code extracted and executed (`status` populated by the
upstream library)
- 5/5 rewards in `[0, 1]`
- Aggregate metrics returned `pass@1/accuracy`, `majority@1/accuracy`,
`pass@1[avg-of-1]/accuracy`

The model passes 0% on this small smoke run with
`max_output_tokens=2048` (the 9B model truncates / mis-indents); a real
parity run vs Skills would use a 30B-class model with the larger token
budget Skills' baseline uses.

## Tests

- `resources_servers/code_fim/tests/test_app.py` — 30 tests covering:
code extraction (last-fence + strict + no-strip + `<think>` handling),
`remove_overlap`, `postprocess_completion`, the verify endpoint (pass /
fail / no-code / unknown task / missing task / boundary trim), the
metrics layer (pass@k, no_answer tracking, headline-metrics selection),
and dataset loading.
- `resources_servers/evalplus/tests/test_app.py` — 24 tests pre-existed;
all still pass (no regressions).

## Licensing

- Upstream `human-eval-infilling` library: MIT
(https://github.com/openai/human-eval-infilling)
- Upstream `loubnabnl/humaneval_infilling` HF dataset: MIT
- This migration: Apache-2.0

## Test plan

- [x] `pytest resources_servers/code_fim/tests/` — 30/30 pass
- [x] `pytest resources_servers/evalplus/tests/` — 24/24 pass (no
regressions)
- [x] Skills-vs-Gym `prepare.py` byte-equivalence check across all three
default splits (1033 + 5815 + 1640 rows, 0 field mismatches, row order
matches)
- [x] End-to-end `ng_run` + `ng_collect_rollouts` smoke test against
`https://integrate.api.nvidia.com/v1`
- [ ] Skills-vs-Gym pass@1 / pass@k parity run on a larger model (left
to follow-up — same pattern as `migrate-gym-human-eval`)

---------

Signed-off-by: gwarmstrong <[email protected]>
Co-authored-by: gwarmstrong <[email protected]>
Alvorecer721 pushed a commit to Alvorecer721/Gym that referenced this pull request Jun 15, 2026
<!--
Opened manually via:  gh pr create -F PR_DESCRIPTION.md
Target remote: NVIDIA-NeMo/Gym
Target branch: main
-->

# Add human-eval benchmark and resource server

## Summary

Migrates the HumanEval+ benchmark (164 Python function-completion tasks)
from NeMo Skills into Gym. Uses execution-based verification against
EvalPlus's bundled base + plus tests, matching the Skills
`eval_evalplus`
evaluator's per-task semantics. The new `evalplus` resource server is
parameterised by `dataset: humaneval | mbpp` so MBPP+ can be added later
as a data-only follow-up benchmark.

## Includes

- `resources_servers/evalplus/` — execution-based code-completion server
  - `evalplus_integration/runner.py`: Ray-remote wrapper around
    `evalplus.evaluate.check_correctness`, parameterised by dataset.
    runtime_env mirrors `code_gen/lcb_integration` (worker uses the
    server's venv, server dir on PYTHONPATH for the package-less
    integration module).
  - Code extraction: last-fence + strict-mode (matches Skills'
    `preprocess_code` byte-for-byte). `<think>...</think>` reasoning
    preambles are not stripped here — start vLLM with
    `--reasoning-parser <name>` so the extractor sees clean output.
  - `verify()` prepends `problem["prompt"]` to body-only completions
    (mirrors `evalplus.evaluate.evaluate()`'s completion-style fallback
    that `check_correctness` itself does not perform).
- `benchmarks/human_eval/` — benchmark dataset binding
  - Data source: HumanEval+ via `evalplus.data.get_human_eval_plus()`
    (164 tasks, MIT license).

## Validated against NeMo Skills

Per-task verifier (deterministic, EvalPlus base + plus tests) | 4
rollouts/task
| temperature=1.0, top_p=0.95, top_k=20 |
nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16:

```
====================================================================================
EvalPlus | 4 rollouts/task | T=1.0 top_p=0.95 top_k=20 | Nemotron-3-Nano-30B-A3B-BF16
====================================================================================
Metric                                    Skills        Gym       Delta
-----------------------------------------------------------------------
pass@1[avg-of-4] passing_base_tests       81.55%       79.88%     -1.68%
pass@1[avg-of-4] passing_plus_tests       76.37%       75.30%     -1.07%
pass@4           passing_base_tests       98.78%       98.17%     -0.61%
pass@4           passing_plus_tests       94.51%       93.90%     -0.61%
no_answer rate                              ~0%        0.15%      +0.15%
truncated rollouts (≥16380 tokens)        1 / 656     1 / 656         0
```

---------

Signed-off-by: gwarmstrong <[email protected]>
Co-authored-by: gwarmstrong <[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