Skip to content

Studio GGUF: keep the stock Q8_0 forward on torch below 2.7 - #16911

Merged
danielhanchen merged 2 commits into
mainfrom
studio-gguf-q8-0-fused-torch-floor
Nov 6, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-gguf-q8-0-fused-torch-floor

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #16884.

#16884 replaced GGUFLinear.forward_native for Q8_0 weights with one compiled dequant+cast kernel. On torch 2.6 that kernel is lowered wrongly by inductor: on an A100 with torch 2.6.0+cu124 (Triton 3.2.0), 24421 of 24576 weight elements differ from the stock dequant for real gguf-quantized Q8_0 blocks, in bf16, fp16 and fp32 alike, with and without emulate_precision_casts. Nothing raises, so the compile guard never falls back and a Q8_0 GGUF render on torch 2.6 runs with corrupted weights. On CPU, torch 2.6 cannot build the kernel at all (CppCompileError, a float & int16 in the generated C++).

Studio still keeps existing installs on torch 2.4 to 2.14 (install.sh preservation path, the torch>=2.4 ROCm and gfx906 routes), so torch 2.6 is reachable.

This PR installs the fused forward only from torch 2.7. Below that, every Q8_0 layer keeps the stock forward over the compiled dequant, which is what ran before #16884. Nothing changes on torch 2.7 and later.

Torch sweep (A100, same script, real Q8_0 blocks and random-byte blocks, 12 cells per version)

torch Triton fused == stock (cells) stock compiled dequant == eager (cells)
2.6.0+cu124 3.2.0 0 / 12 12 / 12
2.7.1+cu126 3.3.1 12 / 12 12 / 12
2.8.0+cu128 3.4.0 12 / 12 12 / 12
2.9.1+cu128 3.5.1 12 / 12 12 / 12
2.10.0+cu128 3.6.0 12 / 12 12 / 12
2.11.0+cu130 3.6.0 12 / 12 12 / 12
2.15.0+cu132 3.9.0 12 / 12 12 / 12

No graph breaks and one dynamic graph across four layer shapes on every version. On gfx1151 (torch 2.11.0+rocm7.13.0) the fused kernel is also bit-identical on real Q8_0 blocks, so ROCm on 2.7+ keeps it.

Tests

  • test_fused_q8_0_torch_floor: the version parse, including ROCm and dev tags.
  • test_torch_below_the_floor_keeps_the_stock_forward: with torch.__version__ set to 2.6.0 the dequant compile still installs, the fused forward does not. Fails with the gate removed.
  • The compile-dependent tests skip below the floor instead of failing.

pytest studio/backend/tests/test_diffusion_gguf_fused_q8_0.py studio/backend/tests/test_diffusion_gguf_compile.py: 40 passed on torch 2.12.

torch 2.6's inductor lowers the fused Q8_0 dequant+cast kernel wrongly on CUDA (almost every weight differs from
the stock dequant on an A100) and cannot build it on CPU, so a Q8_0 GGUF render there gets corrupted weights.
2.7.1 through 2.15 are bit-identical. Install the fused forward only from torch 2.7; the compiled dequant itself
is unchanged.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 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-06T13:11:52.036351Z 6200a5a 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. What shall we delve into next?

Reviewed commit: 6200a5a289

ℹ️ 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 added a commit to Imagineer99/unsloth that referenced this pull request Nov 6, 2026
danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 6, 2026
@danielhanchen
danielhanchen merged commit 257e925 into main Nov 6, 2026
@danielhanchen
danielhanchen deleted the studio-gguf-q8-0-fused-torch-floor branch November 6, 2026 14:52
danielhanchen added a commit that referenced this pull request Nov 7, 2026
…16922)

## Summary

`pip scan-packages :: hf-stack` fails on main since unsloth-zoo
2026.11.3 reached PyPI at 14:20 UTC today (run 42237847432, on the
#16911 merge commit):

```
Summary: 3 CRITICAL, 4 HIGH, 172 MEDIUM
  7 of the 179 finding(s) above are at a site already reviewed in scripts/scan_packages_baseline.json. What differs from the reviewed entry:
    HIGH      unsloth-zoo  unsloth_zoo/compiler.py                     same matched code, file digest outside the pin
    CRITICAL  unsloth-zoo  unsloth_zoo/llama_cpp.py                    same matched code, file digest outside the pin
    HIGH      unsloth-zoo  unsloth_zoo/mlx/loader.py                   same matched code, file digest outside the pin
    HIGH      unsloth-zoo  unsloth_zoo/temporary_patches/moe_utils.py  same matched code, file digest outside the pin
    CRITICAL  unsloth-zoo  unsloth_zoo/vision_utils.py (env + network) same matched code, file digest outside the pin
    CRITICAL  unsloth-zoo  unsloth_zoo/vision_utils.py (IMDS + network) same matched code, file digest outside the pin
    HIGH      unsloth-zoo  unsloth_zoo/vllm_utils.py                   same matched code, file digest outside the pin
```

This is the per-release re-review the digest pins are for, as in #16732
(2026.11.2) and #16624 (2026.11.1).

## Review

I read the seven files in the 2026.11.2 and 2026.11.3 wheels downloaded
from PyPI. In every file the matched code is unchanged (each new entry
has the same `evidence_hash` as an already reviewed one), and none of
the changed lines touch `exec`, `eval`, `compile`, `marshal`, `zlib`,
`base64`, `__import__`, environment reads, HTTP / socket calls or the
metadata address.

| File | What changed in 2026.11.3 | Verdict |
|---|---|---|
| `unsloth_zoo/llama_cpp.py` | unsloth-zoo#2414: reuse an intact
llama.cpp source checkout for LoRA export; when converter modules are
missing and auto install is on, `pip install gguf protobuf sentencepiece
mistral_common` through the existing `try_execute` / `check_pip` | Same
as reviewed |
| `unsloth_zoo/vision_utils.py` | unsloth-zoo#2411 / #2415: PyAV
fallback converts only the sampled frames, `torch.from_numpy` for decord
clips, `startswith` fast path for the prompt prefix | Same as reviewed |
| `unsloth_zoo/compiler.py` | unsloth-zoo#2417: read def names once
instead of a regex per name | Same as reviewed |
| `unsloth_zoo/mlx/loader.py` | unsloth-zoo#2412 / #2407: mlx-vlm 0.7.12
source hashes for MiniCPM-V 4.7 | Same as reviewed |
| `unsloth_zoo/temporary_patches/moe_utils.py` | unsloth-zoo#2413:
prefer the per-expert loop over the Triton grouped GEMM below sm80 |
Same as reviewed |
| `unsloth_zoo/vllm_utils.py` | unsloth-zoo#2410: collect only the LoRA
subtrees in `load_lora` | Same as reviewed |

## Change

As in #16732, each new entry sits right after the reviewed entries for
its file, pinned at the 2026.11.3 file digest. The entries come from
`scripts/scan_packages.py unsloth-zoo==2026.11.3 --write-baseline` and
were copied in; the baseline was not regenerated, so every other
package's entries are untouched. Nothing is removed, so shards that
still resolve older zoo releases are unaffected. 63 added lines, one
file.

## Testing

- `scripts/scan_packages.py unsloth-zoo==2026.11.3`: exit 1 on main (3
CRITICAL, 4 HIGH), exit 0 with this change (13 MEDIUM).
- `scripts/scan_packages.py unsloth-zoo==2026.11.2` and `==2026.11.1`:
exit 0 with this change.
- `tests/security/test_scan_packages.py`,
`tests/security/test_lint_av_shapes.py`,
`tests/test_scripts_write_lf.py`: 181 passed.
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