Repository navigation
[4/8] Add the sparse teacher-policy training path #2638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,383
−31
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -74,6 +74,14 @@ def make_speculative_data_module( | |||||||
| aux_hidden_states_optional: accept dumps written with ``--no-aux-hidden-states``. | ||||||||
| Only modes that never read the aux planes may set this. | ||||||||
| """ | ||||||||
|
|
||||||||
| # Validated once for every mode: each branch consumes sample_size differently | ||||||||
| # (row select, shard slice, dataset limit) but the contract is the same. | ||||||||
| # getattr: data_args is duck-typed across callers and some supply only the fields | ||||||||
| # their own mode reads, so a hoisted check must not demand one they never set. | ||||||||
| sample_size = getattr(data_args, "sample_size", -1) | ||||||||
| if sample_size == 0 or sample_size < -1: | ||||||||
| raise ValueError("sample_size must be -1 (use all samples) or a positive integer") | ||||||||
| # Load chat template from file if provided | ||||||||
| chat_template = None | ||||||||
| if getattr(data_args, "chat_template", None): | ||||||||
|
|
@@ -155,6 +163,41 @@ def make_speculative_data_module( | |||||||
| chat_template=chat_template, | ||||||||
| ) | ||||||||
|
|
||||||||
| elif mode == "sparse": | ||||||||
| # Sparse teacher policy: the dump stores the base's top-k deployment | ||||||||
| # distribution per response token instead of its hidden states, so no base | ||||||||
| # forward (and no base lm_head) is needed at train time. Only the TVD | ||||||||
| # objectives can consume it -- soft_ce wants full logits. | ||||||||
| # Imported here, like the streaming dataset above, so the other modes do not | ||||||||
| # pay for a module only this branch uses. | ||||||||
|
Comment on lines
+171
to
+172
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit, still open from my first pass: since you kept the
Suggested change
|
||||||||
| from modelopt.torch.speculative.external.sparse_data import ( | ||||||||
| SparsePolicyCollator, | ||||||||
| SparsePolicyDataset, | ||||||||
| discover_shards, | ||||||||
| ) | ||||||||
|
|
||||||||
| print_rank_0("Loading sparse teacher-policy data for external draft training...") | ||||||||
| assert not data_args.vlm_processor, "Sparse data is not supported for VLM." | ||||||||
| # Shared with the pre-build instructions: a hand-built cache is only reused if it | ||||||||
| # was keyed on the same shard list, so discovery lives in one place. | ||||||||
| files = discover_shards(data_args.sparse_data_path) | ||||||||
| if not files: | ||||||||
| raise ValueError(f"No .jsonl.gz or .jsonl files found in {data_args.sparse_data_path}") | ||||||||
| train_dataset = SparsePolicyDataset( | ||||||||
| files, | ||||||||
| max_length=train_len, | ||||||||
| limit=data_args.sample_size if data_args.sample_size > 0 else None, | ||||||||
| source_weights=data_args.sparse_source_weights, | ||||||||
| cache_dir=data_args.sparse_cache_dir, | ||||||||
| ) | ||||||||
| print_rank_0( | ||||||||
| f"Loaded {len(train_dataset)} records from {len(files)} shard(s), " | ||||||||
| f"teacher top-k={train_dataset.top_k}" | ||||||||
| ) | ||||||||
| if data_args.sparse_source_weights: | ||||||||
| print_rank_0(f"[sparse] source weights applied: {data_args.sparse_source_weights}") | ||||||||
| data_collator = SparsePolicyCollator(train_len=train_len) | ||||||||
|
|
||||||||
| else: | ||||||||
| print_rank_0("Loading pre-processed data for offline training...") | ||||||||
| assert not data_args.vlm_processor, "Offline data is not supported for VLM." | ||||||||
|
|
@@ -165,8 +208,6 @@ def make_speculative_data_module( | |||||||
| raise ValueError(f"No .pt files found in {data_args.offline_data_path}") | ||||||||
|
|
||||||||
| # sample_size=-1 means use all samples; positive integer selects that many | ||||||||
| if data_args.sample_size == 0 or data_args.sample_size < -1: | ||||||||
| raise ValueError("sample_size must be -1 (use all samples) or a positive integer") | ||||||||
| if data_args.sample_size > 0: | ||||||||
| dumped_files = dumped_files[: data_args.sample_size] | ||||||||
| train_dataset = OfflineSupervisedDataset( | ||||||||
|
|
||||||||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.