Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions docs/source/en/quantization/gguf.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ rendered properly in your Markdown viewer.

## Load GGUF models

Install [kernels](https://huggingface.co/docs/kernels/index), otherwise the packed path falls back to full [dequantization](#dequantize) at load.

```bash
pip install kernels
```

Weights stay packed when the Hub kernel [transformers-community/ggml-quantization](https://huggingface.co/transformers-community/ggml-quantization) is available. The loader defaults to MPS when that kernel is present and runs matmuls directly on the packed blocks. If the kernel isn't available, the model is dequantized at load.

```py
from transformers import AutoModelForCausalLM, AutoTokenizer

Expand All @@ -35,14 +43,21 @@ model = AutoModelForCausalLM.from_pretrained(model_id, gguf_file=filename)
tokenizer = AutoTokenizer.from_pretrained(model_id, gguf_file=filename)
```

The weights only stay in their GGUF blocks on Metal (MPS) devices, where the [llama.cpp](https://github.com/ggerganov/llama.cpp) kernels, fetched from the Hub, run the matmuls directly on the packed blocks to keep inference fast.
The same load works for Qwen3.5 MoE.

```py
moe_model_id = "unsloth/Qwen3.5-35B-A3B-GGUF"
moe_filename = "Qwen3.5-35B-A3B-Q4_K_M.gguf"

moe_model = AutoModelForCausalLM.from_pretrained(moe_model_id, gguf_file=moe_filename)
moe_tokenizer = AutoTokenizer.from_pretrained(moe_model_id, gguf_file=moe_filename)
```
Comment on lines +46 to +54

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet, but i've opened a bit that enables it ! so we should merge this pr after the other PRs gets merged

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.

good to merge now that #48529 is merged or are there more/other PRs we should also wait for?


Right now, the only architecture supported is Qwen3.5. Everything else falls back. On another device or quantization type, the model is [dequantized](#dequantize) at load time, and an architecture that isn't supported yet goes through the legacy loader.
The packed path currently supports Qwen3.5 and Qwen3.5 MoE. Packed loads use float32 automatically because it's faster on MPS. If you set another `dtype`, the loader returns a warning. Other architectures go through the legacy loader.

## Attention

On Metal, attention has a ggml kernel too: [ggml-attn](https://huggingface.co/transformers-community/ggml-attn), the same
flash attention llama.cpp runs, for both decode and prefill.
On Metal, with kernels installed, attention can use [ggml-attn](https://huggingface.co/transformers-community/ggml-attn), the same flash-attention kernel llama.cpp uses for decode and prefill.

```py
model = AutoModelForCausalLM.from_pretrained(
Expand All @@ -65,16 +80,16 @@ model = AutoModelForCausalLM.from_pretrained(
)
```

The model that comes out is a regular dense model, so this is also how you take a GGUF checkpoint into the dtype you passed.
You get a regular dense model in the `dtype` you passed.

Architectures other than Qwen3.5 are read by the legacy loader which dequantize the model also.
Architectures other than Qwen3.5 and Qwen3.5 MoE go through the legacy loader, which always dequantizes.

> [!TIP]
> The legacy loader supports Llama, Mistral, Qwen2, Qwen2Moe, Phi3, Bloom, Falcon, StableLM, GPT2, Starcoder2, and [more](https://github.com/huggingface/transformers/blob/main/src/transformers/integrations/ggml.py).

## Serve

[`transformers serve`](../serve-cli/serving) names a GGUF model `<repo>:<file>.gguf`, since a repository holds
[transformers serve](../serve-cli/serving) lists each `.gguf` file in a repository as its own model. A GGUF model is named `<repo>:<file>.gguf`, since a repository holds
several quantizations and the id has to say which one to load. Requests name it the same way.

```shell
Expand Down
2 changes: 1 addition & 1 deletion docs/source/en/quantization/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Use the Space below to help you pick a quantization method depending on your har
| [EETQ](./eetq) | 🟢 | 🔴 | 🟢 | 🔴 | 🔴 | 🔴 | ? | 8 | 🟢 | 🟢 | 🟢 | https://github.com/NetEase-FuXi/EETQ |
| [Four Over Six](./fouroversix) | 🟢 | 🟢 | 🟢 | 🔴 | 🔴 | 🔴 | 🟢 | 4 | 🔴 | 🟢 | 🟢 | https://github.com/mit-han-lab/fouroversix |
| [FP-Quant](./fp_quant) | 🟢 | 🔴 | 🟢 | 🔴 | 🔴 | 🔴 | 🟢 | 4 | 🔴 | 🟢 | 🟢 | https://github.com/IST-DASLab/FP-Quant |
| [GGUF / GGML (llama.cpp)](./gguf) | 🟢 | 🟢 | 🟢 | 🔴 | 🟢 | 🟢 | 🟢 | 1/8 | 🔴 | 🔴 | [See Notes](./gguf) | https://github.com/ggerganov/llama.cpp |
| [GGUF / GGML (llama.cpp)](./gguf) | 🔴 | 🟢 | 🟢 | 🔴 | 🟢 | 🟢 | 🟢 | 1/8 | 🔴 | 🔴 | [See Notes](./gguf) | https://github.com/ggerganov/llama.cpp |
| [GPT-QModel](./gptq) | 🔴 | 🟢 | 🟢 | 🟢 | 🟢 | 🟢 | 🔴 | 2/3/4/8 | 🟢 | 🟢 | 🟢 | https://github.com/ModelCloud/GPTQModel |
| [HIGGS](./higgs) | 🟢 | 🔴 | 🟢 | 🔴 | 🔴 | 🔴 | 🟢 | 2/4 | 🔴 | 🟢 | 🟢 | https://github.com/HanGuo97/flute |
| [HQQ](./hqq) | 🟢 | 🟢 | 🟢 | 🔴 | 🔴 | 🟢 | 🟢 | 1/8 | 🟢 | 🔴 | 🟢 | https://github.com/mobiusml/hqq/ |
Expand Down
Loading