Skip to content

feat: Pass tokenizer_kwargs to AutoTokenizer.from_pretrained - #3798

Merged
terrykong merged 3 commits into
NVIDIA-NeMo:mainfrom
pstjohn:u-1-tokenizer-kwargs
Aug 25, 2026
Merged

terrykong merged 3 commits into
NVIDIA-NeMo:mainfrom
pstjohn:u-1-tokenizer-kwargs

Conversation

@pstjohn

@pstjohn pstjohn commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Adds tokenizer_kwargs to TokenizerConfig

get_tokenizer() currently constructs tokenizers with only the model name and trust_remote_code=True:

tokenizer = AutoTokenizer.from_pretrained(
    tokenizer_config["name"], trust_remote_code=True
)

There is no config route for passing additional from_pretrained kwargs — for example fix_mistral_regex=False for tokenizer artifacts that already carry a corrected Mistral regex pretokenizer. A caller that needs this must monkeypatch AutoTokenizer.from_pretrained in every process, including inside isolated Ray workers where tokenizers are constructed after the actor has started.

This PR adds tokenizer_kwargs to TokenizerConfig and threads it through both get_tokenizer() implementations. When tokenizer_kwargs is absent or None, behaviour is unchanged: .get("tokenizer_kwargs") or {} produces an empty unpacking.

@pstjohn
pstjohn requested review from a team as code owners August 24, 2026 16:29
@copy-pr-bot

copy-pr-bot Bot commented Aug 24, 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.

@pstjohn pstjohn changed the title Pass tokenizer_kwargs to AutoTokenizer.from_pretrained feat: Pass tokenizer_kwargs to AutoTokenizer.from_pretrained Aug 24, 2026
Adds the option to pass additional arguments to the pretrained
tokenizer.

Signed-off-by: Peter St. John <[email protected]>
@pstjohn
pstjohn force-pushed the u-1-tokenizer-kwargs branch from c6265b3 to 1bab67f Compare August 24, 2026 16:40
@copy-pr-bot

copy-pr-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

rohitrango
rohitrango previously approved these changes Aug 24, 2026

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

LGTM

terrykong
terrykong previously approved these changes Aug 24, 2026

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed with a team of specialised agents plus an adversarial pass. The core change is sound and worth having: fix_mistral_regex is a real transformers kwarg with no other route through get_tokenizer today, and threading it through config rather than a monkeypatch is the right call, especially for DTensor-v2 workers that rebuild the tokenizer locally from config.

Four comments below: one that blocks (the new test cannot pass on any pinned transformers version), one coverage gap (the processor branch, which is the half of the VLM/multimodal flow the change misses), one convention item, and one optional follow-up.

Generated by Claude Code

Comment thread tests/unit/algorithms/test_utils.py Resolved
Comment thread nemo_rl/algorithms/utils.py Resolved
Comment thread nemo_rl/models/automodel/setup.py Resolved
Comment thread nemo_rl/models/policy/__init__.py Resolved
@pstjohn
pstjohn dismissed stale reviews from terrykong and rohitrango via 140bdcb August 24, 2026 22:48
@terrykong terrykong added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Aug 25, 2026
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 140bdcb

@terrykong
terrykong enabled auto-merge (squash) August 25, 2026 05:39
@terrykong
terrykong merged commit a8d4c4e into NVIDIA-NeMo:main Aug 25, 2026
83 checks passed
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants