Skip to content

Studio: realtime option for speed and context stats, shorter Chat defaults - #16888

Merged
shimmyshimmer merged 14 commits into
mainfrom
studio-realtime-stats
Nov 7, 2026
Merged

shimmyshimmer merged 14 commits into
mainfrom
studio-realtime-stats

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Adds a Speed and context stats setting, in Settings > Chat > Chat defaults, with two options:

  • When done (default, unchanged behaviour): the header context meter moves when each pass finishes, and the reply speed line under a streaming reply only shows with Detailed speed and loading info (formerly Generation details) on.
  • Realtime: the context meter counts the prompt as it is read and then the prompt plus the reply so far, and the live tokens · tok/s line shows under a streaming reply even with Detailed speed and loading info off.

The row's info tooltip explains both modes and notes that Realtime may cause lag or slower performance on older or busy machines.

How it works

  • New generationStatsUpdates: "settled" | "realtime" in the chat preferences store, persisted like the other preferences. Anything other than "realtime" (missing, old records, unknown values) normalises to "settled".
  • Realtime reads the live generation_progress figures through useThrottledLiveGeneration, which subscribes to the runtime store outside React and re-renders at most once per 200 ms (leading and trailing, so the first and the last frame always land). The server already sends decode frames at most every 250 ms, so this only guards against bursts.
  • The header meter is wrapped in LiveContextUsageBar. In settled mode it renders the existing ContextUsageBar and subscribes to no live figures, so the chat header never re-renders mid-stream. In realtime mode only the small wrapper re-renders, not ChatPage.
  • When a pass's own context_usage frame lands, the meter switches back to that exact count instead of the last (trailing) decode frame. This is keyed on the snapshot object, not its numbers, so a regenerate with the same prompt still counts live.

Verification

  • npm run typecheck, npm test (15014 tests, 0 failures), npm run build, npm run i18n:check:strict pass.
  • biome lint on the changed files adds no new errors (the remaining ones are on untouched lines; npm run biome:check is red repo-wide on main as well).
  • New tests/realtime-generation-stats.test.ts pins the default and persistence, the throttle (fake clock: a 1,000 frame/s burst renders once per interval and the last frame lands), the live context arithmetic, the settled-snapshot handover, and that settled mode keeps the old code paths.
  • Exercised in a local Studio (macOS, Gemma 4 E2B GGUF): toggled the setting in Settings, sent a ~300 word prompt in each mode and sampled the header every 100 ms. When done: meter stayed at 1.2k for the whole stream and jumped to 1.9k at the end, no live line. Realtime: meter stepped 1.2k, 1.3k, ... 1.9k monotonically while streaming and ended on the same 1.9k, live line updated about 4 times a second. The choice survives a reload.
  • Overhead: browser main-thread time over a ~6 s reply was 1302 ms (When done) vs 1244 ms (Realtime), medians of 4 runs, within noise. The live figures themselves (llama.cpp timings_per_token) moved decode speed by under 1% and 15k-token prefill by noise on the same model.

New strings are translated in all 25 locales.

Settings cleanup

  • Settings > Chat is regrouped so no section runs long: Chat defaults (send shortcut, follow-up, scroll while generating, condense long pastes, speed and context stats), Memory, Conversations, new Replies, new Thinking and tools, Display, Model selection, Chat menu. Plain text composer, Rich text paste and Context window usage move to Display; the owner-only tool output and first-token limits move to Replies.
  • Generation details is renamed Detailed speed and loading info, with a description that says what it adds. Same preference, same behaviour; searching "generation details" still finds it.
  • System > Model memory is renamed Model loading, including the backend error that points users to it.
  • The System tab's no-GPU note said "CPU-only resources are shown above", which is wrong on unified memory machines where a built-in GPU shares that RAM. It now reads "No dedicated GPU detected."
  • Reset buttons (Chat menu, Shortcuts, download folder, model cache folder, chat template) use the Appearance reset style: an outline small button. Chat menu and Shortcuts get the same ruled footer and grey out when nothing differs from the defaults.
  • tests/chat-settings-sections.test.ts pins which rows each section holds, the section order and the reset footers.

Not tested here

  • Staging CI on macOS, Windows and Linux has not run for this branch yet.
  • No GPU training or image paths are touched.

Studio UI regression check

Base 06766f791 vs head 4676652cb. Functional: NO_REGRESSION, UI coverage 85%, 5 visual change(s), 1 text-only change(s). Only steps whose screenshots differ are shown.

settings/s04_tab_system: masks cover 9% of the shot | reproduced on confirm (VISUAL_DIFF)
settings/s04_tab_system

settings/s05_tab_chat: | reproduced on confirm (VISUAL_DIFF)
settings/s05_tab_chat

settings/s13_tab_shortcuts: | reproduced on confirm (VISUAL_DIFF)
settings/s13_tab_shortcuts

settings/s20_toggle_persist: | reproduced on confirm (VISUAL_DIFF)
settings/s20_toggle_persist

settings/s21_reload_persisted: | reproduced on confirm (VISUAL_DIFF)
settings/s21_reload_persisted

Step Text / structure change
settings/s06_tab_api {'removed': ['Model memory'], 'added': ['Model loading']}

Settings > Chat > Speed and context stats picks between When done (the
default, today's behaviour) and Realtime, where the header context meter
counts the prompt and reply as they stream and the live tok/s line shows
without Generation details. Realtime reads the live figures through a
200 ms leading and trailing throttle, and the settled path keeps its
existing subscriptions.
Auto-compact, keep running after the tab closes, scroll while generating
and reply notifications move from Chat defaults to Conversations. Speed
and context stats moves from Display to Chat defaults and also shows
under System > Live monitor; both rows edit the same preference.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T09:42:32.936448Z 4676652 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.

@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: 0070cc734d

ℹ️ 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 +40 to +43
const tracker = useRef<ReturnType<typeof createPassSettledTracker> | null>(
null,
);
tracker.current ??= createPassSettledTracker();

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 Reset the settled tracker when the live thread changes

With Realtime enabled, switching directly between two chats that are both decoding preserves this ref but changes the settled snapshot. createPassSettledTracker interprets the destination chat's snapshot as the previous pass having settled, so liveContextUsage returns null and the destination meter stops updating for the rest of that pass. The hook guards against displaying another thread's live figures, but the tracker needs the same thread isolation: reset or key it by liveThreadKey.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 46a92aa: the realtime meter is keyed by thread, so a chat switch mid-pass starts a fresh settled tracker.

Comment on lines +87 to +90
if (!decoding || !seeded) {
baseline = snapshot;
seeded = true;
return false;

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 Honor settled usage for passes without a decode frame

For a short tool-call pass that finishes before the server's 250 ms decode-frame interval, live.decode remains null even after its exact context_usage arrives. This branch continually replaces the baseline and returns false, so the realtime meter keeps displaying the prefill count with zero completion tokens instead of the settled count. The adapter only clears live generation on tool_end, so the incorrect count persists throughout tool execution or while waiting for approval. Track settlement for prefill-only passes as well, rather than requiring an observed decode frame.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 46a92aa: settlement is tracked from the start of each pass, so a pass that ends before any decode frame shows its exact context_usage.

- Chat defaults keeps the everyday rows: send shortcut, follow-up,
  scroll while generating, condense long pastes, speed and context stats.
- New Replies and Thinking and tools sections; Memory moves above
  Conversations; plain text composer, rich text paste and context window
  usage move to Display.
- Speed and context stats moves to System > Floating window.
- Model memory is renamed Model loading, including the backend message
  that points to it.
- Generation details is renamed Detailed speed and loading info with a
  description that says what it adds.
- Chat menu, Shortcuts, download folder, model cache folder and chat
  template resets use the Appearance reset style; the Chat menu and
  Shortcuts resets get its ruled footer and grey out at the defaults.
… note

Speed and context stats is no longer repeated under System > Floating
window. The System tab's no-GPU note no longer says CPU-only, since on
unified memory machines a built-in GPU shares the RAM shown above.
The tooltip says what each mode refreshes and that Realtime may cause
lag or slower performance on older or busy machines.
…d short passes

Key the realtime meter by thread, so switching between two chats that
are both decoding starts a fresh settled tracker instead of reading the
other chat's snapshot as this pass settling. Track settlement from the
start of each pass, not its first decode frame, so a short tool-call
pass that ends before any decode frame shows its exact context_usage.

[skip ci]
@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 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: 80e91fe193

ℹ️ 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 +83 to +86
const newPass = decoded && !decoding;
decoded = active && decoding;
if (!active || !seeded || newPass) {
baseline = snapshot;

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 pass boundaries across throttled live updates

In Realtime mode, when a tool-call pass settles without a decode frame and its tool finishes quickly, tool_end can clear live progress and the next prefill can arrive within the same 200 ms throttle window. useThrottledLiveGeneration then exposes only the new prefill, so this tracker never observes active === false; since the preceding pass never decoded, newPass is also false. The baseline remains the snapshot from before the completed pass, making the entire next pass appear already settled and disabling its realtime context updates. Track pass boundaries before throttling, or carry a pass identifier through the throttled snapshot rather than inferring boundaries solely from sampled booleans.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in c1884d8: passes are numbered on every store change inside the throttled hook, and the settled tracker keys on that number, so a boundary inside one throttle window is kept.

A pass boundary inferred from throttled samples is lost when a tool pass
with no decode frame ends and the next prefill arrives inside one 200 ms
window, which made the next pass look already settled. Count passes on
every store change in the throttled hook and key the settled tracker on
that number.

[skip ci]
@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 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: c1884d8d49

ℹ️ 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 +93 to +96
if (pass !== seenPass) {
baseline = snapshot;
seenPass = pass;
return false;

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 settlement when mounting during tool execution

When switching back to a chat after its context_usage has arrived but while its tool is still running or awaiting approval, the thread-keyed remount creates a fresh tracker and treats that already-settled snapshot as the baseline. It consequently returns false and replaces the exact context count with the older live figures until tool_end clears them. The new keyed remount exposes this separate initialization case even though switching between actively decoding chats is now isolated correctly. Persist settlement alongside the pass in the runtime store, or otherwise initialize the tracker with whether the current pass has already settled, rather than assuming its first observed snapshot predates settlement.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 15718f8: settlement now lives on the thread's live progress in the store (set when the adapter publishes that pass's context_usage, cleared by the next prefill), so a remount during tool execution keeps it; the component tracker is gone.

The realtime meter inferred settlement in component state from the
settled snapshot changing, which broke on a chat switch, on a pass with
no decode frame, on a boundary inside one throttle window, and on a
remount while a tool runs. The adapter now marks the thread's live
progress settled when it publishes that pass's own context_usage, the
next pass's prefill clears it, and the meter reads the flag. The tracker,
pass numbering and keyed remount are gone.
@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: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 15718f81cb

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

The Chat settings regroup moved the plain text, rich paste and context window
rows out of ComposerSettings, so the composer smoke page (Playwright on every
engine and native Safari) no longer had the switches it drives.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 4676652cbf

ℹ️ 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 7, 2026
@shimmyshimmer
shimmyshimmer merged commit c2ca6b4 into main Nov 7, 2026
@shimmyshimmer
shimmyshimmer deleted the studio-realtime-stats branch November 7, 2026 11:41
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 8, 2026
Resolve composer-settings against unslothai#16888, which moved Plain text, Rich
text paste and Context window usage to Display; Share drafts across chats
stays in Chat defaults, and the pinned Chat defaults row list includes it.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 11, 2026
Related to unslothai#16055.

## Problem

Studio knows where a loaded GGUF's weights are, but the only lasting
readout is the "Weight placement" row in Run settings (unslothai#14909), and it
sits behind a switch that is off by default. In a [Reddit
thread](https://www.reddit.com/r/unsloth/comments/1xra6ua/inference_speed_cratered_after_recent_update/)
about slow generation, people could not tell whether the model had
spilled to the CPU. They tried to read it from the memory estimate,
which is a forecast.

## Fix

- The "Weight placement" row always shows for the loaded GGUF, in the
same grey text for every placement.
- The switch that used to gate it now only controls the live speed
lines, so "Detailed speed and loading info" becomes "Detailed speed
info" in all 25 locales. That label is from unslothai#16888, so please say if you
prefer another name.
- The "partly on CPU" and "none of the layers fit" warnings now end with
the weight amounts, for example "Model weights: 1.9 GiB on the GPU, 2.8
GiB on the CPU." These are totals, and they count the weights only. This
is the idea from unslothai#16064 (thanks @debojyoti-dev), worded so it is also
correct with unified memory.
- A MoE load with expert weights in RAM, which llama.cpp counts as fully
on the GPU, now says so on its success toast.
- A load that llama.cpp logs as fully offloaded while every buffer is in
system memory, on a machine with a GPU, now gets the existing "llama.cpp
could not use it" warning.

There are no backend changes, and which loads get a warning is otherwise
the same.

## Before and after

Main (`011129b355`) vs this PR (`7e9fd96cc5`), with the same real load
on both sides.

A model that is fully on the GPU:

<img width="3504" height="1072" alt="placement_01_fully_on_gpu"
src="https://raw.githubusercontent.com/oobabooga/unsloth/pr-media/pr/studio-gguf-placement-visible/placement_01_fully_on_gpu-b3ed33f4ace9.png"
/>

14 of 37 layers on the GPU:

<img width="3504" height="1124" alt="placement_02_partly_on_cpu"
src="https://raw.githubusercontent.com/oobabooga/unsloth/pr-media/pr/studio-gguf-placement-visible/placement_02_partly_on_cpu-a21ce5ab7fd0.png"
/>

A MoE model with the expert weights of 24 layers in RAM:

<img width="3504" height="1124"
alt="placement_03_moe_expert_weights_in_ram"
src="https://raw.githubusercontent.com/oobabooga/unsloth/pr-media/pr/studio-gguf-placement-visible/placement_03_moe_expert_weights_in_ram-94f22098f15b.png"
/>

## Testing

- Live in Studio on Linux with an RTX 3090: the three loads above, and
the row after a page reload. A small tool makes the card report less
free VRAM than it has, so a model that would fit lands partly on the
CPU.
- 7 new frontend tests. The failed GPU backend case is covered by these
tests only.
- `typecheck`, `i18n:check:strict` and the frontend and `tests/studio`
tests that cover these files pass.
- Not tested on Windows or macOS.


## Before and after, separate installs

Merge base `011129b355` vs this PR `dbd790c8ed`, each built from its own
tree, "Detailed speed info" left at its default (off).

Run settings with gemma-3-270m GGUF loaded on an NVIDIA L4. Main shows
no placement; this PR shows all 19 layers on the GPU and the weight
split:

<img width="620" alt="pr17449_gpu_l4"
src="https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/17449/pr17449_gpu_l4_crop-95099eb1a905.png"
/>

Run settings with Qwen3-0.6B GGUF loaded on a CPU-only Linux machine.
This PR says all 29 layers are on the CPU, with 0.5 GiB in RAM:

<img width="660" alt="pr17449_cpu_only"
src="https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/17449/pr17449_run_settings_crop-4524523ed93c.png"
/>
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.

2 participants