Repository navigation
Studio H3 / H3-Image: SageAttention inside the strided processor, no per-call device sync on sm89 - #17639
Conversation
The main env pin moves from 5.5.0 to 5.5.4 (extras-no-deps, no-torch-runtime, single-env constraints and the darwin override), and the Gemma 4 sidecar (.venv_t5_550) moves with it. The highest pre-installed sidecar (.venv_t5_510) moves from 5.10.2 to 5.13.1; its directory and tier key stay, so existing installs rebuild it in place. 5.13.1 checks safetensors>=0.8.0 at import and the sidecar installs --no-deps, so studio.txt now asks for safetensors>=0.8.0 on every platform (it was Windows only). The config-parse log reads the sidecar versions from the tier table instead of hardcoding them.
… kernels package kernels 0.12.3, the release transformers < 5.13 can import next to, reads the hub's model-type copy of kernels-community/sage-attention, whose builds stop at torch 2.12, so on torch 2.13 sage never engaged. The new loader fetches the one build variant this torch needs from the kernel-type repo (the model-type copy is the fallback), reads metadata.json first so an unsupported card downloads nothing else, checks the build's CUDA archs and sha256 digests, and imports it under a private module name. kernels.get_kernel stays as the fallback, and transformers' own kernels import is untouched. kernels_compat now pins the on-demand kernels install on the oldest transformers that will import it: the main env or any sidecar, since the sidecars install --no-deps over the same env.
…all on sm89 The hub build's sm89 route (INT8 Q.K, FP8 P.V) calls torch.cuda.synchronize() after every attention launch. That drains every stream once per call, including a streamed DiT's weight prefetch, so the host stops running ahead of the GPU. The loader now wraps the build's sageattn: on sm89 it runs the same quantisers and attention op with the same arguments in the same order, without the sync, so the output is bit-identical. The build's CUDA ops launch on the default stream whatever stream is current, which is what the sync papered over for its own default-stream callers. The wrapper therefore runs the whole call on the default stream and orders it against a caller on another stream with stream waits (and record_stream for the tensors that cross), so a side stream caller gets the right answer without a host sync. Other cards, causal or LSE calls, grouped heads and head dims other than 64 / 128 call the build as shipped. UNSLOTH_SAGE_SM89_NO_SYNC=0 turns the wrapper off.
…processor A Sage backend (the kernels-hub build or a pip SageAttention 2) used to send every H3 attention call back to the stock processor, which drops Studio's strided layout, the fused q/k RMSNorm + RoPE and the shared QKV act quant. The strided processor now runs those itself and hands the NHD q / k / v it already holds to the same guarded dispatch the stock processor uses, so calls Sage cannot take still run native. Only the work around the kernel changes: the kernel sees the same q / k / v as on the stock route. H3 video installs the strided processor for an engaged Sage backend too. UNSLOTH_H3_STRIDED_SAGE=0 restores the stock processor for Sage.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…equirements/studio.txt does [skip ci]
…_torch AMD SDK / Radeon wheels leave torch.version.hip unset and carry the ROCm tag only in torch.__version__; route the hub loader's CUDA-build check through the shared is_rocm_torch helper like every other diffusion gate, so such a wheel never resolves a CUDA build variant. Adds tests for the tag-only and stock ROCm wheels and a CUDA control.
… floor, main) # Conflicts: # studio/backend/tests/test_diffusion_sage_hub.py
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
# Conflicts: # studio/backend/core/inference/diffusion_sage_hub.py # studio/backend/tests/test_diffusion_sage_hub.py [skip ci]
Summary
Stacked on #17589 (base branch
studio-transformers-5-5-4, which loads the SageAttention hub build). Retarget tomainonce that merges.MiniMax-H3 / H3-Image attention with SageAttention got slower, not faster, because of two problems. This PR fixes both. On an L4 the DiT's attention time per 2048x2048 image drops from 2.8 s (native flash) to 2.0 s with Sage, quantisers included. The output is bit-identical to the existing Sage route.
sage/sage_hub) sent each H3 attention call back to the stock processor. That lost Studio's strided layout, the fused q/k RMSNorm + RoPE and the shared QKV act quant. The strided processor now does all of that itself. It then passes the NHD q / k / v it already holds to the same guarded dispatch the stock processor uses, so calls Sage cannot take still run native. H3 video also installs the strided processor when Sage is the engaged backend. Kill switch:UNSLOTH_H3_STRIDED_SAGE=0.torch.cuda.synchronize()after every attention launch. On the streamed tier that drained the weight prefetch 300 times per image and left the GPU idle for 2.2 s of a 14.3 s denoise. The loader now wraps the build'ssageattn. On sm89 it runs the build's own quantisers and attention op with the same arguments, in the same order, without the sync.UNSLOTH_SAGE_SM89_NO_SYNC=0.Results
Colab L4, streamed int8 tier, torch 2.13.0+cu130, 6 steps, seed-matched. Base is the same tree without these commits, with the per-card attention race from #17615 applied to both arms (on L4 it picks native flash on base and Sage with this PR). Each arm was rendered twice and the repeats were byte-identical. Denoise times are in seconds.
A second L4 VM gave the same deltas: 2048 went from 16.63 / 16.72 to 16.22 / 16.19 s/img, and the edit repeat from 41.45 / 41.71 to 36.63 / 36.68 s/img. At 1024 Sage is a tie: 0.01 to 0.03 s slower.
The table below separates the two fixes. All three arms force Sage (
UNSLOTH_H3_IMAGE_INT8_ATTENTION=1). The first two rows come from one L4 VM (base 13.45 s denoise there) and the last from another (base 13.33 s).L4 profile of one 2048 render (DiT window):
On the edit the attention kernel drops from 50.6 to 28.8 ms per call, plus 3.6 ms of quantisers. The DiT window goes from 40.9 to 36.1 s.
On an A100 (sm80, resident), the race keeps native flash, as before: a block took 6.85 ms with Sage against 6.69 ms native. With Sage forced, 2048 is a tie (3.50 s denoise both) and the edit is 4% faster (10.7 to 10.2 s).
Accuracy
The two fixes do not change any value: every Sage render here is byte-identical to the same render through the existing Sage route. Whether a card uses the checkpoint's INT8 attention at all is a separate policy: on this branch it is used as the checkpoint declares; #17615 adds a per-card race that keeps it only where it times faster, and with this PR that race picks Sage on L4 (native on A100). For that decision, Sage against native:
Tests
tests/test_video_minimax_h3_attn.pyadds CPU tests:tests/test_diffusion_sage_hub.pyadds CPU tests for the sm89 wrapper: the ops and arguments it runs, every fallback, the kill switch, other cards, and builds without the sm89 parts.sageattnat the 2048 and edit shapes, called from both the default stream and a side stream.