Skip to content

Studio: time a continued reply as the whole answer, not just its last pass - #16451

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
oobabooga:studio-continued-reply-timing
Nov 2, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
oobabooga:studio-continued-reply-timing

Conversation

@oobabooga

@oobabooga oobabooga commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

A review of #14909 reported that when a reply reaches Max Tokens and automatically continues, the timing tooltip describes only the continuation. Their reply had 128 tokens in the first part and 11 in the continuation, and the tooltip showed "11 tokens / 348 ms" for the 139-token answer. This predates #14909.

Problem

A continued reply (Max Tokens auto-continue, or Continue / Resume) shows one merged answer. Its badge, timing tooltip and response details still describe only the last request, under labels like "Tokens" and "Total" that read as totals for the whole answer.

Cause

Each continuation is a new request with its own streamStartTime. The adapter builds the reply's timing, serverTimings and responseDetails from that request alone, while the text starts from the resumed partial. The continuation request already carries the resumed reply's reasoning time (reasoningDuration), which is why "Worked for" covers the whole answer; nothing carried its timing.

Fix

  • New utils/continued-timing.ts: reads a reply's own figures from its metadata and adds them to a pass's figures. Counts and times add up, the first token is the answer's first, and a rate is the time-weighted mean of the passes' rates, which keeps llama.cpp's definition (decode steps over decode time).
  • thread.tsx: Continue carries the resumed reply's figures as ContinuationRequest.priorTiming.
  • chat-adapter.ts: a pass counts its own output (its usage, or an estimate of only the text it appended) and adds the earlier passes. The response details start at the first pass, and their duration is the passes' own time, not the wait before a manual Continue.
  • A Stop keeps only a reply's last streamed metadata, and an error's has no server figures, so every streamed yield and the error's also carry resumeTiming, the passes so far, for Resume to read.

