Skip to content

Studio: train on CPU when no GPU is found, and offer Install Training on GPU-less Chat only installs - #16175

Merged
danielhanchen merged 11 commits into
unslothai:mainfrom
oobabooga:studio-train-on-cpu-hosts
Nov 1, 2026
Merged

danielhanchen merged 11 commits into
unslothai:mainfrom
oobabooga:studio-train-on-cpu-hosts

Conversation

@oobabooga

@oobabooga oobabooga commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Problem

On a host without a GPU, Studio greys out Train with "Training needs an NVIDIA or AMD GPU.", although #14717 added CPU training.

Cause

Both gates predate CPU training. #14593 reports no_torch off Mac only when _a_gpu_build_would_train_here() finds a card, since a full install on a GPU-less host could not train then. #14717 kept Studio out of CPU training by setting UNSLOTH_DISABLE_CPU_FALLBACK=1 in main.py and run.py, which the training worker inherits. unsloth-zoo#2162 has since made Studio's training worker run on the CPU backend, and 2026.10.11 ships both.

Fix

  • hardware.py: trains_on_cpu(reason) is true for no_gpu with PyTorch installed and for no_torch without a usable GPU. /api/health reports it as cpu_training. chat_only stays true, so Chat, Export and Video are unchanged.
  • Every off-Mac --no-torch install reports no_torch, so Install Training is offered there too.
  • The training worker sets UNSLOTH_FORCE_CPU=1 when trains_on_cpu() holds, before importing unsloth. Every other Studio process keeps the opt-out.
  • /api/train/start refuses vision and audio datasets, embedding, decision and drafter training on CPU with a 400, since the CPU backend trains text models with SFTTrainer only.
  • Frontend: Train, /studio and its shortcuts follow a new isTrainUnavailable() instead of isChatOnly(). The Train page notes that training runs on the CPU and, as on MLX, hides the drafter section and leaves a saved or imported drafter out of the request. On a GPU-less Chat only install the upgrade dialog and Settings row promise CPU training only, not export or video.

Behavior boundaries

Verification

Live A/B on Linux with CUDA_VISIBLE_DEVICES="", trl-internal-testing/tiny-Qwen3ForCausalLM and a 64-row JSONL, through /api/train/start with Studio defaults:

main this PR
/api/health chat_only, no_gpu chat_only, no_gpu, cpu_training: true
LoRA, 6 steps "Unsloth cannot find any torch accelerator? You need a GPU." completes, adapter saved
Full finetuning, 4 steps not run completes
Image dataset not run 400

New backend tests cover the verdicts, the health field, the start route refusals and the worker environment; they fail on main. Backend files touching these paths: 8,726 passed, with one failure that also fails on main. The full frontend suite has no failures beyond main's. Typecheck, i18n parity and the bundle budget pass, and lint has no new findings.

Not tested: the Desktop Install Training flow end to end on a GPU-less host, Windows or macOS, and models larger than the tiny test model.

Screenshots

main (4d28d72802) and this PR, two isolated installs with every GPU hidden, fresh en-US browser profile.

Sidebar with the Train row hovered:

cpu_training_train_row

/studio opened directly. On main it redirects to Chat:

cpu_training_train_page

Before / after on a GPU-less host

Two isolated installs (merge base c510fc1ca vs this PR), both launched with CUDA_VISIBLE_DEVICES="", /studio opened directly. Before: the route redirects to Chat and Train is greyed out. After: the Train page stays open with the CPU training notice.

Train page before and after on a GPU-less host

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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 ⚠️ Failed 2026-10-30T17:52:34.097390Z
We couldn’t complete this review. Comment @codex review to try again.
471daef PR opened
ℹ️ 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.

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#439.

@danielhanchen

Copy link
Copy Markdown
Member

(Python 3.13, a-f) fails on an existing test this PR does not touch, studio/backend/tests/test_export_capability.py::test_apple_no_torch_install_reports_no_torch:

AssertionError: assert 'no_accelerator' == 'no_torch'

With this PR's change to how the chat-only reason is derived (main.py / run.py / core/training/worker.py), an Apple install without torch now reports no_accelerator instead of no_torch. That test pins the Apple no-torch case to no_torch, so the new ordering looks like it checks for an accelerator before checking whether torch is installed at all. Worth keeping no_torch first there, or updating that test if the new reason is intended.

@danielhanchen

Copy link
Copy Markdown
Member

One more on this PR: (Python 3.13, rest) fails test_streaming_start_rejects_embedding_models. On the CPU runner the route now answers with the new CPU-host message (Embedding model training is not supported on CPU yet. No GPU was found, so this host trains text models only ...) instead of the embedding refusal that test asserts. So the CPU-host branch runs before the embedding-model check. Either keep the embedding refusal first, or update that test to the new wording if the CPU message is meant to win.

@danielhanchen

Copy link
Copy Markdown
Member

Correction to the comment above: the route still refuses the embedding model; the test fails only on case. tests/test_training_streaming.py:334 asserts "embedding" in exc_info.value.detail, and the new message starts with a capital Embedding model training is not supported on CPU yet..., so the lowercase substring is not found. Lowercasing the comparison in the test ("embedding" in detail.lower()) or keeping a lowercase "embedding" in the message fixes it.

@danielhanchen

Copy link
Copy Markdown
Member

Two more from Repo tests (CPU, studio) on this PR, both on files it edits:

  • test_desktop_surfaces_do_not_restore_studio_branding now flags studio/frontend/src/components/app-sidebar.tsx: the sidebar change brings back the Studio branding that check keeps off the desktop surfaces.
  • test_training_start_prepares_token_once_before_transport expects the start path to call buildTrainingStartPayload(attempt.config, hfToken, getCachedSystemInfo()); with this PR the start helper's call no longer has that shape, so the token-once contract test needs to follow it (or the call kept in that form).

@oobabooga

Copy link
Copy Markdown
Member Author

Fixed in 5247632. All four reproduce locally with CUDA_VISIBLE_DEVICES="":

  • test_apple_no_torch_install_reports_no_torch: trains_on_cpu() read a plain flag that the last detection pass set. On a GPU-less runner with torch installed, an earlier test's real detection set it for no_gpu, so the faked Apple no_torch verdict read as a CPU training host. A real Mac never set it, but the flag now records the verdict that established CPU training (_CPU_TRAINING_REASON), and trains_on_cpu(reason) only matches that verdict. Added a health case for that combination.
  • test_streaming_start_rejects_embedding_models: on a CPU host _validate_training_platform refuses embedding training before the streaming checks run, which is the intended route behavior. The streaming tests now stub the platform check so they exercise the streaming validation on any runner.
  • test_desktop_surfaces_do_not_restore_studio_branding: the new sidebar hint now reads "Reinstall without --no-torch to enable Train.", matching the existing no_torch hint.
  • test_training_start_prepares_token_once_before_transport: the call gained the isCpuTrainingHost() argument. The contract test now matches the leading attempt.config, hfToken, getCachedSystemInfo() arguments instead of the full call text.

The three Core zoo jobs were cancelled, not failed.

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence on 5247632 at oobabooga#439.

@danielhanchen danielhanchen self-assigned this Nov 1, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 1, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 1, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 1, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #16175, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#661.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 8463a2295 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] (on the mirror)

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

Reviewed commit: 8463a22958

No triage reaction was recorded on the mirror

Round 2: reviewed mirror 872911797 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] (on the mirror)

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

Reviewed commit: 872911797a

No triage reaction was recorded on the mirror

Round 3: reviewed mirror 3c41868443 (this PR's a14d32389)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 3c41868443

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 3c41868443 (this PR's a14d32389).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit 1d1363f into unslothai:main Nov 1, 2026
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.

3 participants