Skip to content

Studio: estimate the prompt's time left from how the cost per token grows, not the rate so far - #16450

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:studio-prefill-eta
Nov 2, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:studio-prefill-eta

Conversation

@oobabooga

@oobabooga oobabooga commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

A review of #14909 reported that the "time left" while a GGUF reads a long prompt is too optimistic: it showed 26 s when about 42 s remained.

Problem

"Processing prompt N% · Xs left" runs short for the whole prompt, and by more the longer the prompt is. On a 30K-token prompt it read 38% to 49% short at every point.

Cause

prefillSecondsLeft divides the remaining tokens by llama-server's prompt_per_second, the average rate since the pass started. That assumes every remaining token costs what the earlier ones did. Each prompt token attends to every token before it, so the cost per token grows with its position: the time per 2,048-token batch rose about linearly in every run below (0.60 to 1.55 ms per token on one prompt). A rate over a recent window still lags the growth; on the same samples it stayed 15% to 49% short.

Fix

  • routes/inference.py: the prefill frame also carries llama-server's time_ms, its own clock since the pass started. The client cannot time the frames itself, because they reach it through the 0.25 s stall poll, which sends only the newest sample.
  • generation-progress.ts and the runtime store: each timed sample of a pass adds to eight running least-squares sums, and the time left comes from the fit c + a*x + b*x^2 of elapsed time over tokens (a straight line if the curve bends the wrong way).
  • Two limits keep a few samples from overreaching: the cost per token grows only across as many tokens again as the samples span, then holds; and the fit replaces the rate so far gradually, from the fourth timed sample, fully once the pass has six samples and 30% of the prompt read.

Behavior boundaries

  • The percent, the token counts and the prompt speed in Generation details are unchanged.
  • Whether the label shows at all is still decided on the first samples, so short prompts keep "Working...".
  • Early in a pass the estimate is main's, moving to the fit as above (fully about 45% into the 27K-token prompts below). There it still reads short, as on main. An older llama-server without time_ms keeps main's estimate throughout.

Verification

Unless noted, runs on the CPU, gemma-3-270m-it UD-Q4_K_XL, fresh Studio homes, main at 6401ceda29.

Live A/B through the page, alternating, the same 27K-token prompts, the label read every 100 ms. Error of the shown time left against the time that actually remained, from 30% to 82%:

main this PR
Mean -31% -9%
Mean absolute 31% 12%
Range -41% to -21% -33% to +15%

Below 30% this branch read -43% to -10%, never over. A replay of llama-server's own samples from 10 prompts (two models, Studio's llama-server flags, three runs recorded by Studio) gives the same picture: main -34%, this branch -9% (mean absolute 11%).

One slow batch, through the same functions (2,048 tokens per 500 ms, batch 4 taking 250 ms longer):

Fit without the limits This PR
32K tokens 18.1 s shown for 6.0 s left at most +48%
131K tokens 270.8 s for 30.0 s left at most +36%

On an RTX 6000 Ada, with Studio's llama-server flags: each prompt's progress samples, replayed through both versions the way the page receives them (the newest sample every 0.25 s). The cost per prompt token grows on the GPU too, 2.5x across 58K tokens on gemma-4-E2B and about 4x across 107K on Qwen3.6-35B-A3B. Error from 30% to 83%:

Model Prompt Read in main this PR
gemma-4-E2B Q4_K_M 58K tokens 4.4 s -39% -12%
Qwen3.6-35B-A3B UD-Q4_K_XL 58K tokens 8.5 s -32% -6%
Qwen3.6-35B-A3B UD-Q4_K_XL 107K tokens 21.8 s -46% -11%
Qwen3-8B Q4_K_M 30K tokens 6.3 s -43% -14%

Tests:

  • New: a replay of two recorded prompts, where the estimate never does worse than the rate so far from 30% on and stays within 20% from 45%; the slow-batch case above; and the fit's lifecycle across repeated frames, an untimed llama-server and a new pass. They fail on main, as do two updated backend tests.
  • Frontend tests in files touching the runtime store, adapter or progress: 2,351 of 2,352 pass; save-temporary-chat.test.ts fails the same way on main (the bundled Node 22.12 lacks stripTypeScriptTypes). Backend live-progress, frame-spoofing and chat-run supervisor suites: 110 passed. Typecheck passes; ESLint has no new findings.

Not tested: Metal, and prompts with images.

Screenshots

The same 27K-token prompt on both sides; the legend gives the time that actually remained:

Prompt time left at 37% and 67%, before and after

Verified before and after

Separate Studio installs at base 6401ceda29 and head 71aedfe885, using identical recorded progress frames. At 53%, the estimate changes from 12s to 20s left; the recorded completion leaves 20.57s at this sample. Counts and prompt rate are unchanged. This is a replay through the real UI, not a model-throughput measurement.

Prompt ETA before and after

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-11-02T04:14:29.573330Z
We couldn’t complete this review. Comment @codex review to try again.
754bc74 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.

@shimmyshimmer

Copy link
Copy Markdown
Member

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

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 2fc8921855 (this PR's 71aedfe88)

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

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

Reviewed commit: 2fc8921855

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 2fc8921855 (this PR's 71aedfe88).

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

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
@danielhanchen
danielhanchen merged commit ac72298 into unslothai:main Nov 2, 2026
yermakoffivan pushed a commit to yermakoffivan/unsloth that referenced this pull request Nov 2, 2026
…ip and the weight placement row (unslothai#16452)

A review of unslothai#14909 reported that in another language its new strings
stay English, while the Generation details setting itself is translated.

## Problem

With the UI in German, a GGUF chat shows "Processing prompt 15% · 4s
left · 2.049 / 13.626 tokens · 2.710 tok/s": German digits, English
words. The same goes for "Working...", the live line under a streaming
reply, every row of the reply's timing tooltip including the new "Stop
reason" values, and the "Weight placement" row in Run settings.

## Cause

unslothai#14909 kept these strings in the code, as its description says ("The
live strings are English, like the 'Working...' they replace").
`generation-progress.ts` and `partial-offload.ts` build the sentences
around numbers already passed through `toLocaleString`.
`message-timing.tsx` had no translation at all before unslothai#14909, which
added "Stop reason" and "Draft accepted" to it.

## Fix

- A `generationStats` namespace in `en.ts` holds whole templates with
placeholders ("{count} tokens", "{eta} left", "{gpu} of {total} layers
on the GPU, {cpu} on the CPU"), so each language can order the words
around the numbers.
- `formatPrefillDetails`, `formatPrefillTimeLeft`, `formatLiveDecode`
and `describePlacement` take the `t` function from `useT()`, as
`scheduled-tasks/results.ts` does, so they stay plain functions for the
tests. The Run settings panel passes the memory pool as `"unified"` /
`"shared"` instead of English words.
- The prompt line ("Working..." included, since the two alternate in one
span), the live line, the whole timing tooltip with its button label,
and the Weight placement row read from the catalog.
- All 24 overlays carry the new keys, in a separate commit as the i18n
README asks, reusing each overlay's existing words for token, prompt,
cache, layers, experts, draft and unified memory.
- The catalog has only a one/other pair, which cannot give Russian "2
токена" and "21 токен" next to "5 токенов". So Russian, Ukrainian,
Polish, Czech and Arabic put the count after a label ("токены: 21")
wherever it stands before a noun.

## Behavior boundaries

- English output is unchanged; the existing English assertions in
`generation-details.test.ts` pass as they were.
- "tok/s", GPU, CPU, RAM, VRAM, GiB, MiB and the compact durations
("12s", "2m 10s") stay as they are, as elsewhere in the app.
- Only these four pieces are moved. The rest of the Run settings panel,
the reply's action bar and "Cancelled." were English before unslothai#14909 and
still are.

## Verification

Live A/B with Playwright on fresh Studio homes, gemma-3-270m-it
UD-Q4_K_XL on the CPU, a 13.6K-token prompt, Generation details on, UI
in German; main was `d8efd157ab` for the run below and `6401ceda29` for
the screenshot. With this PR the prompt line reads "Prompt-Verarbeitung
15% · noch 4s · 2.049 / 13.645 Tokens · 2.520 tok/s", the live line "130
Tokens · 115,1 tok/s · Draft 107/128 akzeptiert (84%)", and the
placement row "Platzierung der Gewichte · Alle 19 Schichten auf der
CPU". The same four places render in Japanese, and the tooltip keeps its
layout with the longer German labels.

Tests:

- New: the formatters and the placement description render the German
overlay's templates with German number formatting; the prompt line,
tooltip, placement row and `generation-progress.ts` no longer hold the
English sentences; in Russian, Ukrainian, Polish, Czech and Arabic no
count stands before a noun.
- `i18n:check:strict` passes with no missing keys. The 830 tests in
files touching these formatters, components or the locale files pass.
Typecheck passes; ESLint has no new findings.
- The startup bundle stays within budget; the i18n chunk grows by 1.6 KB
raw (0.6 KB transfer).

Not checked by a native speaker: the 24 overlays.

## Screenshots

UI in German on both sides:

![Prompt line, live line, timing tooltip and Weight placement in German,
before and
after](https://raw.githubusercontent.com/oobabooga/unsloth/pr-media/pr/studio-generation-details-i18n/pr_i18n_01_german_ui-97fa66faa72f.png)

<!-- generation-evidence:start -->
## Verified before and after

Separate Studio installs at base `ac7229860e` and integrated head
`7cdeff4ae7`, with German selected and identical recorded progress
frames. The fitted estimate from unslothai#16450 stays at 20s on both sides; the
prompt-progress and draft-acceptance labels become German while all
numbers remain identical. These pictures verify presentation, not model
throughput.

![Generation details before and after
1](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16452/pr16452_integrated_zoom_00-3a318e5d910b.png)

![Generation details before and after
2](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16452/pr16452_integrated_zoom_01-336668a6a098.png)

Validation at this head: 26 focused generation-details tests pass, full
frontend suite 14,644 passed and zero failed, production build passes,
and strict parity passes for all 25 catalogs. The merge resolution
explicitly checks the fitted estimate renders as "noch 20s".

<!-- generation-evidence:end -->

---------

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