Skip to content

Studio: honour Voice Settings Load into on cold STT API loads (#15280) - #15284

Merged
danielhanchen merged 19 commits into
unslothai:mainfrom
indrajeetapache:fix/stt-api-honors-load-into-15280
Nov 2, 2026
Merged

danielhanchen merged 19 commits into
unslothai:mainfrom
indrajeetapache:fix/stt-api-honors-load-into-15280

Conversation

@indrajeetapache

@indrajeetapache indrajeetapache commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Cold speech-to-text API requests ignored the CPU RAM choice in Voice Settings because the choice lived only in browser storage. This change saves the owner's choice on the server and applies it when an STT model loads without an explicit device.

Fixes #15280

The existing Voice Settings controls and loading flow are preserved. First-run migration uses an atomic conditional write, so an old browser preference cannot overwrite a newer explicit selection in another browser. The saved choice applies to all four STT sidecars; an explicit request device or UNSLOTH_AUDIO_DEVICE retains precedence, and a request without a device keeps an already-resident model in place. Native audio and TTS keep their existing environment-only default. The OpenAI transcription and translation endpoints also accept an optional device form field.

Validation:

  • 91 focused backend tests passed, including settings, device preference, audio.cpp lifecycle, and upload bounds. All 10 changed frontend tests passed. Another 360 STT and OpenAI route tests passed; 5 optional OpenAI SDK checks skipped.
  • The Qwen3-ASR sidecar regression test fails on the merge base with assert 'cuda' == 'cpu' and passes on this branch. It uses synthetic GGUF metadata and a fake audio server; it verifies routing and server configuration rather than real model memory residency.
  • A simulated routing matrix has 864 cases: 828 unchanged, 36 intentionally adopting a saved CPU choice, and no unexpected changes. These are pure routing checks, not hardware runs.
  • Two isolated Studio installs show that after selecting CPU RAM, a fresh browser uses the saved CPU choice on this branch. Before the change it returns to GPU when available.

The migration regression fails before the follow-up fix and passes afterward, in both backend and frontend tests. Cross-platform CI passes on Linux, Windows, and Apple Silicon macOS with torch installed: 89 backend and 10 frontend tests pass on each OS. The fixed-head fallback review is clean. The full Studio regression suite reports NO_REGRESSION on the current head, including remote Colab T4-HM inference/diffusion checks. Its report retains 19 confirmed flaky snapshots and one Hub visual flag with only three bottom image rows differing; the repeat has zero pixel difference. A separate broader CI parity job is inconclusive because its null control has no stable actions; remaining broad CI is still pending. Real Qwen3-ASR weights and their VRAM footprint have not been tested. No local GPU was used.

Screenshot from separate installs at merge base f9cecc99d and fixed head f8ed0f31a. Both browsers selected CPU RAM first; the pictured fresh browsers show GPU when available before and CPU RAM after. No model weights are downloaded or loaded for this preference screenshot.

Voice Settings in a fresh browser before and after

OpenAI /v1/audio/transcriptions omitted device, so a cold load used auto/GPU
even when Settings said CPU RAM (unslothai#15280). Persist sttDevice server-side (like
embedding device), use it from audio_device_default when UNSLOTH_AUDIO_DEVICE
is unset, and accept an optional device form field on the OpenAI STT routes.
@danielhanchen

Copy link
Copy Markdown
Member

Frontend build + bundle sanity and Frontend unit tests (Windows) both fail here on one test that this PR does not touch, tests/audio-cpp-catalog.test.ts:

# Error: A resource generated asynchronous activity after the test ended. This activity created the error
  "Error: Cannot find module '.../studio/frontend/src/features/auth/login-page' imported from ..."
not ok 73 - tests/audio-cpp-catalog.test.ts

That test imports features/settings/stores/voice-settings-store.ts. It passes on main (34 of 34) and fails on this PR's head locally the same way. The new setSttDevice and onRehydrateStorage both fire import("../api/stt-device"). stt-device.ts imports authFetch from the @/features/auth barrel, which pulls in login-page, a module Node's test runner cannot resolve. Rehydration runs when the store is created, so the import lands after the catalog test has finished and fails it.

A couple of ways out:

  • Import authFetch from its own module rather than the barrel. The store tests then load no UI code.
  • Keep the server sync out of the store, for example in the Settings component that calls setSttDevice, plus one app-start sync.
  • At minimum, .catch(() => {}) on the dynamic import, so a missing module cannot surface as an unhandled rejection.

The Unsloth Updating Tests red (GET / with FileNotFoundError: dist\index.html) looks downstream of the frontend build failing. Chat UI Tests (extra) timed out loading the page (Page.goto: Timeout 30000ms exceeded), which may be the same cause; worth re-checking once the build is green.

@danielhanchen danielhanchen self-assigned this Oct 26, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 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-28T12:04:41.246896Z
We couldn’t complete this review. Comment @codex review to try again.
20bdfcc 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

Copy link
Copy Markdown
Member

Frontend build + bundle sanity now fails here on the startup budget (job 121380421428): over the startup budget: transfer 2051.3 KB > 2051.3 KB. Main sits right at the budget after #15247 and #15249 raised it (2,100,497 bytes), so any change that adds eager startup code trips it. Either keep the new code out of the eager graph (dynamic import()), or raise BUDGET in studio/frontend/scripts/check-bundle-budget.ts in this PR by the measured growth, with a line in its comment saying what grew, as that file asks.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

# Conflicts:
#	studio/backend/core/inference/stt_ggml_sidecar.py
#	studio/backend/core/inference/stt_sidecar.py
#	studio/frontend/src/app/routes/__root.tsx
danielhanchen added a commit that referenced this pull request Oct 26, 2026
…oise is not amplified (#15381)

## Problem

`Repo tests (CPU, gloo)` is red on main since #15326. Three tests fail
locally and in CI (for example #15284):

- `test_env_tp2_trainer_matches_one_process[sharded_16bit]`
- `test_env_tp2_trainer_matches_one_process[full_load]`
- `test_env_tp2_with_fsdp2_flag_and_no_dp_dimension`

They fail like this:

```
comparison failed. Mismatched elements: 1 / 3:
Max relative difference: 1.24e-05
Index | Obtained           | Expected
2     | 0.3388126790523529 | 0.33881688117980957 +- 3.4e-06
```

## Product or test

The test. I measured both arms (`tp = 2` against one process) step by
step on main:

| | step 1 | step 2 | step 3 |
|---|---|---|---|
| loss, relative gap | 0 | 0 | 0 |
| grad norm, relative gap | 3.2e-7 | 1.6e-6 | 1.2e-5 |

The worst LoRA tensor after the run (`layers.1.mlp.gate_proj.lora_B`) is
1.35e-4 off, while the rest sit near 2e-6.

The losses match exactly and the first-step gap is fp32 reduction-order
noise. The gap then grows about 10x per step, which is what `m /
(sqrt(v) + eps)` does to near-zero LoRA gradients at the Trainer's
default `adam_epsilon = 1e-8`. Changing only eps on both arms:

| `adam_epsilon` | step-3 grad-norm gap | worst tensor |
|---|---|---|
| 1e-8 (default) | 1.24e-5 | 1.35e-4 |
| 1e-5 | 5.3e-6 | 5.9e-6 |
| 1e-4 | 9.4e-7 | 4.4e-7 |
| 1e-3 | 1.2e-6 | 1.4e-7 |

A tensor-parallel bug would not shrink with eps. This is the same effect
#15264 fixed for the hand-written TP x FSDP2 loop. The new
UNSLOTH_TP_SIZE Trainer tests share `_trainer_args`, which still used
the default eps.

## Fix

`_trainer_args` in `tests/test_tp_native_gloo.py`, used by both the
native and the env-driven Trainer tests, now passes `adam_epsilon =
_TRAINER_ADAM_EPS` (1e-4). A comment records the measurement. The
tolerances (`rel = 1e-5` on grad norms, `rtol = 1e-4, atol = 1e-6` on
the adapter state) are unchanged.

## Verification

- `tests/test_tp_env_gloo.py` and `tests/test_tp_native_gloo.py` in
full: 52 passed. On main, the three tests above fail.
- Sabotage: with the backward all-reduce of the column-parallel input
removed in `tp_native.py` (`return grad, None`), a real TP bug that
leaves earlier layers with partial gradients, all three tests fail at
`Max relative difference: 3.5e-4`, 35x over the tolerance. The looser
eps does not hide a real TP error.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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 added a commit that referenced this pull request Oct 26, 2026
…ative Trainer runs back on the default (#15397)

## Problem

#15381 set `adam_epsilon = 1e-4` in the shared `_trainer_args` of
`tests/test_tp_native_gloo.py`. That fixed the three UNSLOTH_TP_SIZE
Trainer tests in `test_tp_env_gloo.py`, but on the CI runners it broke
the two native Trainer tests that use the same helper. Comparing the
`gloo` shard before and after (both on current-main bases):

| CI run | native
`test_trainer_trains_a_tensor_parallel_model_like_one_process[1-2]` /
`[2-2]` | `test_env_tp2_*` (3 tests) |
|---|---|---|
| #15284, base 975e864 (before #15381) | pass | fail |
| #15386, base 0be4c5d (after #15381) | fail on `lora_A` state (`rtol =
1e-4, atol = 1e-6`) | pass |

On this host both groups pass at both settings. The runners' CPUs round
differently from this machine, and I could not emulate theirs here:
`ATEN_CPU_CAPABILITY=avx2` aborts the spawned ranks with `buffer
overflow detected`. So the CI table above is the evidence for which eps
each group needs.

The two groups differ in their adapters. The env tests use
`init_lora_weights = False`, where every factor gets a real gradient
from step 1; that is where the default eps amplifies reduction-order
noise, as measured in #15381. The native tests use the default `B = 0`
start, where `lora_A`'s gradients are tiny for the first steps. There,
eps 1e-4 sits inside their range and moves `lora_A` differently on the
two arms.

## Fix

- `_trainer_args` goes back to AdamW's default eps, so the native
Trainer tests run as they did when they passed on CI.
- `test_tp_env_gloo.py` passes `adam_epsilon = 1e-4` only at its own
training call, with the measurement and the reason in a comment.

Tolerances are unchanged.

## Verification

- `tests/test_tp_env_gloo.py` and `tests/test_tp_native_gloo.py`: 52
passed on this host.
- This PR's own `Repo tests (CPU, gloo)` shard is the check on runner
hardware. Both groups should pass there.

## Not covered here

`test_tp2_x_fsdp2_dp2_matches_one_process[phi3-True-None]` also fails in
both CI runs above, by 6.9e-5 to 7.7e-5 relative on grad norms
(tolerance 1e-5), and passes on this host. It only became visible after
#15355: before that, the `phi3` cases errored on the removed tiny model.
It uses its own hand-written loop (eps 1e-6), not `_trainer_args`, so
this change does not touch it.
danielhanchen added a commit that referenced this pull request Oct 26, 2026
… shards (#15400)

## Problem


`tests/test_tp_native_gloo.py::test_tp2_x_fsdp2_dp2_matches_one_process[phi3-True-None]`
fails in `Repo tests (CPU, gloo)` on every recent run, on the per-step
grad norms (tolerance 1e-5):

| CI run | step 1 | step 2 | step 3 |
|---|---|---|---|
| #15284 (job 121590971980) | 1.5e-6 | 3.6e-5 | 7.7e-5 |
| #15386 (job 121637289351) | 1.5e-6 | 3.6e-5 | 6.9e-5 |

It only became visible after #15355. Before that, every `phi3` case
errored on the removed `trl-internal-testing/tiny-Phi3ForCausalLM`. On
this host the same test passes inside 1e-5.

## Product or test

The test. In the same run, the loss check (rel 1e-5) and the step-1
per-gradient check (`rtol = 1e-4, atol = 1e-6` on every LoRA gradient)
both pass. Only the multi-step norms drift, and the gap grows each step
from a 1.5e-6 start. That is reduction-order noise compounded by AdamW,
which phi3's fused qkv and gate_up shards make larger than llama's. The
runners' CPUs round differently from this host.

A real tensor-parallel error does not hide behind the norms. With the
backward all-reduce of the column-parallel input removed in
`tp_native.py` (`return grad, None`), the phi3 case fails on the step-1
per-gradient check, before the norms are compared.

## Fix

`_TP_FSDP2_NORM_REL = {"phi3": 2e-4}` sets the norm tolerance for phi3
only, with the CI measurements in a comment. Every other arch keeps
1e-5. The loss, per-gradient, mismatch and placement checks are
unchanged for all arches.

## Verification

- `test_tp2_x_fsdp2_dp2_matches_one_process`: all 5 parametrizations
pass.
- Sabotage: with the all-reduce removed, the phi3 case still fails.
- ruff format and check are clean.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
@danielhanchen

Copy link
Copy Markdown
Member

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

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.

Verdict

The round did not reach a clean review on the mirror before it closed.

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

danielhanchen added a commit to Etherll/unsloth that referenced this pull request Nov 2, 2026
danielhanchen added a commit to Etherll/unsloth that referenced this pull request Nov 2, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
@danielhanchen
danielhanchen merged commit 2099086 into unslothai:main Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] "Load into" setting ignored when STT model is loaded from API

2 participants