Skip to content

feat(data): support dotted import paths in dataset_name - #2642

Merged
yuki-97 merged 5 commits into
NVIDIA-NeMo:mainfrom
lonexreb:fix/1020-dotted-import-dataset-classes
Jun 5, 2026
Merged

yuki-97 merged 5 commits into
NVIDIA-NeMo:mainfrom
lonexreb:fix/1020-dotted-import-dataset-classes

Conversation

@lonexreb

Copy link
Copy Markdown
Contributor

Summary

Closes #1020.

load_response_dataset previously rejected any dataset_name not in the built-in DATASET_REGISTRY, forcing users to edit nemo_rl to plug in their own dataset class. After this change, a dataset_name of the form my_pkg.my_module.MyDataset is treated as a fully qualified import path: the dispatcher imports the module via importlib and resolves the class. Built-in registry behavior is unchanged.

```yaml
data:
default:
dataset_name: my_pkg.my_module.MyDataset # importable from PYTHONPATH
```

What changed

  • nemo_rl/data/datasets/response_datasets/__init__.py — added _resolve_external_dataset_class() helper that resolves dotted-path dataset names via importlib. load_response_dataset falls back to it when the name is not in DATASET_REGISTRY. Error messages are now per-branch so users see a precise failure:
    • bare name not in registry and not dotted → Unsupported dataset_name with full alternatives
    • dotted path with unimportable module → Could not import module
    • dotted path with missing attribute → has no attribute
    • dotted path resolving to a non-class → is not a class
  • tests/unit/data/datasets/test_response_dataset_registry.py — new unit test file covering each branch (built-in lookup unchanged, dotted-path resolution, all four error modes). Uses a throwaway types.ModuleType registered in sys.modules so no on-disk fixture modules are required.
  • docs/guides/grpo.md — small section under the data config docs explaining the workflow.

Backwards compatibility

Fully backwards compatible. All existing dataset_name values resolve via the registry exactly as before; the dotted-path branch is only reached when the name is not in the registry.

Test plan

  • `ruff check` — clean
  • `ruff format --check` — clean
  • `python3 -m py_compile` — clean
  • CI `L0_Unit_Tests` — runs the new `test_response_dataset_registry.py`
  • Manual smoke (out of scope for this PR; the unit tests exercise the dispatch in isolation)

@lonexreb
lonexreb requested review from a team as code owners May 30, 2026 07:13
@copy-pr-bot

copy-pr-bot Bot commented May 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.

@github-actions github-actions Bot added Documentation Improvements or additions to documentation community-request labels May 30, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Jun 1, 2026

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

hi @lonexreb , thanks for supporting this! left some comments.

Comment thread docs/guides/grpo.md Resolved
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Jun 1, 2026
lonexreb added a commit to lonexreb/RL that referenced this pull request Jun 2, 2026
Addresses @yuki-97's review on PR NVIDIA-NeMo#2642:

1. Move the dotted-path resolver out of `response_datasets/__init__.py`
   into `nemo_rl/data/datasets/utils.py` as a shared, public helper
   `resolve_external_dataset_class`, so both response and preference
   dispatchers can reuse it.

2. Apply the same dispatcher pattern to
   `nemo_rl/data/datasets/preference_datasets/__init__.py`:
   `load_preference_dataset` now also accepts dotted import paths,
   resolved via the shared helper.

3. Restructure both dispatchers into an explicit 3-way branch
   (registry / dotted path / error) and consolidate the error into a
   single helpful message naming all three options.

4. Restore the `# load dataset` comment.

5. Copy the "Custom datasets defined outside NeMo RL" docs section to
   `sft.md`, `dpo.md`, and `rm.md` (the response variant in sft.md, a
   preference variant in dpo.md and rm.md).

6. Update the unit-test file to import the resolver from its new
   location and add parallel coverage for `load_preference_dataset`
   (built-in + external + bad-bare-name + bad-dotted-path).

All behavior remains backwards compatible.

Signed-off-by: Shubhankar Tripathy <[email protected]>
@lonexreb

lonexreb commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @yuki-97! Just pushed d5b32bb5 addressing all four comments:

  1. Moved _resolve_external_dataset_class to nemo_rl/data/datasets/utils.py as a public, shared helper resolve_external_dataset_class.
  2. Applied the same logic to nemo_rl/data/datasets/preference_datasets/__init__.py — load_preference_dataset now also accepts dotted paths via the shared helper, with an equivalent 3-way dispatch and parallel test coverage.
  3. Restructured both dispatchers into the explicit 3-way branch you suggested (registry / dotted path / consolidated error), and used your error-message phrasing.
  4. Restored the # load dataset comment.
  5. Copied the docs section to sft.md, dpo.md, and rm.md (response variant in sft.md, preference variant in dpo.md and rm.md). Happy to migrate them to a single centralized data doc when you're ready — let me know.

