Skip to content

feat(eval): add IsolatedExporter to run an exporter's backend work in its own venv - #4915

Merged
prokotg merged 3 commits into
prokotg/eval-export-record-exportersfrom
prokotg/eval-export-isolated-runner
Oct 28, 2026
Merged

prokotg merged 3 commits into
prokotg/eval-export-record-exportersfrom
prokotg/eval-export-isolated-runner

Conversation

@prokotg

@prokotg prokotg commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • IsolatedExporter (nemo_gym/exporters/isolated.py): an exporter whose backend work runs in its own venv, so its SDK never enters Gym's environment. A subclass declares requirements, worker_fpath and build_payload(artifacts, workdir); config validation and file staging stay in the main process, and the staging directory is removed afterwards.
  • The venv is built by _venv_setup.setup_environment() (locked, reused when ready) at <uv_venv_dir>/exporters/<name>/<requirements digest>/.venv; a changed requirement list gets a fresh venv.
  • The worker is a standalone file with run(payload) -> dict, run by a stdlib-only harness (_isolated_worker.py). The payload goes in on stdin (credentials stay out of ps) and the result comes back in a file (SDK output cannot corrupt it). PYTHONPATH, PYTHONHOME and VIRTUAL_ENV are not inherited.
  • A worker exception or crash, a failed venv build, a run that cannot be prepared and a worker that cannot be launched all return failed results instead of raising. A worker that reports a result but then exits non-zero fails too.
  • The venv root, interpreter and worker path are made absolute before the worker changes into the staging directory, so a relative uv_venv_dir works. The exporter venv's bin leads the worker's PATH, so a bare python is the exporter's. The worker module is registered in sys.modules, so dataclasses with postponed annotations load.
  • The harness drops its own directory from sys.path, because mlflow.py and wandb.py beside it would otherwise shadow the SDKs of the same name.
  • An exporter can bound its worker with worker_timeout_s(payload); a worker that outlives it is killed and the export fails. The default is no limit.

Nothing uses it yet; EvalRDL (step 6) is the first user. Part of #2977 (export-aware evaluation runs).

PR plan

