Skip to content

Studio: enable packing and assistant-only training defaults where supported - #15478

Merged
danielhanchen merged 9 commits into
mainfrom
fix/assistant-completions-default
Oct 27, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
fix/assistant-completions-default

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Studio initialized both sequence packing and Assistant completions only to false. Every shipped model recipe also defaulted packing off, and vision/audio dataset selection could overwrite an enabled assistant-only choice. Fresh chat-training configurations now enable both options wherever the selected objective and data path support them.

Normalize automatic model recommendations independently of explicit user configuration, so a legacy recipe's false does not override the enabled defaults. Keep user toggle choices, imported YAML false, restored run settings and their persistence distinct from automatic capability changes. Reset to model defaults clears those choices. Unanswered assistant-only defaults return after leaving raw-text or streaming mode. Image/audio chat VLMs retain assistant masking without a model-family whitelist; image/audio collators still do not pack, and standalone speech, embedding/decision, raw/CPT, streaming masking and text-diffusion packing restrictions remain enforced.

Align frontend initial defaults, omitted API/worker options, token preview and starter YAML recipes. Model-specific YAML is normalized only when serving automatic model-picker recommendations; importing that YAML still preserves its literal choices. Older saved drafts have no reliable user-choice provenance, so existing saved false values are conservatively retained. Use Reset to defaults for an old draft to adopt the new defaults.

Validation: 67 frontend store/persistence/restore/default-policy tests and 81 backend defaults/streaming/model-config/completion-mask tests passed; one optional backend test skipped. Two existing cache-fixture tests require Windows symlink privileges and were excluded after failing in fixture setup with WinError 1314. Frontend typecheck including tests, Ruff and git diff --check passed. No model weights were loaded or GPU training started for validation.

Updated on main 9d184f3. This extends the original assistant-only VLM fix with the requested enabled packing and assistant defaults.

UI before / after

Studio > Train > Training Hyperparameters > Memory on a fresh install, merge base vs this PR (same journey, Tesla T4). "Enable packing" now starts checked. The journey ticks "Assistant completions only" itself, so that box matches on both sides.

Memory tab before and after

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T14:03:33.217066Z 6569a40 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.

@danielhanchen danielhanchen changed the title Studio: keep assistant-only training enabled for vision datasets Studio: enable packing and assistant-only training defaults where supported Oct 27, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Frontend build + bundle sanity and Frontend unit tests (Windows) fail here on three tests that pass on main (22 of 22 in the same files at a1064bb), so they follow this PR's new training defaults (job 122010507004):

  • tests/advanced-settings-summary.test.ts: "advanced settings summary uses method-aware LoRA defaults"
  • tests/training-start-payload-drafter.test.ts: "persisted state from before drafter training migrates to the feature off"
  • tests/training-config-roundtrip.test.ts: "a partial import patches only the keys the file names"

With packing and assistant-only on by default, the default-derived values these tests compare against have moved. If the new defaults are the intended behaviour, the expectations in those three tests need updating in this PR (and the migration test should still show a pre-drafter persisted state lands with the feature off).

@danielhanchen

Copy link
Copy Markdown
Member Author

One more PR-specific red: (Python 3.13, rest) fails 12 tests in studio/backend/tests/test_studio_train_validation.py (job 122010507786). They pass on main (38 of 38 at 63939ab). That file validates single fields through TrainingStartRequest.__pydantic_validator__.validate_assignment(TrainingStartRequest.model_construct(), ...), and the new _default_training_objective_toggles validator at models/training.py:719 reads self.training_type, which a model_construct() instance does not have:

AttributeError: 'TrainingStartRequest' object has no attribute 'training_type'

Reading it with getattr(self, "training_type", None) (and the same for any other field the validator reads) keeps single-field assignment validation working.

The Repo tests (CPU, rest) failure here is a main issue, fixed by #15493.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@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: 811508b669

ℹ️ 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 on lines +3992 to +3993
packing: bool = True,
train_on_completions: bool = True,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Make the masking length check packing-aware before enabling both

For text chat datasets whose examples are substantially shorter than the context length, enabling packing and completion masking together makes default training abort before the first step. UnslothTrainer constructs the packed SFTTrainer dataset, then its post-masking check compares len(self.trainer.train_dataset) against the original unpacked dataset length (trainer.py, lines 5057–5067). Packing 100 valid conversations into 10 sequences therefore reports 90% of samples as having no trainable response tokens and returns an error, even if masking discarded nothing. Compare against the processed dataset length immediately before masking, rather than the original row count, before enabling this combination by default.

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.

Fixed in 0b525a9: the drop check now compares against the trainer's dataset length right before masking (packed rows when packing is on). Reproduced the mismatch on a T4: 64 chat rows pack into 3 rows with identical trainable tokens (1087 vs 1087), which the old check read as 61/64 dropped.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 0b525a916e

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

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

2 similar comments
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 6569a40a4f

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

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 27, 2026
@danielhanchen
danielhanchen merged commit e047171 into main Oct 27, 2026
59 of 68 checks passed
@danielhanchen
danielhanchen deleted the fix/assistant-completions-default branch October 27, 2026 15:59
danielhanchen added a commit to Etherll/unsloth that referenced this pull request Oct 28, 2026
…t's path guard (unslothai#15727)

When compatible OpenAI fine-tuning jobs are queued, `_start_queued`
probes the head job's model (`_trains_alone`) to decide whether it can
join a multi-LoRA batch. That probe ran with the raw `model_name`,
before the account's path guard and outside the job's account context. A
managed account could queue two batchable jobs whose model is a UNC path
(`\\host\share\model` or `//host/share/model`); on a Windows host the
probe's file checks then open that share, which makes the Studio service
account sign in over SMB and hands its NetNTLM response to that host.