Behavior boundaries

  • A reply that was never continued keeps exactly its own figures.
  • Context usage (the context meter, and the details sheet's token section) stays per request.
  • A continuation interrupted by a page reload is finished by the recovery path from the backend run, which knows only that request; it keeps the last pass's figures, as on main.
  • A stopped reply still shows no timing badge, as on main.
  • With Generation details off the stream has no per-token timings, so a stopped pass adds its time and estimated tokens but not llama-server's Generation and Speed figures.

Verification

Live A/B with Playwright on fresh Studio homes, gemma-3-270m-it UD-Q4_K_XL on the CPU, the first request capped at 64 tokens so it stops on length and auto-continues, as in the report; main was d8efd157ab for the first table and 6401ceda29 for the second and the screenshot.

Continued reply main this PR
Tokens 278 (continuation only) 263 (64 + 199)
Total 2.03 s (continuation only) 2.20 s (613 + 1,583 ms)
First token 98 ms (the continuation's) 171 ms (the first pass's)
Context usage output 278 199 (per request)

Stop pressed during the continuation, then Resume:

Resumed answer main this PR
Tokens 616 (last pass only) 898 (64 + 121 estimated + 713)
Total 4.26 s (last pass only) 6.32 s (all three passes)

Tests:

  • New continued-reply-timing.test.ts: two and three passes adding up, the report's 128 + 11 merging to 139, a stopped and a broken-off reply's carried figures read by Resume, a never-continued reply left unchanged, and the adapter's wiring (checked in the source, since the adapter only runs against a live stream; the Stop path is exercised end to end above).
  • The 2,205 frontend tests in files touching continuation, the adapter, the timing tooltip, the details sheet or run recovery pass. Typecheck passes; ESLint has no new findings.

Not exercised live: three continuations by Max Tokens alone, and a pass that fails with an error rather than a Stop.

Screenshots

The legend's first-pass figures come from the stored messages:

Timing tooltip of a continued reply, before and after

Additional verification

A regression in the submitted aggregation moved a failed continuation's reply timestamp into the future. Fixed in 1e381c3 by preserving the finish time when combining active durations. The regression test failed with 13,548 instead of 9,348 before the fix and passes afterward. Both comment-reduction passes are complete and passed the comment-only checks.

At head a38b0d4, fresh isolated Studio builds at merge base 6401ced and the PR head received the same scripted 128-token first pass and 11-token continuation. Both sent two requests and rendered identical answer text and byte-identical system prompts. Request bodies matched after removing the isolated homes' provider and thread IDs. The tooltip changed from 11 to 139 tokens, and from 300ms to 4.10s generation. These supplied timing values verify aggregation; they are not a model speed benchmark.

The same two-pass differential also passes in Chromium, Firefox, Microsoft Edge and WebKit, with unchanged request content.

The affected continuation, timing and reply-time tests pass (149 tests); TypeScript checking passes. The broader frontend suite passed 14,618 tests with zero failures and one Windows-only test skipped on Linux. Linux, macOS and Windows scoped staging tests passed for the functional fix.

Continued answer timing before and after: 11 tokens becomes 139, and 300ms generation becomes 4.10s

Studio UI regression check

Base 6401ceda2 vs head a38b0d4dd. Functional: NO_REGRESSION, 1 visual change(s), 0 text-only change(s). Only steps whose screenshots differ are shown.

continued_reply_timing: Same scripted response in fresh base and head installs. These supplied server timings prove aggregation, not model speed. Chromium, Firefox, Edge and WebKit pass; requests and answer text are unchanged.
Facts: tokens: {'before': 11, 'after': 139}; generation_ms: {'before': 300, 'after': 4100}
continued_reply_timing

@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:19:25.861296Z
We couldn’t complete this review. Comment @codex review to try again.
a5bdaa8 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.

danielhanchen added a commit that referenced this pull request Nov 2, 2026
## Summary

`Repo tests (CPU, gloo-tp-pp)` failed on #16444 and #16451 in
`tests/test_pp_env_gloo.py`, which #16407 added. Neither PR touches
pipeline parallel. Both failures are the same case, with an identical
value:

```
test_pp_env_gradient_accumulation_and_microbatches[gemma3_ga1_bs4]
base_model.model.model.layers.0.mlp.gate_proj.lora_A.weight: Tensor-likes are not close!
Mismatched elements: 1 / 64 (1.6%)
Greatest absolute difference: 1.5791505575180054e-05 at index (2, 2) (up to 1e-05 allowed)
```

The identical value means the result depends on the runner's CPU, not on
chance, so any run that lands on that runner type fails.

The adapter comparison runs after several optimizer steps, so it carries
the fp32 reduction-order noise of a 2-stage split against the
single-process reference. The file already records that noise for the
grad norms ("3e-5 absolute ... between two identical reference runs").
On this host, the largest adapter difference across all five cases of
the test is 3.7e-6, which is why 1e-5 looked safe.

## Change

`tests/test_pp_env_gloo.py`: in
`test_pp_env_gradient_accumulation_and_microbatches` only, the
trained-adapter comparison takes `atol = 5e-5`, about 3x the CI value.
`rtol` is unchanged, and so is every other `_same_tensors` call:
save_pretrained, Trainer.save_model and export.

The `_close` call just before it is also unchanged. It pins the step
count and every loss at rel 1e-5. It pins the first grad norm at rel
1e-5 and the rest at 1e-4.

## Testing

- `tests/test_pp_env_gloo.py`: 14 passed, 1 skipped.
- Sabotage: I temporarily scaled every `lora_A` by `1 + 1e-4` in the
pipeline-parallel ranks only. `[ga1_bs4]` and `[gemma3_ga1_bs4]` both
still fail, as they do at `1 + 1e-3`. So a real divergence much smaller
than any pipeline bug would be still fails the test.
@danielhanchen danielhanchen self-assigned this Nov 2, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 2, 2026
@danielhanchen

Copy link
Copy Markdown
Member

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

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 6409704f2 (no equivalent commit found on this PR)

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

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

Reviewed commit: 6409704f26

No triage reaction was recorded on the mirror

Round 2: reviewed mirror bc261f9186 (this PR's 1e381c35b)

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

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

Reviewed commit: bc261f9186

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror bc261f9186 (this PR's 1e381c35b).

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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
@danielhanchen
danielhanchen merged commit 92aaa26 into unslothai:main Nov 2, 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.

2 participants