Let me know if you'd like any further tweaks.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Jun 2, 2026
yuki-97
yuki-97 previously approved these changes Jun 3, 2026

@yuki-97 yuki-97 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 @lonexreb , LGTM!

@yuki-97 yuki-97 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Jun 3, 2026
@yuki-97

yuki-97 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

/ok to test d5b32bb

@yuki-97

yuki-97 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

hi @lonexreb , there's a lint check fail, could you run pre-commit run --all-files to fix? and maybe good to rebase main since it's 10 commits behind now and CI will check if the PR is behind > 10.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-customer Waiting on the original author to respond labels Jun 3, 2026
lonexreb added 3 commits June 4, 2026 18:14
Closes NVIDIA-NeMo#1020.

`load_response_dataset` previously rejected any `dataset_name` that was
not a key in the built-in `DATASET_REGISTRY`, forcing users to edit
nemo_rl to plug in their own dataset class. After this change, a
`dataset_name` of the form `my_pkg.my_module.MyDataset` is treated as
a fully qualified import path: the dispatcher imports the module via
`importlib` and resolves the class. Built-in registry behavior is
unchanged.

Error messages have been split so users get a precise failure mode:
- bare name not in registry and not dotted -> "Unsupported dataset_name"
  with the full alternatives spelled out
- dotted path with unimportable module -> "Could not import module"
- dotted path resolving to a non-class -> "is not a class"

Added unit tests covering each branch (`tests/unit/data/datasets/
test_response_dataset_registry.py`), and a docs snippet under the
GRPO data guide explaining the workflow.

Signed-off-by: Shubhankar Tripathy <[email protected]>
Addresses @yuki-97's review on PR NVIDIA-NeMo#2642:

1. Move the dotted-path resolver out of `response_datasets/__init__.py`
   into `nemo_rl/data/datasets/utils.py` as a shared, public helper
   `resolve_external_dataset_class`, so both response and preference
   dispatchers can reuse it.

2. Apply the same dispatcher pattern to
   `nemo_rl/data/datasets/preference_datasets/__init__.py`:
   `load_preference_dataset` now also accepts dotted import paths,
   resolved via the shared helper.

3. Restructure both dispatchers into an explicit 3-way branch
   (registry / dotted path / error) and consolidate the error into a
   single helpful message naming all three options.

4. Restore the `# load dataset` comment.

5. Copy the "Custom datasets defined outside NeMo RL" docs section to
   `sft.md`, `dpo.md`, and `rm.md` (the response variant in sft.md, a
   preference variant in dpo.md and rm.md).

6. Update the unit-test file to import the resolver from its new
   location and add parallel coverage for `load_preference_dataset`
   (built-in + external + bad-bare-name + bad-dotted-path).

All behavior remains backwards compatible.

Signed-off-by: Shubhankar Tripathy <[email protected]>
The `ruff --select I` import-sort hook in `.pre-commit-config.yaml`
moves `from nemo_rl.data.datasets.utils import …` to its correct
alphabetical position (after `tulu3`). No functional change.

Signed-off-by: Shubhankar Tripathy <[email protected]>
auto-merge was automatically disabled June 4, 2026 23:15

Head branch was pushed to by a user without write access

@lonexreb
lonexreb force-pushed the fix/1020-dotted-import-dataset-classes branch from d5b32bb to 0e90595 Compare June 4, 2026 23:15
@lonexreb

lonexreb commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @yuki-97 — done:

  • Ran pre-commit run --files … over the changed files. The only fix needed was ruff --select I reordering the new from nemo_rl.data.datasets.utils import resolve_external_dataset_class line to its correct alphabetical position.
  • Rebased on latest origin/main (was 17 commits behind). Clean rebase, no conflicts. Re-ran ruff check + ruff format --check on all touched files post-rebase — all green.
  • Force-pushed to the fork branch (--force-with-lease).

PR is now 3 commits ahead of main and lint should be green. Let me know if anything else needs attention.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Jun 5, 2026
@yuki-97

yuki-97 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

/ok to test b007f51

yuki-97
yuki-97 previously approved these changes Jun 5, 2026
Comment thread docs/guides/dpo.md Resolved
Comment thread docs/guides/rm.md Resolved
Comment thread docs/guides/sft.md Resolved
Co-authored-by: Yuki Huang <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
@yuki-97

yuki-97 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

/ok to test 34e44c0

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Jun 5, 2026
@yuki-97
yuki-97 merged commit 9ba6b1b into NVIDIA-NeMo:main Jun 5, 2026
74 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Jun 5, 2026
pengdurice pushed a commit to pengdurice/RL that referenced this pull request Jun 12, 2026

This branch was previously deployed

2 inactive deployments
test — 34e44c0e Deployed Jun 5, 2026 by copy-pr-bot[bot] via Wait in test approval queue #11994
public — 34e44c0e Deployed Jun 5, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) community-request Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing dataset classes defined outside of NeMo-RL

3 participants