Skip to content

Report measured model loading and 4-bit conversion during image training - #15536

Merged
danielhanchen merged 5 commits into
mainfrom
fix/diffusion-model-load-progress
Oct 30, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
fix/diffusion-model-load-progress

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Image training can spend a long time loading weights or converting them to 4-bit without reporting how much work is complete. This adds scoped loader observers in the training worker and carries successful tensor/component/shard counts through the service and HTTP status schema to the existing progress UI. Conversion is credited only after it succeeds; the text explains that cached downloaded weights can still be converted in memory on each run.

This PR targets main and is independent of #15535. Either PR can be reviewed and merged first.

The existing shared download manager remains responsible for HTTP/XET transfers. Active downloads suppress retained loading counts, and preparation, training, cancellation/error/completion clear them. The observers restore library hooks on exit and fall back to ordinary waiting feedback for unsupported loader API shapes.

Validation on the independent branch:

  • 229 backend tests passed: service, measured loading, shared downloads and DiT trainer coverage. Includes a real tiny sharded model load with exact weight preservation, failed-conversion accounting, hook restoration, HTTP schema preservation and terminal cleanup.
  • Frontend production build and 17 progress-state tests passed without Clarify training setup feedback and the music entry flow #15535.
  • Fresh full-page Playwright main-versus-head comparison verified measured 4-bit loading at 28/62 tensors. Screenshots use controlled API events.
  • Python lint and repository-pinned formatting passed before the clean rebase.

No new full-size FLUX training run is claimed. Basic UI/music refinements, download readiness/preflight and reusable quantized weights are outside this PR.

UI before / after

Both builds were served the same mid-load status (4-bit conversion, 28 of 62 weight tensors). Main shows the generic loading card with an elapsed timer and an empty bar; this branch shows the conversion stage, the measured count and 45%.

Image training load progress, before and after

@Imagineer99
Imagineer99 force-pushed the fix/diffusion-model-load-progress branch from 53a0800 to 1ce53aa Compare October 27, 2026 11:04
@Imagineer99
Imagineer99 changed the base branch from fix/media-training-ux to main October 27, 2026 11:04
danielhanchen added a commit that referenced this pull request Oct 27, 2026
…5501 (#15549)

`Source lint` and `workflow-trigger lint`
(`tests/security/test_lint_risky_loaders.py::test_the_tree_matches_the_baseline`)
fail on main since #15501 merged, and so on every PR based after it
(e.g. #15536, job 122152574837):

```
1 risky loader call site(s) not in the baseline:
  unsloth/_cpu_init.py:205  [dynamic-import] spec_from_file_location
```

#15501 added `_load_dataprep` to the CPU backend init, which loads
`unsloth/dataprep/raw_text.py` and `ebooks.py` by file (so it skips
`dataprep/__init__`, which needs a GPU device type). The call is safe,
but the baseline entry was not recorded before it merged.

## Review

- The path is `Path(__file__).resolve().parent / "dataprep" /
f"{name}.py"`, inside the installed package.
- The only callers pass the constants `"raw_text"` and `"ebooks"`, and
`_load_dataprep` is deleted right after, so nothing else can reach it.
- This is the same shape as the existing `unsloth/__init__.py` entry
that loads `dataprep/ebooks.py` by file on MLX.

## Change

One entry from `python scripts/lint_risky_loaders.py --update`, with the
reason filled in. Nothing else in the baseline moves.

## Verification

- `python scripts/lint_risky_loaders.py`: main reports the site above
and exits 1; this branch prints `ok: 111 risky loader call site(s), all
recorded`.
- `tests/security/test_lint_risky_loaders.py`: main 1 failed, 45 passed;
this branch 46 passed.
- The entry is digest-pinned to the call: changing its path argument to
`os.environ["X_DATAPREP"]` reopens the site and the lint exits 1 again.
@danielhanchen

Copy link
Copy Markdown
Member

(Python 3.13, a-f) fails 8 tests here (job 122152575587), both from the new diffusers imports. The backend shard does not install diffusers:

  1. tests/test_diffusion_load_progress.py (new, 6 tests) imports diffusers directly:

    tests/test_diffusion_load_progress.py:13: in test_real_sharded_model_counts_loaded_tensors_and_preserves_weights
    E   ModuleNotFoundError: No module named 'diffusers'
    

    A module-level pytest.importorskip("diffusers") (or stubbing the loader modules the way the neighbouring diffusion tests do) keeps it from failing where diffusers is absent.

  2. tests/test_diffusion_training_download_phases.py::test_dit_resumes_download_progress_after_preparation (2 params) passes on main but fails here:

    core/training/diffusion_dit_trainer.py:2534: in _train_dit
    core/training/diffusion_load_progress.py:26: in report_model_load_progress
    E   ModuleNotFoundError: No module named 'diffusers.models'; 'diffusers' is not a package
    

    That test stubs diffusers as a plain module, and report_model_load_progress now imports diffusers.models / diffusers.utils unconditionally whenever on_event is set. Since the progress reporting is meant to fall back without blocking training, wrapping those three imports in try/except ImportError and yielding without progress (as is already done for transformers.core_model_loading) fixes this test and also covers a diffusers build that lacks model_loading_utils.

Copy link
Copy Markdown
Member Author

This PR adds measured progress while Unsloth prepares an image-training model, including loading and 4-bit conversion.

Model loading and 4-bit conversion: before, the page shows generic loading feedback with an indeterminate bar. After, it reports completed work: 28 of 62 weight tensors processed → 45%, with clearer wording that downloaded files are reused while conversion runs in memory each time.

Before and after: measured model loading and 4-bit conversion

Encoder loading: the page also identifies the conditioning stage and reports component progress—1 of 3 components → 33% in this scene.

Before and after: encoder and component loading progress

Compared the PR merge base 34969fde40 with 6f034c3b59. Playwright captured separately built production frontends using controlled API responses generated by each revision's training service and response schema. These demonstrate the UI and state handling; they are not a full-model GPU training run or a real network download.

All six states passed on both revisions (12 captures), including fallback without measured counts and switching correctly to download, preparation, and training feedback.

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

Copy link
Copy Markdown
Member

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

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 759ed5b5f5 (this PR's 759ed5b5f)

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

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

Reviewed commit: 759ed5b5f5

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 759ed5b5f5 (this PR's 759ed5b5f).

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

@danielhanchen
danielhanchen marked this pull request as ready for review October 30, 2026 09:50
@danielhanchen
danielhanchen self-requested a review as a code owner October 30, 2026 09:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-30T09:50:27.372039Z
We couldn’t complete this review. Comment @codex review to try again.
759ed5b Draft marked ready
ℹ️ 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
danielhanchen merged commit b48b16e into main Oct 30, 2026
@danielhanchen
danielhanchen deleted the fix/diffusion-model-load-progress branch October 30, 2026 09:50
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