Skip to content

feat(studio): rework train page setup flow - #7633

Merged
danielhanchen merged 180 commits into
unslothai:mainfrom
Sneakr:feat/train-page-rework-main-adapt
Aug 6, 2026
Merged

danielhanchen merged 180 commits into
unslothai:mainfrom
Sneakr:feat/train-page-rework-main-adapt

Conversation

@Sneakr

@Sneakr Sneakr commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Reworks the train page setup flow: a new wizard for model, dataset, and parameters, shared resource pickers, cache-aware model/dataset resolution for training starts, and artifact-aware training history with deletion support.

  • UI/UX Rework
  • Replace the old train setup sections with configure, current run, and history views
  • Add a train setup wizard with model, dataset, parameters, config actions, and run preview
  • Add train-specific model and dataset pickers with Hub, cached, and local device sources
  • Add shared resource picker UI used by the train model and dataset selectors
  • Add train readiness, resource notice, model validation, model type inference, and cache reference helpers
  • Reconcile selected cached model and dataset references with the local inventory
  • Send cached model and dataset metadata in training start requests
  • Pin cached model and dataset snapshots for training starts, with Hub fallback when cached files are incomplete
  • Reject GGUF, adapter, adapter-only, and GGUF-only models from training
  • Keep dataset preview, mapping, split, streaming, S3, eval dataset, upload, and slice behavior in the new flow
  • Add simple and advanced parameter modes for train configuration
  • Move HF token handling for train-adjacent flows to the shared hub token store
  • Update onboarding and export token usage to stay in sync with the shared token
  • Add optional artifact deletion in training history with active-run and shared-output protection
  • Show missing training artifacts in history and block resume when artifacts are gone
  • Update train tour steps, train page styling, and localized copy
  • Add coverage for cached starts, cache paths, model snapshots, and history artifact deletion
  • Bug fixes and further improvements

Sneakr added 18 commits July 28, 2026 00:40
Unify model and dataset picker behavior, training start guards, and token handling.

Validate cache provenance for local models, downloaded resources, and processed datasets. Prevent stale preview and history state while keeping the train page modular.
…ork-main-adapt

# Conflicts:
#	studio/frontend/src/features/settings/index.ts
#	studio/frontend/src/i18n/locales/ja.ts
#	studio/frontend/src/i18n/locales/pt-br.ts
#	studio/frontend/src/i18n/locales/zh-CN.ts
#	tests/studio/test_model_picker_contracts.py
@Sneakr
Sneakr requested a review from danielhanchen as a code owner July 30, 2026 03:10
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Preserve local dataset path intent, localize setup-change errors, and remove unused picker tour hooks. Refresh model picker and PDF recipe contracts for the refactored training flow.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 21070e88e4

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

On the third item in that review, the cached-preview one at formatting.py L236-240: the behaviour is real, but it is not introduced here.

cached_dataset_candidates in hub/utils/dataset_cache.py ranks rather than filters on b41b819a4 as well, and diffing both the scoring function and _load_cached_hf_preview_slice against the merge-base comes back empty. prefer_local_cache and local_path are already fields on the base CheckFormatRequest, and the call site is ungated on both sides. The only change this PR makes to that path is that an explicit local_path now resolves through dataset_snapshot_from_cache_path.

So I have not changed it here. The asymmetry it points at is worth fixing on its own: _select_tier1_repo_file in the same file returns None when nothing matches the requested subset or split, while the cached path keeps location_rank = 3 candidates and previews them anyway. That is a preview-selection semantics change against main, not something to bolt onto this branch.

Deleting a run with its artifacts stages the output directory with a same-parent rename and
purges it once the database row is gone. The purge swallowed OSError while the response still
said artifacts_deleted=true, so a failed rmtree stranded every byte under the hidden randomized
.{name}.deleting-<hex> name: the row is gone by then, so nothing points at it and no retry can
rediscover it.

The purge now reports whether the bytes are actually gone, and puts the directory back under its
own name when they are not. The response says the artifacts were kept, with a purge_failed
reason, and the history grid's existing artifacts_deleted check surfaces it.

Same window, other half: when the row delete and the restoring rename both fail, the response now
names the staged path instead of raising a bare 500 that leaves the artifacts unreachable.
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 6, 2026
Aligning the picker's grammar with TrainingStartRequest went one step too far: _valid_option
started refusing ".." anywhere, for both fields. _check_split_name does reject ".." outright, so
that is right for splits, but _check_subset only constrains the charset, which means a config
directory named v1..v2 is perfectly startable and the picker was hiding it. That is the same bug
as offering an option the start request rejects, just pointing the other way.

The ".." refusal is now scoped to split names. Neither charset admits a separator, so the bare
"." and ".." names remain the only traversal shapes left to refuse for either field.

