Skip to content

Studio drafter: split TRL packed rows at seq_lengths, reattach a Hub full fine-tune's MTP head on export - #14911

Merged
danielhanchen merged 8 commits into
mainfrom
dh/drafter-packed-rows-hub-mtp
Oct 25, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
dh/drafter-packed-rows-hub-mtp

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Two gaps in the drafter flow from #13806.

Packed rows were one drafter example

_row_examples split a packed row only where position_ids restart at 0. TRL's packed dataset (pack_dataset(..., strategy="bfd"), used by packing=True) stores the boundaries as seq_lengths and only builds position_ids later in its collator, so the rows the drafter phase reads from trainer.train_dataset have no position_ids. With packing on, every packed row became one long example: the drafter was trained across unrelated documents, and data_source="regenerate" found only the first prompt of each packed row.

_row_examples now cuts at seq_lengths when they add up to the row length, and still falls back to position_ids for older layouts. Rows packed with the wrapped strategy carry no boundaries, as before.

Hub full fine-tunes lost their trained MTP head on export

_attach_full_checkpoint_mtp_head returned 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 the mtp.* tensors on load, the merged save only stitches an attached head, and package_merged still wrote an MTP drafter.json next 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 through config.json at 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_lengths packs three documents with real TRL pack_dataset and 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_tune loads 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 main get_mtp_head is never called.

Both fail on main and pass here; test_drafter_training.py and test_drafter_launch_flags.py pass (75).

Not covered: a real Hub full fine-tune exported end to end, and the separate case where both completion_mask and assistant_masks are present (only completion_mask is applied).

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread studio/backend/core/export/export.py Outdated
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread studio/backend/core/export/export.py Outdated
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T06:08:48.133775Z ee593cb Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…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]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…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]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 91754b12c9

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: ee593cbedc

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 25, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 25, 2026
@danielhanchen
danielhanchen merged commit 40290cf into main Oct 25, 2026
0 of 34 checks passed
@danielhanchen
danielhanchen deleted the dh/drafter-packed-rows-hub-mtp branch October 25, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant