Repository navigation
Studio drafter: split TRL packed rows at seq_lengths, reattach a Hub full fine-tune's MTP head on export - #14911
Conversation
…full fine-tune's MTP head on export
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 758b34319c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| manifest = training_manifest(checkpoint_path) | ||
| token = getattr(self, "_checkpoint_token", None) | ||
| # A Hub id reads its manifest from the Hub with the load's credential. | ||
| manifest = training_manifest(checkpoint_path, token) |
There was a problem hiding this comment.
Pin the manifest lookup to the loaded revision
When a Hub repository's default branch advances after the model load resolves its commit, this call fetches drafter.json from the new branch head because training_manifest() ultimately calls hf_hub_download() without revision, while _loaded_hub_snapshot() then selects shards from current_model.config._commit_hash. This can either skip a valid trained head or attach an older head based on a manifest from a different checkpoint. Pass the loaded commit through the manifest lookup so both artifacts come from the same revision.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, fixed. training_manifest() and _hub_adapter_snapshot() now take a revision, and _attach_full_checkpoint_mtp_head passes the commit the load resolved (current_model.config._commit_hash, the same value _loaded_hub_snapshot uses for the shards). The manifest and the head now always come from the same checkpoint, even if the branch moves after the load. Added test_hub_full_fine_tune_manifest_is_read_at_the_loaded_commit, which fails without the fix.
| manifest = training_manifest(checkpoint_path) | ||
| token = getattr(self, "_checkpoint_token", None) | ||
| # A Hub id reads its manifest from the Hub with the load's credential. | ||
| manifest = training_manifest(checkpoint_path, token) |
There was a problem hiding this comment.
Keep the manifest probe offline with cached loads
When _hf_offline() selects a cached Hub load because the endpoint is unreachable without an offline environment flag, the model loader receives local_files_only=True, but this new manifest lookup runs afterward and ultimately calls hf_hub_download() without local_files_only. Consequently, loading any cached full model can block on Hub connection timeouts while probing for drafter.json, defeating the fast offline fallback even when the model and relevant manifest are already cached. Thread the load's offline decision into the manifest lookup.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, fixed. load_checkpoint now records its local_files_only decision (the _hf_offline() result, so it covers the HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE env vars and the unreachable endpoint probe), and the manifest lookup passes it through to hf_hub_download. A cached load with the Hub down reads drafter.json from the cache and never waits on connection timeouts. The flag is reset on unload along with the token. Added test_offline_hub_full_fine_tune_keeps_the_manifest_probe_offline and test_load_records_its_offline_decision_for_the_manifest_probe, which both fail without the fix.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…aded commit and offline when the load was [skip ci]
…ckaging The merged, GGUF and LoRA packaging paths now pass the commit the load resolved and its offline decision to training_manifest, so a Hub branch that advanced after loading cannot pair the exported weights with a newer manifest or drop the drafter metadata. [skip ci]
…mmit, not the base's current_model.config._commit_hash names the base repo for a LoRA adapter, so reading the adapter's drafter.json at it 404'd and dropped the drafter metadata. Record the adapter's cached snapshot commit at load time (offline, from the HF cache); pass no revision when it cannot be told. Full fine-tunes keep the config commit. [skip ci]
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Two gaps in the drafter flow from #13806.
Packed rows were one drafter example
_row_examplessplit a packed row only whereposition_idsrestart at 0. TRL's packed dataset (pack_dataset(..., strategy="bfd"), used bypacking=True) stores the boundaries asseq_lengthsand only buildsposition_idslater in its collator, so the rows the drafter phase reads fromtrainer.train_datasethave noposition_ids. With packing on, every packed row became one long example: the drafter was trained across unrelated documents, anddata_source="regenerate"found only the first prompt of each packed row._row_examplesnow cuts atseq_lengthswhen they add up to the row length, and still falls back toposition_idsfor older layouts. Rows packed with thewrappedstrategy carry no boundaries, as before.Hub full fine-tunes lost their trained MTP head on export
_attach_full_checkpoint_mtp_headreturned early for anything that is not a local folder, so loading a full fine-tune with a trained MTP head by Hub id never reattached it. transformers drops themtp.*tensors on load, the merged save only stitches an attached head, andpackage_mergedstill wrote an MTPdrafter.jsonnext to a model whose config had its MTP declaration stripped.The manifest is now read with
training_manifest(checkpoint_path, token), which already resolves Hub ids with the load's credential, and the head is loaded from the local snapshot the load just cached (found throughconfig.jsonat the loaded commit,local_files_only=True), so a private repo needs no extra credential plumbing and nothing large is downloaded. Local folders behave as before.Tests
studio/backend/tests/test_drafter_training.py:test_examples_split_trl_packed_rows_at_seq_lengthspacks three documents with real TRLpack_datasetand checks one example per document, each with its own mask and prompt. On main it gets two examples, one of them spanning two documents.test_export_reattaches_the_head_of_a_hub_full_fine_tuneloads by Hub id and checks the head is attached from the cached snapshot at the loaded commit with the load's token, and nothing is attached without a manifest. On mainget_mtp_headis never called.Both fail on main and pass here;
test_drafter_training.pyandtest_drafter_launch_flags.pypass (75).Not covered: a real Hub full fine-tune exported end to end, and the separate case where both
completion_maskandassistant_masksare present (onlycompletion_maskis applied).