Repository navigation
Studio MOSS-Image: INT8 attention route, shared Q/K/V quant, bf16 compiled from the first render (11-35% faster) - #18090
Conversation
… share one q/k/v activation quant The in-tree MOSS-Image blocks now call their module's dispatch_attention_fn (read per call), carry head_dim and mark their processor, so the INT8 attention dispatch route can take their unmasked joint attention. MOSS-Image joins AUTO_DITS, raced per card like the other families, but only when its own Linears are quantized (AUTO_QUANTIZED_ONLY): a bf16 load keeps its attention as the accuracy reference. On a ConvRot int8 checkpoint the three projections read the same input, so q / k / v now run on one rotation + activation quant through the int8 GEMM swap's shared_rotq_linears instead of three (the same op on the same tensor; the compiled graph around it changes, so images match within compile noise). Kill switch UNSLOTH_DIFFUSION_MOSS_SHARED_QKV=0.
A dense MOSS-Image load with speed unset ran the deferred profile: two exact eager images, compiled from the third. The eager port is host-bound (1024 px bf16: 14.5 s vs 8.0 s compiled per image on an RTX PRO 6000, 27.5 s vs 12.9 s on an A100), so the second and third images ran about 1.8x slower than the compiled path. A new FamilyProfile field, compile_from_render_one, carries that measured reason; a family that sets it engages the default speed tier from render 1, as the INT8 default and the small-DiT bf16 rule already do. An explicit speed request still wins.
…inside the act quant On a ConvRot int8 checkpoint the compiled block wrote the bf16 SiTU-GLU product (4 tanh(g / 4) sigmoid(g) * 25 tanh(v / 25)) to memory, then the down projection's rotation + act quant read it back. rotq_h16x, which already builds the SwiGLU product from the projection's two halves, takes an ACT constexpr for SiTU-GLU (fp32 math, one bf16 rounding, as the compiled chain), behind its own per-device probe (codes_close vs the stock product + rotation + quant) and op (unsloth_studio::convrot_situ_act_quant_int8). The MOSS block calls int8_gemm.situ_linear when the down projection is a swapped ConvRot Linear and falls back to the stock product and projection otherwise. Kill switch UNSLOTH_DIFFUSION_MOSS_SITU_FUSED=0 (and the producer switch).
…measured faster Building the SiTU-GLU product inside the down projection's act quant saves about 1% per image on sm120 (RTX PRO 6000, 4.914 -> 4.859 s at 1024 px) but costs about 2% on sm80 (A100, 8.791 -> 8.985 s). Arm it on sm120 only; other cards keep the compiled stock SiTU. UNSLOTH_DIFFUSION_MOSS_SITU_FUSED=1 still forces it on any card whose probe passes.
On an L4 the fused SiTU-GLU act quant takes 30.76 -> 29.45 s per 1024 px image (s/step 1.170 -> 1.134; repeated head run 29.90 s, 1.139), so sm89 joins sm120 in the default set. sm80 stays off.
|
@codex review |
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 Summary: ❌ FailedThis 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: Didn't find any major issues. Keep it up! 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". |
…t alias (teardown errors since #18080) (#18097) Since #18080 the Studio CPU shards (`rest`, `g-l`, `m-r`) error at teardown on any worker that imported `torch._dynamo` earlier. Seen on the staging runs of #18003, #18080 and #18090, e.g.: ``` ERROR at teardown of test_torchao_export_rejected_early_when_stubbed[torchao_fp8] torch/overrides.py:1778: has_torch_function = _add_docstr( RuntimeError: function '_has_torch_function' already has a docstring ERROR at teardown of test_versions_are_checked_before_imports AssertionError: imported a package the version check already rejected ERROR at teardown of test_a_broken_torch_import_is_retried_once_per_detection_epoch OSError: libcudart.so.12: cannot open shared object file ``` ## Cause The `_restore_dynamo_process_knobs` fixture from #18080 snapshots and restores `cache_size_limit`. On torch 2.6+ that entry is an alias of `recompile_limit`, and torch resolves an alias read with `importlib.import_module("torch._dynamo.config")`. Several tests take torch out of `sys.modules` and block imports to exercise the no-torch paths (`test_torchao_select.py`, `test_mlx_stack_blockers.py`, `test_polled_probe_costs.py`, `test_warm_window_review_fixes.py`, `test_hub_download_transport_auto.py`, `test_mlx_repair.py`). The fixture teardown runs before their monkeypatches are undone, so the alias read re-imported torch under the blocker. Those tests are correct, and the reset itself is still wanted; only the alias read was wrong. ## Fix `_dynamo_own_knobs(cfg)` keeps only the config's own entries (`_config[k].alias is None`). Restoring `recompile_limit` already covers `cache_size_limit` on new torch, and on older torch, where `cache_size_limit` is a real entry, it is still restored. Reading an own entry never imports. New `test_conftest_teardown_imports_nothing.py` imports `torch._dynamo`, takes torch out of `sys.modules` and makes `importlib.import_module` fail for torch, so any conftest teardown that imports torch errors. ## Verification Run locally with `torch._dynamo` already imported on the worker, as in CI: - main conftest: 14 teardown errors across `test_torchao_select.py`, `test_mlx_stack_blockers.py`, `test_polled_probe_costs.py`, `test_warm_window_review_fixes.py`, `test_hub_download_transport_auto.py` and `test_mlx_repair.py` (the CI ones), and the new test errors too. - this branch: all pass (196 and 188 passed in the two runs). - `test_process_state_reset_between_tests.py` still passes, so the knob reset still works.
# Conflicts: # studio/backend/core/inference/diffusion_int8_attention_dispatch.py # studio/backend/tests/test_diffusion_int8_attention_dispatch.py [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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". |
…he fused SwiGLU (#18798) On the MiniMax-H3-Image streamed tier, every MLP ran the stock forward. This is the tier 24 GB cards get (L4, 3090, a capped Ada). `_install` in `diffusion_minimax_h3_image_speed.py` installed the fused SwiGLU only when the levers held the exact string `"h3_int8_gemm"`, but the streamed route records `"h3_int8_gemm_streamed"`. So on those cards `value * silu(gate)` was written out in bf16, then rotated and quantised again for the down projection, in every block and every step. The resident tiers have fused this since #18090 / #18284. ## Change - The fused SwiGLU now installs on both int8 GEMM routes. - This is safe on the streamed route for three reasons: - The pinned streamer keeps the swapped Linears and copies into their parameters. That is the condition `int8_gemm_route` already requires before it picks the streamed GEMM. - `producer_linear` returns `None`, which falls back to the stock MLP, for any call whose weight is not on the card. - `_ready` falls back as well whenever the SwiGLU module or the down Linear has a hook. The input projection still runs its own forward, so its hooks are kept. - The pageable streamer, which swaps parameters per call, still gets neither the GEMM nor the fused MLP. - `UNSLOTH_H3_FUSED_SWIGLU=0` keeps the stock MLP, as before. - Q / K / V fusion stays resident-only. Merging the three weights into one buffer would leave the streamer copying into parameters the GEMM no longer reads. ## Tests - `test_the_fused_swiglu_installs_on_every_int8_gemm_route` (CPU, 5 cases): pinned streamed installs it, resident installs it, `UNSLOTH_H3_FUSED_SWIGLU=0`, `UNSLOTH_H3_IMAGE_INT8_GEMM_STREAMED=0` and the pageable streamer do not. - The streamed-pinned case fails on main and passes here (`test_differential.py`: DISCRIMINATING, no head failures). - `tests/test_diffusion_minimax_h3_image_speed.py`, `tests/test_h3_fused_swiglu.py`, `tests/test_h3_image_resident_route.py`: 62 passed. ## GPU (Colab L4, 22.5 GB: the streamed tier) H3-Image at 1024x1024, 6 steps, `streamed` placement. Main and this branch ran in fresh processes on one VM, sharing one Studio home, with 2 warm-up cells and then 3 interleaved reps per arm. The batch ran twice, on two VMs, after an infrastructure retry. | VM | main s/step | branch s/step | delta | |---|---|---|---| | 1 | 0.8628 | 0.8472 | -1.8% | | 2 | 0.8652 | 0.8518 | -1.5% | Medians of 9 steady renders per arm. - **Fused-SwiGLU calls:** 1500 to 2100 per cell here, 0 on main. - **Images:** identical to main, with LPIPS 0.000 and `torch.equal` on all 4 prompts on both VMs. Every arm also repeats itself bit for bit. - **Peak allocated memory:** 17.98 GiB on both arms. ## Not proven here - sm86 (3090) is not a Colab tier. - No larger-card resident-tier comparison ran. It is not needed for accuracy, because the streamed images match main bit for bit.
Summary
MOSS-Image renders faster on every card measured, with images within the INT8 floor. There are three changes, plus a per-card gate on the third.
UNSLOTH_DIFFUSION_MOSS_SITU_FUSED=1forces it on.Results
Settings for every row:
Per-change ablations: each row turns one change off against the full branch on the same VM, SFT default.
Image change per fix (mean LPIPS, against the arm with that fix off, RTX PRO 6000 / A100 / L4):
L4 profile: bf16 cuDNN attention took 1495 ms per 4-step render before, and the INT8 attention kernel takes 807 ms after. No graph breaks and no recompiles.
Testing
test_diffusion_moss_speed_routes.pycovers the attention route, the shared quant, the compile-from-first-render rule, the SiTU gate per arch and the kill switch.Not covered