test_processed_cache_options_are_local_deduplicated_and_non_train_capable pinned the pre-change
behaviour for both names in its fixture. Its "config with spaces" entries stay dropped, since
_check_subset rejects the space and offering it turns a click into a 422, and "v1..v2" comes back.
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: cf59a7bdff

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

@BardiaKoopah

Copy link
Copy Markdown
Contributor

Closing the loop on finding 1 from my earlier testing, now that 1e65e189b has landed: I ran a real MLX stop-and-resume for the combination that could not attest before, and it works end to end.

The case is a normal 16-bit repo with the 4-bit toggle on — unsloth/Qwen3-0.6B, load_in_4bit=True, which loads as runtime_4bit. That is the Studio default on Apple Silicon, and before the fix it never attested, so resource_provenance_allows_resume returned False and the run's checkpoints were unusable no matter how intact they were.

Phase 1 — train 8 steps, save_steps=4:

provenance: attested, repo_id unsloth/Qwen3-0.6B, load_mode runtime_4bit
steps 1 .. 8, completed
checkpoints written: checkpoint-4, checkpoint-8

Phase 2 — a second run with resume_from_checkpoint pointing at checkpoint-8:

Resuming from .../resume-e2e/checkpoint-8 (step=8, loss_history=...)
first progress step: 9      <- the counter continued rather than restarting at 1
last step:           16
provenance: attested, load_mode runtime_4bit
completed, no errors
checkpoints written: checkpoint-12, checkpoint-16

The step counter picking up at 9 is the part worth noting: the optimizer state and loss history came back, so this is a real resume rather than a fresh run pointed at an old directory.

So the MLX resume work in this PR does what it says — the gate was the only thing standing in the way, and with attestation fixed the machinery underneath was already correct. Worth recording because the original report made resume look broken on Apple Silicon when in fact only the provenance check was.

Two things still open from that testing, neither a regression here:

Environment: M2 MacBook Air (16GB), mlx 0.31.2, mlx-lm 0.31.2, unsloth_zoo 2026.8.4 (the version this repo pins), backend at e96d02074.

mahiatlinux added a commit that referenced this pull request Aug 26, 2026
)

* lower the train configure two-column threshold to 56rem

The Run preview card and its Start training button only split into a second
column when the train-configure container query matches. That container is the
page wrapper, so its width is min(1180, window - sidebar) - 72, and the sidebar
is 280px by default. The 64rem tier from #7633 needed a 1376px window, and
below that the card stacked under the wizard as a full-width row.

56rem is the narrowest tier that still leaves the wizard column past its own
28rem @md/train-section threshold once the 320px preview track, the 32px gap
and the card's 40px padding come out, so the model/method/token row stays two
across. The second column now appears from a 1248px window with the sidebar
expanded, and from 1016px with it collapsed to the rail.

* add a regression test for the train preview column budget

The threshold is a class name on the design scale, so nothing in the source
says it is really a window-width requirement. The test reads the tier, the
preview track, the gaps, the page padding, the training card's inset and
SIDEBAR_WIDTH_DEFAULT out of the source and out of Tailwind's own scales, then
holds both ends: two columns must be reachable in a 1280px window, and the
wizard column must still clear @md/train-section, the narrowest tier the
wizard's own sections use.

It also pins the sticky offset to the same tier as the column split, so the
preview cannot scroll away inside its own track, and checks that both named
containers are still declared, since every tier it reads is inert without them.
A tier it cannot resolve throws rather than dropping out of the budget.

* clarify train preview breakpoint test

---------

