[2/5] feat: cross-tokenizer collator, Arrow dataset, and eval datasets#2348
Closed
avenkateshha wants to merge 3 commits into
Closed
Conversation
This was referenced Apr 27, 2026
Foundational library code for cross-tokenizer distillation. No algorithm
or training-loop integration yet — those follow in subsequent PRs.
- nemo_rl/algorithms/x_token/tokenalign.py: TokenAligner(nn.Module) with
Numba-accelerated DP alignment, projection-matrix loading
(dense and sparse COO), and the project_token_likelihoods_instance
forward path used by the cross-tokenizer loss.
- nemo_rl/algorithms/x_token/__init__.py: package init.
- nemo_rl/utils/x_token/{minimal_projection_generator,
minimal_projection_via_multitoken,reapply_exact_map,
sort_and_cut_projection_matrix}.py: standalone CLI scripts
(argparse-driven, __main__ entrypoints) for one-time projection-matrix
preparation. Not on the training import path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Adithyakrishna Hanasoge <avenkateshha@nvidia.com>
7e19a1c to
66eb138
Compare
Data-layer plumbing for cross-tokenizer off-policy distillation, plus
in-training eval datasets. Builds on the TokenAligner package from the
prior PR.
- nemo_rl/data/cross_tokenizer_collate.py: CrossTokenizerCollator and
TeacherCTSpec. Runs in StatefulDataLoader worker processes — does
per-teacher tokenize + DP alignment up front so the train loop only
consumes pre-built per_teacher_ct_data. Lazy-imports TokenAligner so
workers that don't need cross-tokenizer never touch x_token.
- nemo_rl/data/__init__.py: add NotRequired prefetch_factor to DataConfig.
- nemo_rl/data/datasets/response_datasets/arrow_text_dataset.py:
ArrowTextDataset with lazy packing, registered as "arrow_text" in
DATASET_REGISTRY.
- nemo_rl/data/datasets/eval_datasets/{humaneval_plus,mbpp_plus,mmlu}.py
and registry entries: in-training eval datasets. mmlu.py adds an
optional num_few_shot argument with a static _build_few_shot_prefixes
helper; default of 0 preserves existing behavior.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Adithyakrishna Hanasoge <avenkateshha@nvidia.com>
66eb138 to
5934699
Compare
Follow-up to the TokenAligner refactor on 01-tokenaligner that dropped align_fast() / precompute_canonical_maps(). The collator was the only non-trivial caller of those APIs. - Dropped TeacherCTSpec.use_align_fast (typed-dict field). - Removed the precompute_canonical_maps() call in _lazy_init — that helper no longer exists on TokenAligner; align() does the full sequence-level canonicalization on each call. - Replaced the use_align_fast if/else branch with the unconditional aligner.align(s_t, t_t, chunk_size=dp_chunk_size) DP path. Behavior: alignment for sequences containing encoding-artifact or byte tokens may differ slightly because align() runs _merge_encoding_artifacts / _merge_consecutive_bytes (the cached per-token canonical maps used by align_fast skipped these). For pairs without those tokens, results are identical. Small per-batch CPU bump in the collator workers since canonical strings are no longer cached per id. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Adithyakrishna Hanasoge <avenkateshha@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Data-layer plumbing for cross-tokenizer off-policy distillation, plus in-training eval datasets. Builds on the
TokenAlignerpackage from PR 1.nemo_rl/data/cross_tokenizer_collate.py:CrossTokenizerCollatorandTeacherCTSpec. Runs inStatefulDataLoaderworker processes — does per-teacher tokenize + DP alignment up front so the train loop only consumes pre-builtper_teacher_ct_data. Lazy-importsTokenAlignerso workers that don't need cross-tokenizer never touchx_token.nemo_rl/data/__init__.py: addNotRequiredprefetch_factortoDataConfig.nemo_rl/data/datasets/response_datasets/arrow_text_dataset.py:ArrowTextDatasetwith lazy packing, registered as"arrow_text"inDATASET_REGISTRY.nemo_rl/data/datasets/eval_datasets/{humaneval_plus, mbpp_plus, mmlu}.pyand registry entries: in-training eval datasets.mmlu.pyadds an optionalnum_few_shotargument with a static_build_few_shot_prefixeshelper; default of 0 preserves existing behavior.What does this PR do?
Adds the data-layer plumbing (collator + Arrow dataset) consumed by the cross-tokenizer distillation training loop, plus HumanEval+/MBPP+/MMLU eval datasets used for in-training evaluation.
Issues
None linked yet.
Usage
Before your PR is "Ready for review"
py_compileconfirmed clean. Full functional run lands with PR 5.Additional Information
Stacked on PR 1 (TokenAligner) — #2347. Imports
TokenAlignerlazily so workers without CT teachers don't pay the cost.Full chain: