Skip to content

Studio: Use via API button on the Train page - #15996

Merged
danielhanchen merged 8 commits into
mainfrom
studio-train-api-button
Oct 29, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
studio-train-api-button

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

The Train page gets the same "Use via API" button the Images and Video pages have. It opens Settings > API on a new Training example that reproduces the current Train page setup through the OpenAI-compatible fine-tuning endpoints, in Python, JavaScript or curl (Linux / macOS or Windows PowerShell), with the API key and server address filled in like the other API examples.

What the example does

  1. Uploads the training file (files.create, purpose fine-tune), named after the dataset the form has uploaded, else train.jsonl.
  2. Creates the job with the form's settings: model, hyperparameters (n_epochs, batch_size), seed, suffix (the project name), and Studio settings as extra body fields (Python extra_body, flat JSON for JavaScript and curl).
  3. Polls the job and prints its new events oldest first, without repeats, until it finishes.
  4. Chats with fine_tuned_model.

Cancelling a job is shown as a separate snippet.

Every field of the payload the Start button sends has a route (TRAINING_FIELD_ROUTE, typed over the whole request, so a new field fails typecheck until it is placed): the OpenAI fields above; Studio settings, sent where the form sets them (learning rate as the exact string, max steps, training type, 4-bit, sequence length, image size, trust remote code, dataset row range, format and custom mapping, embedding learning rate, gradient accumulation, warmup, save interval, weight decay, gradient clipping, packing, optimizer, scheduler, LoRA rank / alpha / dropout / targets, gradient checkpointing, rsLoRA / DoRA / LoftQ, train on completions, layer choices, image / audio / embedding / decision run type and the decision checkpoint subfolder); and host-side fields that never appear (tokens, cache and host paths, offload, evaluation, logging, resume, drafter, Hub / S3 dataset fields). A Hub or S3 dataset gets a note to upload it as a file instead.

Without a Train page setup (opened from Settings directly), the card shows a placeholder example and says so.

Tests

  • studio/frontend/tests/training-api-snippets.test.ts (21): field routing and mapping (every Studio setting set to a non-default value must reach the example, nothing host-side may), every language and OS, shell and PowerShell quoting of hostile values, no secrets or host paths, events de-duplication, cancel snippet, button wiring.
  • studio/backend/tests/test_training_api_snippet_contract.py (12): every generated job body (including one with every Studio setting set) goes through the fine-tuning route's own validation and _training_config; each setting lands on the TrainingStartRequest unchanged, and keys outside the contract are still refused. The bodies come from the frontend generator (UPDATE_TRAINING_API_BODIES=1 regenerates them), so the two sides cannot drift apart.
  • Each generated example (bash, Python, Node, PowerShell 7) was run end to end against a recording fake of the endpoints: upload, create, poll to success with events printed once each, chat, and cancel all exit 0, and the recorded create-job bodies are identical across the four.
  • Frontend typecheck and build pass.

Screenshots

Before / after on two fresh install.sh --local builds (main and this branch), with the Train form set to unsloth/Qwen3-0.6B and its recommended defaults.

The Train header gains the API button, with the same "Use via API" tooltip as Images and Video:

Train header before and after

Settings > API: before, the Quickstart has no Training tab. After, the button opens it filled from the form: the model, the step count and the batch size the form shows.

Settings API before and after

danielhanchen and others added 2 commits October 29, 2026 09:22
Opens Settings > API on a new Training example filled from the current
training form: upload a JSONL file, create the fine-tuning job with the
form's settings, follow its events, then chat with the trained model.
Only an allowlist of settings is carried over; tokens, host paths,
offload, drafter and Hub / S3 dataset fields never are.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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-29T17:24:25.417444Z 59d9b82 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 self-assigned this Oct 29, 2026

@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: 58d2560b51

ℹ️ 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 +69 to +73
for (const [flag, fallback] of Object.entries(FLAG_DEFAULTS)) {
const value = payload[flag as keyof typeof FLAG_DEFAULTS];
if (value != null && value !== fallback) extras[flag] = value;
}
extras.train_on_completions = payload.train_on_completions;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the selected decision-model checkpoint subfolder

When the Train page selects Laya's multilingual or typed-decisions checkpoint, the generated request preserves is_decision but drops payload.model_subfolder. These checkpoints share the same convaiinnovations/laya model name and are distinguished only by their subfolder (studio/backend/core/systemone/catalog.py). The decision trainer reads config.get("model_subfolder") to select the checkpoint, so running the example silently trains the root English checkpoint instead of the selected model. Include the non-null checkpoint subfolder in the allowed extras so the API example reproduces the selected training setup.

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 the latest commit: the example now sends model_subfolder whenever the form sets one, so a Laya multilingual or typed-decisions run reproduces the selected checkpoint. The backend contract fixture gained a decision body, and the route's own validation keeps the subfolder on the TrainingStartRequest.

@danielhanchen

Copy link
Copy Markdown
Member Author

The Windows staging leg fails 6 of the 10 cases in the new studio/backend/tests/test_training_api_snippet_contract.py on one line:

studio\backend\tests\test_training_api_snippet_contract.py:44
    assert request.local_datasets == [f"/uploads/{FILE_ID}.jsonl"]
E   AssertionError: assert ['\\uploads\\...abcdef.jsonl'] == ['/uploads/fi...abcdef.jsonl']

The _find_file stub returns Path("/uploads/....jsonl"), and str() of that on Windows is \uploads\....jsonl, so the route is right and only the literal is POSIX. Comparing against the stub's own path keeps it exact on every platform, e.g.:

assert request.local_datasets == [str(Path(f"/uploads/{FILE_ID}.jsonl"))]

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 29, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 29, 2026
@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: 96ad29547a

ℹ️ 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 +75 to +78
extras.train_on_completions = payload.train_on_completions;
if (payload.format_type && payload.format_type !== "auto") {
extras.format_type = payload.format_type;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the selected dataset row range

When the Train form specifies a start or end row, the generated example drops dataset_slice_start and dataset_slice_end, even for an uploaded dataset. buildTrainingStartPayload includes these values, and trainer.py uses them to restrict the training rows; without them, the API example trains on the entire uploaded file instead. Include non-null slice bounds in the extras so copying the example does not silently change the training data or substantially increase the run time.

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, together with the rest of this class: instead of a hand-kept allowlist, every field of the Train payload now has a route in TRAINING_FIELD_ROUTE (OpenAI field, Studio setting, derived, or kept on the host), typed over the whole request so a new field fails typecheck until it is placed. The example now also carries the row range, the embedding learning rate, gradient clipping, gradient checkpointing, the save interval, the vision image size and trust remote code when set. A new test sets every Studio setting to a non-default value and requires each one in the example, and the backend contract fixture gained a body with all of them, accepted unchanged by the route.

Comment on lines +38 to +40
const extras: Record<string, unknown> = {
"learning_rate": payload.learning_rate,
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Carry over the CPT embedding learning rate

For a Continued Pretraining run with a custom embedding learning rate and embedding targets enabled, this mapping preserves the main learning rate but discards payload.embedding_learning_rate. The training worker then substitutes learning_rate / 10 when the field is absent (studio/backend/core/training/worker.py), so the generated example silently uses different optimizer settings from the Train form. Include the non-null embedding learning rate in the allowed extras.

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, together with the rest of this class: instead of a hand-kept allowlist, every field of the Train payload now has a route in TRAINING_FIELD_ROUTE (OpenAI field, Studio setting, derived, or kept on the host), typed over the whole request so a new field fails typecheck until it is placed. The example now also carries the row range, the embedding learning rate, gradient clipping, gradient checkpointing, the save interval, the vision image size and trust remote code when set. A new test sets every Studio setting to a non-default value and requires each one in the example, and the backend contract fixture gained a body with all of them, accepted unchanged by the route.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 59d9b826b9

ℹ️ 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
danielhanchen merged commit edc13e6 into main Oct 29, 2026
3 of 46 checks passed
@danielhanchen
danielhanchen deleted the studio-train-api-button branch October 29, 2026 18:25
danielhanchen added a commit that referenced this pull request Oct 29, 2026
`Repo tests (CPU, rest-2)` is red on main since #15996 (Use via API
button on the Train page). It now fails on unrelated PRs, for example
#16024:

```
test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[5]
AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding ...
  'studio/backend/tests/test_training_api_snippet_contract.py:19: read_text()'
```

The new snippet contract test reads its JSON fixture
`fixtures/training_api_job_bodies.json` with `read_text()`. On Windows
that decodes as cp1252, so the test breaks as soon as the fixture gains
a non-ASCII byte. The guard is right and the test was wrong. The fix is
`read_text(encoding = "utf-8")`.

## Verification

- `tests/test_source_read_encoding.py`: fails on main (the one site
above), 16 passed here.
- `studio/backend/tests/test_training_api_snippet_contract.py`: 12
passed.
shimmyshimmer added a commit that referenced this pull request Oct 30, 2026
…op startup screens (#16069)

## What changed

Studio in a non-English language showed English in several places that
the parity check could not see, and `npm run i18n:check:strict` on
`main` has failed since #15996 (Studio frontend CI, "Locale parity"
step).

- `settings.apiKeys.trainingApi` (8 keys) added to all 13 overlays. This
turns the Locale parity step on `main` green again.
- `managedEngines` (the More engines / vLLM / SGLang settings, about 45
strings) was `managedEngines: en.managedEngines` in 11 overlays, so the
keys existed but shipped English. Now translated in ar, de, es, fr, hi,
it, ja, ko, pt-BR, ru and zh-CN.
- Settings > Agents configuration notes were still English in 10
overlays.
- pt-BR: the Settings > Resources llama.cpp backend block and the GPU
rendering old-driver warning were still English.
- Stale translations whose English was reworded later:
`decisions.description` still named "Laya" in every overlay; pasted-text
description, GGUF quantization list description (also named the "On
Device" tab in English), upload label ("Or upload a local file").
- Mistranslations found in review: he (setup code "expired" instead of
"expires", "unloaded to the GPU" instead of "offloaded", message count),
hi (Connections description, gender agreement, "unsaved changes"), it
and pt-BR (account reset description), sv (engine "offload" instead of
"unload"), fr ("full screen" for the in-app full view).
- `check-parity.ts` now fails when an overlay reuses an English subtree,
so a `section: en.section` alias cannot pass the key check again.

### Shared screens moved into the catalog

The first screens every user sees were hardcoded English. They now go
through `t()`, with translations in all 13 languages:

- Sign-in and first-run password setup (`auth-form.tsx`), and browser
tab titles (route `staticData` now only takes a `titleKey`).
- The remote code consent dialog. Model name, provider and the follow-up
note are slots, so each language picks its own word order and sentence
spacing.
- Guided tour chrome (badge, Skip / Back / Next / Done, tip, Read more).
- Release notes panels and the llama.cpp / whisper.cpp / audio.cpp
runtime update card (runtime lists use `Intl.ListFormat`, backend names
reuse the existing `llamaBackend.backends.*` keys).
- Desktop startup, install, repair, update, diagnostics, install
location and window titlebar labels. Startup phase messages are now
message keys translated at render, and `LogDetails` takes full show/hide
labels instead of prefixing an English verb to a noun.

### Second review pass

A second, independent review (a back-translation of every overlay string
plus a read of its flagged rows) found more strings whose English
changed after they were translated, or that use the wrong sense of a
word:

- English changed, translations did not: the LoftQ, RS-LoRA and DoRA
option descriptions, the "Chat API" heading, the "Not set" Hugging Face
token status (still "Add"), the loaded-models drag handle label, and the
generation details description.
- Dropped content: the invalid Hugging Face ID errors leave out the `--`
/ `..` and `.git` rules that `hub-resource-id.ts` enforces, and the chat
import/export descriptions leave out Markdown although import accepts
`.md`.
- Wrong sense: the Japanese log notice had writing and reading reversed.
In Arabic, "upload" and "transcribe" used the words for load and copy,
"Unload" read as "cancel download", "offload" read as "unload", and
"State" said "Input". In Hebrew, "Enable", "Resume training" and
"Resuming" read as restart / new training. zh-CN used the "Projects"
word for "Items". "Archives" read as "Files" in es and pt-BR. Also ru
"Best loss", fr "Fork chat", de "Runtime", and the Hebrew and Swedish
engine and HTML-card descriptions that still described older behaviour.
- The Arabic "shell" term الصدفة is correct (it is the established
computing term); it now carries "(Shell)" to avoid the reading as
"chance".

155 strings across the 13 overlays. A key-by-key diff against the
previous commit confirms only the listed entries changed.

### Language menu

Settings > General > Language is now searchable: a pill search field
(the same control as the font picker), languages sorted by English name
with the native name first, Auto detect fixed above the scrolling list,
a wider panel, and no scroll arrows. It opens on the language in effect,
and scrolls with the mouse wheel inside the Settings dialog (the popover
is modal, as the font picker's is). Two notes that still pointed at the
old Sandbox and Remote access tab names now name Security and Remote &
LAN.

![Language menu,
scrolled](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/16069/i18n_langmenu.q-3399f4624cbf.png)

## Verification

- `npm run i18n:check:strict`: 0 missing keys, no errors, all 13
overlays (fails on `main`).
- `npm run typecheck`, `npm run build`, `npm run bundle:check` pass.
- `npm test`: 14456 pass; the 4 failures in
`tests/hub-gguf-card-unified-budget.test.ts` also fail on `main`
(missing `@/lib/folder-icons` stub) and are unrelated.
- `biome check` on the changed files reports the same 13 existing
formatter diagnostics as on `main`.
- Screenshots: sign-in and first-run setup pages from a local Studio
build in en / ja / ar; the consent dialog (custom-code and unsafe-files
variants) and the Desktop startup screen rendered from the same
components in a local harness, since this host has no non-GGUF model to
load and does not run the Desktop shell.
- A 180-string sample per locale (weighted toward delete, password and
security strings) was reviewed for meaning; nothing misleading was found
on those warnings.

## Not covered

About 4,200 user-visible strings in Studio are still hardcoded English
and never go through `t()` (Data Recipes, Images, Audio, Video, Hub,
Export, API monitor, the per-feature tour step text, and parts of Chat).
The image drop zone and crop editor are left for the Images / Video
migration, since their labels are built from subject names those pages
pass in English. The runtime update toast text comes from
`llama-job-lifecycle.ts` and backend job messages and stays English.
Desktop native dialogs and menus are English only. Those need their own
per-area migrations and are not part of this change.

## Screenshots

First-run password setup from a local Studio build (en / ja / ar):

![First-run setup in en, ja and
ar](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/16069/i18n_cmp-setup.q-a6319d2acd07.png)

Sign-in page from the same build:

![Sign-in in en, ja and
ar](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/16069/i18n_cmp-login.q-454d2efecc59.png)

Remote code consent dialog, custom-code variant. Japanese puts the
provider first through the `{model}` / `{provider}` slots, and the
follow-up note joins without an English space:

![Consent dialog custom-code variant in en, ja and
ar](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/16069/i18n_cmp-consent-review.q-3ad04291f0f4.png)

Consent dialog, unsafe-files variant:

![Consent dialog unsafe-files variant in en, ja and
ar](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/16069/i18n_cmp-consent-unsafe.q-a1757b84842f.png)

Desktop startup screen (ja / ar):

![Desktop startup screen in ja and
ar](https://raw.githubusercontent.com/shimmyshimmer/unsloth-staging-4/pr-media/pr/16069/i18n_cmp-startup.q-188300931f9e.png)

---------

Co-authored-by: Unsloth <[email protected]>
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.
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.

1 participant