Co-authored-by: Leo Borcherding <[email protected]>
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 1, 2026
… since a clean pass (unslothai#16270)

## Studio: skip the startup manifest downgrade scan when nothing changed
since the last clean pass

### What changes

Every backend start runs `migrate_ordinary_v2_manifests_for_downgrade()`
inside the lifespan, before the server answers anything. It globs every
Hub download manifest, stats each one and reads a 256 byte prefix to
find ordinary v2 records to rewrite as v1. On a home with thousands of
manifests that is the largest single lifespan step, and it competes for
the GIL with the hardware detection thread, so it costs far more in the
server than in isolation (about 65 us per file in the server vs 12 us
standalone).

The scan now records a clean pass and skips itself on the next start
when nothing it depends on has changed:

- After a complete pass that found no ordinary v2 record, it writes
`hub-state/manifest_migration.json` with the mtime of `manifests/` and
of each `cache-*` scope dir, the active hub cache (canonical and raw),
the manifest versions and a migration id.
- On the next start, if the marker matches the current mtimes and
settings, the scan is skipped. That costs one stat per scope dir.
- Every manifest write goes through `tmp + os.replace`, so any added or
replaced manifest moves the mtime of the dir holding it. A new scope dir
moves the parent's. So any download, any manifest written by another
Studio version, a cache setting change or a bump of
`_MANIFEST_MIGRATION_ID` / `_MANIFEST_VERSION` re-runs the full scan.
- No marker is written when the pass migrated something, hit a write or
read failure (an unreadable manifest or a `cache-*` scope that cannot be
listed), stopped at the 10,000 file cap, or saw an ordinary v2 record it
left alone. It is also skipped when the dirs changed in the last 2 s, so
a write landing in the same mtime tick as the scan cannot be missed. In
that case the next start scans as before.
- The marker lives beside `manifests/`, not inside it, so writing it
does not move the mtimes it records.

The migration still runs synchronously in the same place in the
lifespan, before any download can start, so no write moves into a window
where it could race a download.

### Results, base vs head

`run.py --api-only` on a scratch Studio home with 5000 manifests (10% v2
on first start), 1000 chat threads, 4000 messages and 200 research runs,
CPU only, empty scratch HF cache. Interleaved base/head, separate home
copy per arm. Medians [range], ms.

| 5000 manifests | base | head |
|---|---|---|
| migration step, warm (5 runs) | 339 [316-481] | 3 [2-3] |
| lifespan, warm | 506 [473-652] | 147 [143-150] |
| spawn to ready, warm | 2334 [2213-2558] | 1973 [1891-2037] |
| spawn to first /api/health done, warm | 3727 [3562-3789] | 3197
[3110-3245] |
| login, warm | 52 [42-83] | 45 [41-66] |
| spawn to ready, first start on a fresh copy (3 runs) | 2975
[2765-4981] | 2806 [2768-2960] |

Every warm head run is faster than the fastest warm base run. The first
start does the full scan on both sides, as expected.

| 500 manifests | base | head |
|---|---|---|
| migration step, warm (4 runs) | 50 [35-57] | 3 [1-44] |
| lifespan, warm | 193 [174-216] | 155 [144-175] |
| spawn to ready, warm | 2040 [1981-2246] | 1930 [1905-2192] |

The 44 ms head run at 500 is the first start after a start that migrated
50 manifests. That pass is not recorded, so the next one scans again and
then writes the marker.

Other startup maintenance measured on the same home and left alone:
studio.db schema check plus research claim backfill (`open_wal_keeper`)
11-14 ms warm, orphan reconciliation under 7 ms.

### Tests

- New `tests/test_manifest_migration_marker.py`, 18 tests (one
POSIX-only, skipped on Windows). Head passes 18/18 on Linux and macOS,
17 + 1 skipped on Windows.
- Manifest bytes after startup match the unmarked scan on a home with
v1, ordinary v2 (scoped and unscoped), dataset v2 and a dataset
completion record. A fresh home with no manifests dir also works.
- The second start reads no manifest. This fails on main, where 10
manifests are read again.
- The scan re-runs for each of these: a new v2 manifest, an overwritten
manifest name, a new cache scope, a migration id change, a manifest
version change, an active cache change and a corrupt marker.
- No marker is written after a pass that migrated something, after
recent dir changes, after a write failure, or at the file cap.
- Neighbour suites (35 files touching manifests or hub state), base vs
head: 2354 passed on both sides, with the same 13 failing IDs on both.
Those are in `test_cached_gguf_routes`, `test_export_offline_window`,
`test_hub_download_http_size_ceiling` and `test_mtp_drafter_companion`,
and they predate this change.

#- A marker that cannot be read (including deeply nested JSON that
raises `RecursionError`) or any unexpected error in the marker check
falls back to the full scan and writes no marker, so a bad marker can
never block the migration.
- What a skipped migration would cost: no code on main writes an
ordinary v2 manifest, so only pre-unslothai#7633 builds or another Studio version
sharing the home can leave one. The migration only matters for a later
downgrade to a v1-only version, which would then miss one partial
download; the current version reads both. Every Studio writer goes
through `tmp` + `os.replace`, which moves the folder mtime.

## Not covered

- Windows and macOS were not run. The skip relies on a directory's mtime
moving when an entry is renamed into it. That holds on ext4, APFS and
NTFS. On a filesystem that does not maintain directory mtimes (FAT/exFAT
under Windows), a v2 manifest written by another Studio version could go
unmigrated until the next download changes the dir.
- No GPU host. The cost under contention depends on what the hardware
detection thread is doing at that moment.
- The one-time cost of actually migrating many v2 manifests (about 3 ms
each, from the fsync per rewrite) is unchanged.

### Follow-ups in this PR

- A manifest that cannot be read during the pass (for example a Windows
sharing violation) now keeps the pass unclean instead of being treated
as not v2.
- Migration candidates are listed with `os.scandir` per directory
instead of `Path.glob`, which silently returns nothing for a directory
it cannot read. A `cache-*` scope that cannot be listed blocks the
marker while the other scopes still migrate. Matching stays
case-insensitive on Windows, as glob was.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants