Repository navigation
Studio: keep every turn when training a chat dataset with Alpaca format - #11053
Conversation
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. |
|
Codex Review: Didn't find any major issues. Swish! 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". |
Review + UI evidencePinned head: Review fix (Codex P2, genuine). When Studio trains a vision-capable model on a text dataset (for example Gemma 3), the tokenizer is a processor, so chat standardization turns every message into a list of text parts. Structured ChatML datasets arrive the same way. The first commit joined the system prompt as a string and raised
GitHub Actions A/B (same workflow, fresh upstream main
Studio UI, before/after. Real Studio on an NVIDIA L4 (Chromium 1440×900). Each side trained
Neither side changes the frontend, so both use the same build. Each side served its own backend checkout. Conclusion: on main, Alpaca target format dropped the system prompt and every turn after the first. This PR trains on all 24 replies, and it now also handles processor tokenizers and structured content. Codex approved Fork CI (full official workflows, fresh upstream main |
|
Confirmed this hits format_conversion.py where the Alpaca conversion keeps only the first user and assistant message and always leaves input empty, so the system prompt and later turns never reach training. Will get this reviewed. |
|
Reviewed Verdict: issue REAL | PR as submitted: CORRECT | merge: YES. Two follow-ups below, neither blocking. The bug, reproduced on mainI wrote a probe independent of your tests and ran it against both trees so a bug in the tests could not hide a bug in the code. 8 conversations, system prompt plus 3 turns each:
Two of those are fixes you did not claim in the description. Main does not just drop turns on a structured-content dataset, it trains on the stringified dict; and a chat column containing a null conversation crashes the conversion outright on main. I also checked the layout against Tests and lint
Real training run, B200,
|
| Arm | Rows | Steps | Peak mem | Tokens/s | Losses (1st,2nd,3rd..last2) | Grad norms |
|---|---|---|---|---|---|---|
| main, 8 convos x 3 turns | 8 | 8 | 1.17 GB | 59.8 | 3.098, 3.017, 1.741 .. 0.471, 0.367 | 15.73, 15.41, 16.507 .. 3.35, 3.263 |
| PR, 8 convos x 3 turns | 24 | 24 | 1.17 GB | 271.4 | 2.694, 2.679, 1.874 .. 0.112, 0.114 | 13.082, 13.299, 7.552 .. 1.806, 1.635 |
| main, 4 convos x 40 turns | 4 | 4 | 1.21 GB | 159.6 | 1.132, 1.13, 0.674, 0.674, 0.556 | 4.963, 5.044, 5.011, 5.011, 11.5 |
| PR, 4 convos x 40 turns | 160 | 160 | 2.11 GB | 8807.9 | 0.124, 0.124, 0.12 .. 0.017, 0.003 | 0.497, 0.5, 0.481 .. 0.159, 0.02 |
3x the rows on the short dataset, both arms complete, no NaN. remove_columns is doing real work here, not cosmetics: a batched map that changes row count fails on a length mismatch without it, and nothing on this path reads the dropped columns (dataset_utils.py:615 sets chat_column = None, and _format_alpaca at chat_templates.py:276-291 reads only the three).
Two follow-ups, neither blocking
1. Eval rows leak into training inputs. split_dataset_for_evaluation (core/training/eval_dataset.py:29) calls train_test_split with shuffle on the already-expanded dataset, so turns of one conversation scatter across both splits, and a later turn carries the earlier answers verbatim in input. With 20 conversations x 3 turns (60 rows, 44 train / 16 eval) I measured 8 of the 16 eval answers appearing word for word inside a training row's input. This is new: on main input was always empty, so it could not happen. It does not corrupt training, but it makes the eval loss Studio reports optimistic. Splitting before expansion, or grouping by conversation, would fix it. Fine as a separate PR.
2. A zero-row streaming conversion raises an error with no reason in it. Zero-row conversions are newly possible (a conversation with only tool roles, or assistant-only). For a streaming dataset the next(iter(result)) probe then raises StopIteration, which except Exception catches and reports as:
ValueError: Streaming ChatML-to-Alpaca conversion failed on the first row:
Empty after the colon, because StopIteration carries no message. Main returned 4 garbage rows instead. Catching StopIteration separately and saying that no conversation produced a usable user/assistant pair would be clearer. One line. The non-streaming twin silently yields a 0-row dataset for the same input.
Smaller notes, no action needed
- Images are dropped silently:
_content_textskips non-text parts andremove_columnsnow also removes the image column. The path is reachable (a text model plus an image-bearing chat dataset, sincedataset_utils.py:806branches on the model not the data). Still a clear improvement, since main put the stringified[{'type': 'image', ...}]intoinstruction. The "Multimodal dataset detected" warning is discarded by the hardcoded"warnings": []atdataset_utils.py:611-621, which predates this PR. inputgrows with the full prefix, so long conversations get long. Measured on the 40-turn arm above: max row 5780 tokens, and 104 of 160 rows silently right-truncated at 2048. Inherent to this layout and matching the export, so I would not change it. Worth knowing that with "Train on completions" on, such a dataset can now hit the >30% dropped-samples error attrainer.py:4368; that setting is off by default and its message already points atmax_seq_length.n_rows = len(dataset)atdataset_utils.py:1018is read before conversion and reused in the progress text at line 1050, and the dataset preview reports raw rows, so the count shown will not match the steps the user gets. Cosmetic.bound_dataset_rowscaps conversations before formatting (trainer.py:3061), so amax_stepsrun now tokenizes more rows than the cap intends. Not a correctness issue.remove_columns=dataset.column_names or ...would pass a dict tomapfor aDatasetDict. Every training path names a split first so I could not reach it; sibling code guards for it explicitly (dataset_bounds.py:349,dataset_none_detect.py:484-501). Main fails on the same input too, just with a different message.- The
column_names or list(next(iter(dataset), {}))fallback pulls a row eagerly for an untypedIterableDataset. Instrumented generator: starts 2 -> 3, rows read 3 -> 4.
What I did not prove
Windows and macOS (pure Python with no platform-specific paths, so I judged the org CI sufficient); real remote streaming datasets, only local IterableDataset; and any dataset large enough for the quadratic input growth to matter at scale, since my largest was 200 turns.
Simulation: #11053 | issue: REAL | PR as submitted: DEFECTIVE, 0 fixed by me (1 silent-drop + 3 export divergences reported, none blocking) | merge: YESHead
The inverse question: is the path identical for everyone else438 cells, every role value (7 aliases,
Provably identical, not merely probably: the 400 are byte-equal on the No bare The PR cites the TypeScript export as its rationale; I ran it
The happy path matches the export exactly, which is the claim that mattered. The divergence is the new consecutive-same-role merge, which the export does not do: it takes the last user message and skips an assistant with no pending user. The third row is the sharp one. An empty user turn is dropped before pairing, so the two assistant replies become adjacent and merge, and the training target
Silent total loss on OpenAI-shaped content parts
A dataset in OpenAI Responses shape converts to nothing at all, silently. Reusing the existing helper's type list is a one-line change. This is the one finding I would call a defect in the new code's own terms rather than an edge case. Negative controls: can the PR's tests failNine mutations of the PR's own source, each run against
No vacuous pass found: nothing ran as root, no test was skipped for an absent dependency, and every assertion compares a value rather than presence. Dependency corners
8 cells, 8 resolved, 0 drift. Harness fault to declare: my first matrix run reported Cross-platform, both arms
Not VOID: the base arm shows the defect on all four resolvable platforms and the head arm is green on all four. windows-11-arm fails at This matters more than it looks: Cost5 repeats per cell, same seed and data order. The first iteration of each cell includes Arrow fingerprint warmup and is the stated noise band (a 4.3 to 4.6 s outlier on both arms).
1.6x the wall time for 20x the rows. Conversion cost is not a concern. The cost that is real is downstream: on a 4 x 40-turn dataset the branch produced 160 rows with a longest row of 5780 tokens and 104 of 160 silently right-truncated at Blast radius
Adversarial pass: a different questionThe first pass asked what the change does to the data. This one asked what it does to a user who had already converted the dataset before updating, since No finding. Same source dataset and cache directory, run base then head then base again: fingerprints What I could not prove
|
|
@codex security review |
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
…at (unslothai#11053) * Studio: keep every turn when converting chat datasets to Alpaca * Studio: read structured message content when converting chats to Alpaca --------- Co-authored-by: Daniel Han <[email protected]>

If you picked Alpaca as the Target Format for a chat dataset, training only used the first question and answer of each conversation. The system prompt and every later turn were dropped with no warning, and training still finished normally.
Each assistant reply now becomes its own Alpaca row. The user message goes in instruction, and the system prompt plus earlier turns go in input. This is the same layout Studio already uses when you export chats as Alpaca. Auto and the other formats are unchanged.
With 8 conversations that each have a system prompt and 3 turns, main trained on 8 rows with only the first turn. With this change it trains on 24 rows with every turn and the system prompt, and Auto gives the same result as main. Added unit tests that fail on main.
Before and after in Studio
Two isolated Studio installs, one built from this PR's merge base
89862daecand one from heade430d2edc, each serving its own checkout. Same local file on both sides (8 conversations, a system prompt and 3 turns each,dataset_sha256identical on both halves), same modelunsloth/Qwen2.5-0.5B-Instruct, LoRA, 1 epoch, batch 1, Target Format Alpaca. The Train tab's History card is the surface a user actually reads:89862daece430d2edcLoss: 0.9216 Steps: 8/8Loss: 0.1279 Steps: 24/24inputThe row count is the only input that moved: both sides read a byte-identical dataset file.