`account_path` already refuses share and device paths for managed
accounts before touching the filesystem, and `start_training` applies
it, but the batch probe ran first.

## Fix

- The probe calls `account_path(model_name, reference = True)` first. A
path the account may not use makes the job train alone, so the normal
single start refuses it with the usual 403.
- `_start_queued` runs the probe under `arun_as(entry.account, ...)`, so
it sees the job's account rather than the drain loop's.

Owners, Desktop and notebooks are unaffected (`account_path` returns
early for the owner). Managed accounts still batch Hub ids and workspace
paths exactly as before. The check is a pure lookup, so repeated drains
behave the same.

## Tests

- `test_batch_probe_never_touches_a_managed_share_path` (both UNC
spellings): fails on main (the diffusion, LoRA and config probes all
receive the share path), passes here.
- `test_batch_probe_unchanged_for_the_owner`: the owner's jobs still
probe and batch.
- `test_openai_fine_tuning.py`: the same 10 tests fail as on main, all
multi-LoRA batching tests that fail since packing became the default
(unslothai#15478 landed before unslothai#15344); 67 pass. Account path suites: 880 passed.
danielhanchen added a commit to Etherll/unsloth that referenced this pull request Oct 28, 2026
…documents (unslothai#15733)

Since unslothai#15478 turned packing on by default, every queued fine-tuning job
asks for packing, and unslothai#15344 sent packing jobs to train alone. So
compatible jobs stopped batching at all, and three batching tests in
`studio/backend/tests/test_openai_fine_tuning.py` fail on main
(`test_compatible_queued_jobs_start_as_one_batch`,
`test_jobs_differing_only_in_member_fields_batch_in_queue_order`,
`test_only_plain_dense_models_batch[dense]`).

This PR lets packing jobs batch, with packing kept per job so a job's
documents never meet another job's:

* Each member packs only its own documents, with TRL's default packing
strategy at the run's max length, the same packing its single run would
get. Pre-tokenized datasets stay unpacked, as in the single run.
* Once any member packs, each micro-batch is one padding-free row, as in
the single packed run: positions restart at every document,
`packed_seq_lengths` is passed to the model, every token is routed to
its own member's adapter, and the label opening each document is masked
so nothing is predicted across a boundary. A document never spans two
members.
* Packing is used only where the single job's Unsloth SFTTrainer would
pack: not on padding-free blocklisted models, encoder-decoders, forwards
that cannot take `packed_seq_lengths`, or hybrid linear-attention models
whose varlen kernels are not available (their recurrent state would
carry across documents). Elsewhere packing is ignored, as the single job
ignores it.
* Packing is also used only where a packed forward provably keeps
documents apart: before packing, one forward of a short document after
another in one packed row is compared with that document alone, and a
model whose packed documents see each other trains unpacked with a
warning. Qwen3.5 on transformers 5.3 (Studio's tier for it) passes every
static check above, yet its full attention layers let packed documents
attend across the boundary (logits off by up to 14.7 against 0.36
elsewhere); the root cause is fixed in core by unslothai#15771, and this check
keeps batched jobs isolated on any install that lacks it.
* Vision-language models (Qwen3.5, Qwen3.6) tokenize their text through
the processor's tokenizer, as the single job does; the full processor is
still what gets saved.
* `packing` is now a per-member field, so packed and unpacked jobs can
share a batch; an unpacked member in a packed batch trains exactly as it
would alone.

Tests (CPU, tiny Qwen3;
`studio/backend/tests/test_multi_lora_trainer.py`):

* a packing member's losses and saved adapter are the same with a
different neighbour and alone, and every packed document holds one
adapter's tokens with positions restarting at each;
* an unpacked member beside packed ones matches its own run;
* packing is ignored when the model cannot pack; a hybrid packs only
with its varlen kernels;
* packed rows keep each document's labels with its tokens.

Negative control: with positions not restarting per document, the
isolation checks fail. All of `test_multi_lora_trainer.py`,
`test_openai_fine_tuning.py` and `test_training_batch_backend.py` pass
(113).

GPU, through the OpenAI-compatible API on a fresh `install.sh --local`
Studio (Qwen3-0.6B, 4-bit and 16-bit; a job trained alone, then the same
job batched beside another while a third holds the GPU; 16 documents, 20
steps, packing on by default):

| GPU | mode | batched job packed | steps alone / batched | step 1 loss
alone / batched | final loss alone / batched | learning rate |
|---|---|---|---|---|---|---|
| RTX PRO 6000 (bf16) | 4-bit | 16 documents into 1 row | 20 / 20 |
2.2689 / 2.2807 | 0.00017 / 0.00027 | identical every step |
| RTX PRO 6000 (bf16) | 16-bit | 16 documents into 1 row | 20 / 20 |
2.6012 / 2.5983 | 0.00016 / 0.00019 | identical every step |
| T4 (fp16) | 4-bit | 16 documents into 1 row | 20 / 20 | 2.2761 /
2.2772 | 0.00058 / 0.00020 | see below |
| T4 (fp16) | 16-bit | 16 documents into 1 row | 20 / 20 | 2.6012 /
2.6012 | 0.00017 / 0.00015 | see below |

The single run packed too ("Unsloth: Packing enabled") on every arm. On
the T4 the learning-rate schedules drift apart after the single run
skips a step on an fp16 overflow while the batched job does not; that
comes from the batch sharing one fp16 loss scale, which is on main
already and is fixed separately in unslothai#15741.
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