Skip to content

Studio: read the SDXL v-prediction markers beside the weight load and once per commit, skip the UNet scheme probe - #16696

Merged
danielhanchen merged 4 commits into
mainfrom
studio-load-marks-overlap
Nov 4, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-load-marks-overlap

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

An SDXL pipeline load on an L4 took 24-25 s before the first image. Profiling one load (py-spy, fresh process, warm disk cache) showed two avoidable costs:

  • About 6 s checking for v-prediction markers. After the weights loaded, the load listed the repo and read the header of every root .safetensors file (base, 0.9 VAE, offset LoRA) one after another: 15 HTTP requests. A returning user paid it again (18 requests), although the result was already recorded per commit; only offline loads used the record.
  • About 3.4 s on the transformer-quant scheme probe, a child process, although a UNet family has no quantised scheme to seed.

Change

  • diffusion_sampler.py:
    • start_root_single_marks starts the marker read on a daemon thread before from_pretrained, with the caller's context copied, so the Hub reads overlap the weight load. apply_pipeline_prediction_type(..., marks_future=) waits for it; if the background read failed, it reads again inline.
    • The root file headers are read in parallel.
    • An online load of a commit whose markers are already recorded uses the record (a commit cannot change), so a returning load makes no marker requests.
  • diffusion.py: the scheme probe is skipped for a UNet family with no prequant repos.
  • Tests: test_diffusion_unet_skips_scheme_probe.py (new) and test_diffusion_vpred_sdxl_detect.py (5 new tests; one existing assertion that required re-reading an already recorded commit now asserts no Hub call, and that a new commit is still read).

Evidence

SDXL 1024x1024 on one L4, main vs this PR interleaved, output bit-identical:

arm load (s) first image (s) steady s/img
main, new user 25.0-25.8 35.1-36.5 9.65-9.67
this PR, new user 15.1-17.5 25.0-27.6 9.53-9.66
main, returning user 20.1-25.0 30.0-35.1 9.62-9.67
this PR, returning user 14.2-18.8 24.1-28.8 9.65-9.68
  • A returning load makes 5 HTTP requests instead of 18.
  • Steady speed is unchanged.

Tests

  • 54 passed in the two files; 6 fail on main.
  • The related diffusion suites pass (1047).
  • AMD gfx1151 (Linux, ROCm), base and head in the same job: no regressions (194 of 194).

Not covered

  • The lazy import of the SDXL pipeline class (about 5 s, transformers' CLIP) is not prewarmed here; it needs a real Studio startup to measure.

@danielhanchen danielhanchen self-assigned this Nov 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-11-04T19:43:20.525534Z 49edb30 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: 718b8cfaee

ℹ️ 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 +9502 to +9506
start_root_single_marks(
_base_local_dir or fetch_base,
fetch_base,
hub_token,
not local_files_only,

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 Bind the early marker read to the revision being loaded

For a direct load_pipeline() call without _base_local_dir, this starts the marker lookup against a Hub ID before from_pretrained() resolves its revision. If the cache's refs/main still points to commit A but the repository now serves commit B, _snapshot_commit() selects A and the future returns A's markers, while from_pretrained() subsequently downloads B. apply_pipeline_prediction_type() then unconditionally uses those precomputed markers, potentially applying v-prediction to epsilon weights (or vice versa) and corrupting generated images. Previously the lookup ran after the weight load updated the cached revision. Only overlap the read when the load has a staged, commit-pinned snapshot, or resolve and pin the same commit for both operations.

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 49edb30: the overlapped read starts only when the base snapshot is staged locally (_base_local_dir, the commit from_pretrained loads). A Hub id resolves its revision inside from_pretrained, so it reads after the load as before (test_the_marker_read_overlaps_only_a_staged_snapshot).

A Hub id resolves its revision inside from_pretrained; an early read could take
refs/main's older commit while the load downloads a newer one.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 49edb305c5

ℹ️ 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 5c2d611 into main Nov 4, 2026
@danielhanchen
danielhanchen deleted the studio-load-marks-overlap branch November 4, 2026 21:13
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.

1 participant