Skip to content

Studio: report first-step training and gradient accumulation - #15480

Merged
danielhanchen merged 6 commits into
mainfrom
fix/training-startup-phase
Oct 28, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
fix/training-startup-phase

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

A new training run switches to Training in progress when the trainer loop begins, before it has run an optimizer step or produced a loss. The startup overlay then appends waiting for first step (0) and keeps showing repository byte counters, making an active first step look like a stalled download.

Report milestones from the real trainer callbacks:

  • Starting training loop at train begin.
  • Running first training step (batch 1 of up to 4), advancing with gradient-accumulation substeps.
  • First training step finished. Waiting for the first loss measurement until a loss is logged.
  • Training in progress once that first measured loss is available.

The shared helper covers SFT/vision/audio callbacks and the decision/embedding callback. It handles resumed steps relative to this session, short final accumulation groups, pre-train evaluation/log callbacks, and zero loss. It never labels unknown work as compilation and respects stop requests.

The overlay displays the actual status without the generic (0) suffix. Once a real trainer callback confirms loop entry, it stops polling and displaying the repository download rows; a cache scanner's different file subset can no longer imply another download while batches execute. Resource loading/preparation and its progress bars remain visible before loop entry.

Validation:

  • 23 backend startup/callback tests passed, including actual SFT and decision/embedding callback-to-parent events; the final inactive-state guard was additionally verified by all 5 helper tests.
  • 15 frontend preparation/phase tests passed.
  • Frontend typecheck (including tests), Ruff, and git diff --check passed.

No training was started for validation. The UI reports callback milestones, not an estimated percentage for unknown compilation time.

Before / after

Train > Current Run start overlay halfway through the first optimizer step (gradient accumulation 4, step 0, model cache scan short of the expected bytes). Each side renders its own frontend build with the status its own backend emits at that moment: base reports Training in progress... from train begin, this PR reports the batch milestone (sequence captured from a real Unsloth SFT run on a T4).

Training start overlay before and after

Before: the overlay keeps the preparation lines, appends waiting for first step... (0) and keeps polling and drawing the Model weights download row. After: only the real milestone, no download row (0 download-progress polls once the loop has started).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-28T10:08:20.913412Z 618205c 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 added a commit that referenced this pull request Oct 27, 2026
…#15493)

## Problem

`Repo tests (CPU, rest)` fails on main since #15368, so every PR based
on it inherits 8 failures (#15474, #15475, #15479, #15480, #15481 and
others):

```
tests/test_for_training_generation_flag.py::test_for_training_deletes_a_generation_flag_delegated_by_a_peft_wrapper[llama.py-FastLlamaModel]
unsloth/models/llama.py:5526: in for_training
    _tensor_parallel_for_training(model)
E   TypeError: 'NoneType' object is not callable
```

All 8 parametrizations fail the same way, for `llama.py` and
`vision.py`.

## Product or test

The test. It lifts `for_training` out of `llama.py` / `vision.py` with
`ast` and runs it in a namespace where any name it did not lift resolves
to `None`. From `_utils.py` it lifted a hardcoded list of ten helpers.
#15368 made `for_training` call a new `_utils` helper,
`_tensor_parallel_for_training`, which is not on that list, so the
lifted code called `None`. `for_training` itself is fine: the helper
only restores the sharded parameters on a tensor-parallel model and does
nothing otherwise.

## Fix

The hardcoded list stays as roots. On top of it, the test now lifts
every `_utils.py` function that `for_training` or those helpers reach by
name, transitively, with the same walk it already used for helpers in
the model file (factored into `_closure`). A helper added later is
lifted the same way instead of turning into `None`.

## Verification

- `tests/test_for_training_generation_flag.py`: 8 passed (8 failed on
main).
- Sabotage:
- With `del m._flag_for_generation` replaced by `pass` in `llama.py`
(the behaviour this test guards), 2 fail, so the guard still bites.
- With `_tensor_parallel_for_training` made to raise, 6 fail. The lifted
helper is the real one and actually runs, not a stand-in.
- ruff format and check are clean.
@danielhanchen danielhanchen self-assigned this Oct 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

3 similar comments
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 28, 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: 08a4f32ef5

ℹ️ 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 +432 to +434
{!trainingLoopStarted && (
<>
<TypingAnimation duration={44}>

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 Keep animated intro lines as direct Terminal children

On the initial overlay mount for a new job (instant=false), this fragment stalls the terminal animation before the status and download rows appear. Terminal in components/ui/terminal.tsx enumerates only direct children and injects __onDone into each to advance activeIndex; React treats the fragment as one child, and it never invokes that callback. Consequently, the subsequent status and resource rows remain at opacity-0 throughout model/dataset preparation, until loop entry removes the fragment. Render the two conditional TypingAnimation elements as separate direct children, or explicitly make Terminal handle fragments.

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 618205c: the two intro lines are now separate direct children, since Children.toArray does not traverse a Fragment and the cloned Fragment never calls __onDone. The stall lasted until the next re-render flipped instant on, so it delayed the rows rather than hiding them for the whole preparation.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 618205c6cd

ℹ️ 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 4ac4e91 into main Oct 28, 2026
5 of 48 checks passed
@danielhanchen
danielhanchen deleted the fix/training-startup-phase branch October 28, 2026 10:57
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.

1 participant