Separate PRs; steps 1-8 are stacked (stack #4910). Goal: make gym eval export pluggable so a finished run can go to tracking systems without live exporters, and gym eval submit can export after each benchmark.

  1. save the masked, unresolved config from gym eval run (feat(eval): save the masked config beside rollouts from gym eval run #4908)
  2. RunArtifacts and path derivation helpers (feat(eval): add RunArtifacts to derive a run's files from its rollouts path #4909)
  3. Exporter base class and registry, starting with atif, plus the positional exporter CLI argument (--format deprecated) (feat(eval): add the Exporter base class and registry, with atif as the first exporter #4911)
  4. post-run mlflow and wandb export: shared metrics flattening, BaseExporter.export() and the already-exported guard (feat(eval): export a finished run to MLflow or W&B with gym eval export #4914)
  5. This PR: isolated-venv subprocess runner for directory exporters
  6. EvalRDL exporter (feat(eval): export a finished run to EvalRDL with gym eval export evalrdl #4965)
  7. gym eval submit integration: an export map with job-level defaults and per-benchmark overrides, validation, install extras, and a job-script tail (Slurm only at first) (feat(orchestration): run exports after each benchmark of gym eval submit #4974)
  8. contributor guide: add an exporter (user-facing docs land in each step's PR) (docs(contribute): add a guide to writing an exporter for gym eval export #5077)

Validation

  • test_isolated_exporter.py: 19 passed, building a real venv and running a real worker (also: relative venv root and worker path, a bare python resolving to the exporter venv, dataclasses with postponed annotations, a non-zero exit after a result, a launch failure, the harness directory off sys.path, the time limit): different sys.prefix, no nemo_gym import, no PYTHONPATH, venv reused, staging removed, skipped/failed/success round-trip, worker exception and crash, failed build, unpreparable run. pre-commit: passed.
  • Also installed a pinned package through the real install path and imported it in the venv.

Known gaps

Rollout evidence

N/A: no agent, verifier or model behavior is touched.

@prokotg
prokotg added this pull request to stack #4910 October 22, 2026 12:55
@copy-pr-bot

copy-pr-bot Bot commented Oct 22, 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.

@prokotg

prokotg commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test af9e0da

@prokotg

prokotg commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 56082d4

Comment thread nemo_gym/exporters/isolated.py Outdated

def __init__(self, config: RunExportConfig, *, venv_root: Path) -> None:
super().__init__(config)
self.venv_root = Path(venv_root)

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.

why not Path(venv_root).resolve()? Without resolve(), a relative path override +uv_venv_dir=./venvs makes the worker launch look for the exporter's Python in the wrong folder and crash with FileNotFoundError

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.

Agreed, and good catch. venv_root is now Path(venv_root).resolve() in __init__, so a relative +uv_venv_dir=./venvs points at the right interpreter after the launch changes into the staging directory. Fixed in b4e627b, with a test that runs the exporter from a relative root.

@prokotg
prokotg force-pushed the prokotg/eval-export-isolated-runner branch from 18e049b to 506cb4d Compare October 27, 2026 12:50

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

Review by Alex Gronskiy (EvalRDL side).

_isolated_worker.py

  • The fix that drops the harness's own directory from sys.path lands in #4965, but this PR introduces the bug: mlflow.py and wandb.py already sit next to the harness, so a worker importing those SDKs would import Gym's modules instead. Move the fix and its regression test here.

isolated.py

  • _run_worker has no timeout (listed as a known gap). The EvalRDL timeout setting only limits the wait for the service's verdict; the upload itself (parts, retries) has no overall limit. Before #7's job-script tail lands, subprocess.run(timeout=...) at roughly the config timeout plus a margin would stop a hung upload from consuming the Slurm allocation.

Otherwise LGTM.

@prokotg

prokotg commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Both addressed in 6e56806:

… its own venv

The SDK and its dependencies stay out of Gym's environment. The main process validates the config and
stages files; a stdlib-only harness runs the exporter's worker in a locked, requirements-keyed venv,
with the JSON payload on stdin and the result in a file.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
Anchor the venv root, interpreter and worker file to absolute paths before
the launch changes into the staging directory, put the exporter venv first
on the worker's PATH, register the worker module in sys.modules so
dataclasses and postponed annotations work, fail a worker that reports a
result but then exits non-zero, and return a failed result when the worker
cannot be launched.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
… the worker's run time

mlflow.py and wandb.py sit beside the harness, so a worker importing those
SDKs would have loaded Gym's modules instead. An exporter can now give its
worker a time limit; a worker that outlives it is killed and the export fails.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
@prokotg

prokotg commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bb5aa0a

@prokotg

prokotg commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/review

@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 remaining eligible findings in this follow-up.

Verified all five prior findings against current source and regression assertions:

  • Launch and environment handling now anchors paths, selects the exporter venv for executable lookup, converts launch errors to failed results, and rejects success/skipped results followed by nonzero exits.
  • Worker loading registers the module before execution, addressing postponed-annotation dataclasses.

Also checked harness-directory removal and optional timeout handling through their affected import, failure-reporting, and staging-cleanup paths, with the relevant regression cases.

Static review only; tests were not executed. The previously reviewed tree is unavailable, limiting independent inter-review comparison. This review verified the reported fixes and identifiable subsequent changes rather than restarting whole-PR discovery; no new escalation-eligible regression was established.

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 findings-only review. Request a full review with /review reset=true.

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

Review by Alex Gronskiy (EvalRDL side). Both points are addressed, thanks. LGTM.

Optional nit: the timeout message prints exc.timeout, which some Python versions report as the remaining time (0.999936s locally on 3.12). Printing self.worker_timeout_s(payload) makes it stable.

@github-actions

Copy link
Copy Markdown
Contributor

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

This branch was previously deployed

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

Labels

area:evaluation Evaluation, rollout collection, reward profiling, comparison, and exporters feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants