Skip to content

fix: gym dataset collate creates the artifact dir when missing (run-from-wheel)#1811

Merged
wprazuch merged 2 commits into
mainfrom
wprazuch/gym-run-from-wheel
Jun 29, 2026
Merged

fix: gym dataset collate creates the artifact dir when missing (run-from-wheel)#1811
wprazuch merged 2 commits into
mainfrom
wprazuch/gym-run-from-wheel

Conversation

@wprazuch

@wprazuch wprazuch commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Final piece of the "use built-in components from a pip install of NeMo Gym" work (epic #1205, criterion C5). After #1806 (merged) made a dataset's read resolve to the install root, gym dataset collate on a built-in dataset from an external cwd would then crash on the write: the derived artifacts (_metrics.json, _prepare.jsonl) are built from the raw, cwd-relative jsonl_fpath and open(..., "w") with no mkdir, so they hit FileNotFoundError when that directory doesn't exist in the cwd.

Fix: mkdir(parents=True, exist_ok=True) the artifact directory before writing (the output_dirpath write was already guarded). For the common case (collating your own dataset in your project) it's a no-op; it just prevents the crash for the install-root-resolved case.

Tests

  • test_collate_creates_missing_parent_dir — collate auto-creates a missing artifact parent instead of crashing.

ruff clean; test_train_data_utils + test_cli_setup_command green. 2 files, +26.

Scope notes (verified, intentionally not in this PR)

  • gym env start of a built-in from a wheel already workssetup_command's non-editable path installs nemo-gym==<version> from the index; it just needs a published version (verified empirically). No code change needed.
  • gym env test of a built-in from a wheel — the per-server test venv lacks pytest (it's only in the [dev] extra). Deliberately left out: pulling all of [dev] (pre-commit/mypy/ruff + test deps) into every test venv is too coarse, and running a built-in's tests from a wheel is a contributor-in-repo edge case. Can be revisited with a narrow [test] extra if needed.

Completes the run-from-wheel story (epic #1205 C5). `gym env start` of a built-in
already works once nemo-gym is published (setup_command's non-editable path installs
`nemo-gym==<version>` from the index); this fixes the two remaining tooling gaps:

- gym env test: the per-server venv installed bare `nemo-gym` from the index, dropping
  the `[dev]` extra, so `&& pytest` failed (exit 127). Add an opt-in include_dev_extra
  to setup_env_command; _test_single passes it so the test venv gets pytest. gym env
  start stays lean (no test deps).
- gym dataset collate: the per-dataset artifact writes (_metrics.json / _prepare.jsonl,
  derived from the raw cwd-relative jsonl_fpath) crashed with FileNotFoundError when the
  dir didn't exist in the cwd (e.g. a built-in dataset resolved from the install root via
  #1806). mkdir(parents) the artifact dir before writing.

Tests: include_dev_extra installs nemo-gym[dev]; collate creates a missing parent dir.
Signed-off-by: Wojciech Prazuch <wprazuch@nvidia.com>
Per review: pulling nemo-gym's [dev] extra (pre-commit/mypy/ruff + the pytest deps)
into every per-server test venv is too coarse just to get pytest for `gym env test`
from a wheel. Reverting the setup_command/_test_single `include_dev_extra` change;
`gym env test` from a wheel (a contributor-runs-in-repo edge case) stays a documented
limitation. PR #6 now only fixes the clear `gym dataset collate` write crash (mkdir).

Signed-off-by: Wojciech Prazuch <wprazuch@nvidia.com>
@wprazuch wprazuch changed the title fix: make gym env test & dataset collate work from a wheel install fix: gym dataset collate creates the artifact dir when missing (run-from-wheel) Jun 29, 2026
@wprazuch wprazuch merged commit 00fe01d into main Jun 29, 2026
30 checks passed
@wprazuch wprazuch deleted the wprazuch/gym-run-from-wheel branch June 29, 2026 13:33
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