Repository navigation
Studio: prepare decision datasets faster, in less memory, with row progress - #16106
Merged
Merged
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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
danielhanchen
pushed a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 30, 2026
danielhanchen
added a commit
that referenced
this pull request
Oct 30, 2026
…6123) `Repo tests (CPU, rest-2)` is red on main since #16106 (prepare decision datasets faster, in less memory, with row progress). It fails on unrelated PRs, for example #16114: ``` tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[14] AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding ... 'studio/backend/tests/test_decision_dataset_prefetch.py:298: read_text()' ``` `_frontend_regex` reads `studio/frontend/src/features/studio/preparation-progress.ts` with `read_text()`. On Windows that decodes as cp1252 and breaks as soon as the file gains a non-ASCII byte. The guard is right and the test was wrong, so this adds `encoding = "utf-8"`. This is the same fix #16025 made for #15996. ## Verification - `tests/test_source_read_encoding.py`: fails on main on the line above. 16 passed here. - `studio/backend/tests/test_decision_dataset_prefetch.py`: 11 passed.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Decision fine-tuning in Studio could sit on "Preparing decisions..." for the better part of an hour on a large dataset, with nothing on screen moving. A user training
CNWPlayer/Vega-1.6-128M-Baseontasksource/procedural-typed-decisions(configall, 396k rows, 293 MB) saw the model row stuck on "Preparing decisions" and restarted, thinking it had hung.What was going on
FastDecisionModel.build_datasetruns the vendored Clefencode_recordonce per row. That function tokenizes about 70 short strings per row, one tokenizer call each ("OPTION 1: ","\n","END FIELD\n", the field headers, the fixed system prompt). Nearly all of them repeat on every row, so the time goes to the tokenizer wrapper, not to real work: about 4.5 ms per row, single core.item["input_ids"]andrecord.input_ids. That is about 54 KB per row, so roughly 20 GB of RAM for this dataset before training starts.Changes
unsloth/models/decision.py:_clef_itemshandsencode_recorda small memoizing tokenizer (_MemoTokenizer). It cachesadd_special_tokens=Falseresults for strings up to 512 characters (the unique per-row state text skips the cache), caps the cache size, returns a fresh list on every call (encode_recordextends the first list it gets), and interns token ints so the stored ids share one int object per token id. Anything other than the exact callencode_recordmakes passes straight through to the real tokenizer. The vendored Clef file is untouched;build_dataset's signature and item types are unchanged.studio/backend/core/training/decision_trainer.py: rows are passed tobuild_datasetas_ProgressRows, alistthat reportsPreparing decision rows P% (n/total)at most once a second while the builder reads it, and checks for a stop on every row. The frontend already renders that exact shape as a determinate bar, and the word "rows" files it under the Dataset row, so there is no frontend change. Evaluation rows get their ownPreparing evaluation rowslabel. This works for the CUDA and MLX builders alike, since both read the rows once in order.Results
Real rows, the first
alltrain shard (120,000 rows, 389,823 decisions),CNWPlayer/Vega-1.6-128M-Basetokenizer, transformers 5.3.0, Studio's own question validation included. Each arm runs its own tree (asserted from the imported module paths):8980a121...8980a121...(identical)For the full 360k-row train split that is about 27 minutes and ~20 GB on main versus about 10 minutes and ~12 GB here, with a live progress bar the whole way.
The built dataset is byte-identical: the same token ids, question and option spans, targets and labels on every row.
Tests
tests/test_decision_model.py::test_clef_items_tokenize_each_repeated_string_once:_clef_itemsoutput equals plain per-rowencode_record, and every distinct string reaches the tokenizer once. On main it makes 888 tokenizer calls for 46 distinct strings, so it fails there.tests/test_decision_model.py::test_memo_tokenizer_returns_fresh_lists_and_passes_other_calls_through: mutating a returned list cannot corrupt the cache; long strings are not cached; other call shapes behave like the real tokenizer.studio/backend/tests/test_decision_dataset_prefetch.py: the progress messages parse with the frontend's ownCOUNTED_PREPARATION_REand classify as dataset work under itsDATASET_PREPARATION_RE(both read frompreparation-progress.ts, so the two sides cannot drift); a stop raised mid-read ends the build. Both fail on main.Not changed: the MLX tokenization path (it goes through unsloth_zoo's pipeline), the training step, and the Laya layout.
Screenshots
Studio's training-start overlay 20 seconds into preparing 40,000 real rows of
tasksource/procedural-typed-decisions, from two separate Studio installs built from the merge base (left) and this branch (right). The run is a real decision training run throughPOST /api/train/starton a small local Laya checkpoint. This host has no GPU, so Studio was started withUNSLOTH_ALLOW_CPU=1and the page's GPU check was answered as present so that the Train page opens; everything else on screen comes from the running backend.Left: one "Preparing decisions" step on the Model weights row for the whole build. Right: the same step on the Dataset row with a live percent, row count and bar. In the same run on Studio's worker, main sent 1 status during the ~145 seconds of preparation and this branch sent 147 (one a second); both runs ended with the same held-out accuracy (0.29 -> 0.32) and calibration error (0.07).