Skip to content

Studio diffusion: keep the CFG-parallel weight probe inside large inference weights - #14844

Merged
danielhanchen merged 2 commits into
mainfrom
studio-cfg-parallel-probe-integer-index
Oct 23, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-cfg-parallel-probe-integer-index

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

#14626 added weights_probe, which samples 64 bytes from every inference-tensor weight so CFG-parallel can notice an in-place edit and rebuild its replica. The sample offsets came from

torch.linspace(0, n - 1, steps = min(n, 64), device = ...).long()

where n is the weight's size in bytes. linspace runs in float32, so once n - 1 >= 2**24 the last offset can round up to n, one past the end:

weight bytes last offset
3072 x 3072 bf16 18,874,368 18,874,368 (out of range)
3072 x 12288 int8 qdata 37,748,736 37,748,736 (out of range)

On CPU index_select raises IndexError. On CUDA it is a device-side assert in the gather kernel, which poisons the CUDA context: the router catches the exception and turns CFG-parallel off, but every later CUDA call in that Studio process fails too.

It is reached when a denoiser holds inference-tensor weights (loaded or moved under torch.inference_mode) and CFG-parallel engages. The existing tests only use small weights, below 16 MiB.

Fix

The offsets are computed in int64: arange(k) * (n - 1) // (k - 1). That gives the same evenly spaced samples, always ends exactly at n - 1, and stays exact at any size. The per-size index cache and everything else are unchanged.

Tests

  • New test_probe_stays_inside_inference_weights_past_two_to_the_24_bytes: a 3072 x 3072 bf16 inference weight (18,874,368 bytes) must probe without error, return 64 samples, and see a change to its very last byte.
    • main: fails with IndexError: index out of range in self
    • this branch: passes
  • tests/test_diffusion_multigpu.py: 122 passed. The one failure, test_execution_device_reports_the_primary_of_a_split_pipeline, is an ImportError (get_cached_repo_tree) from a diffusers / huggingface_hub version mismatch in the local environment and fails the same way on main.

Not covered

No two-card CFG-parallel render with real inference-tensor weights was run; the fix is checked at the probe level on CPU.

…ffsets so large inference weights stay in bounds
@danielhanchen danielhanchen self-assigned this Oct 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T01:29:33.729361Z 63af03e 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 63af03eb72

ℹ️ 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 89ae8fa into main Oct 23, 2026
2 of 34 checks passed
@danielhanchen
danielhanchen deleted the studio-cfg-parallel-probe-integer-index branch October 23, 2026 02:41
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