# GGUF

Hugging Face Hub mendukung semua format file, tetapi memiliki fitur bawaan untuk [format GGUF](https://github.com/ggerganov/ggml/blob/master/docs/gguf.md), yaitu format biner yang dioptimalkan untuk pemuatan dan penyimpanan model yang cepat, sehingga sangat efisien untuk keperluan inferensi. GGUF dirancang untuk digunakan dengan GGML dan eksekutor lainnya. GGUF dikembangkan oleh [@ggerganov](https://huggingface.co/ggerganov) yang juga merupakan pengembang [llama.cpp](https://github.com/ggerganov/llama.cpp), sebuah framework inferensi LLM C/C++ yang populer. Model yang awalnya dikembangkan dalam framework seperti PyTorch dapat dikonversi ke format GGUF untuk digunakan dengan mesin-mesin tersebut.

Seperti yang dapat kita lihat pada grafik ini, berbeda dengan format file yang hanya berisi tensor seperti [safetensors](https://huggingface.co/docs/safetensors) – yang juga merupakan format model yang direkomendasikan untuk Hub – GGUF mengkodekan baik tensor maupun seperangkat metadata yang distandarkan.

## Mencari file GGUF

Anda dapat menelusuri semua model dengan file GGUF dengan memfilter berdasarkan tag GGUF: [hf.co/models?library=gguf](https://huggingface.co/models?library=gguf). Selain itu, Anda dapat menggunakan alat [ggml-org/gguf-my-repo](https://huggingface.co/spaces/ggml-org/gguf-my-repo) untuk mengonversi/mengkantisasi bobot model Anda menjadi bobot GGUF.

Sebagai contoh, Anda dapat melihat [TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF](https://huggingface.co/TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF) untuk melihat file GGUF dalam praktik.

## Penampil untuk metadata & info tensor

Hub memiliki viewer untuk file GGUF yang memungkinkan pengguna memeriksa metadata & info tensor (nama, shape, presisi). Viewer ini tersedia di halaman model ([contoh](https://huggingface.co/TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF?show_tensors=mixtral-8x7b-instruct-v0.1.Q4_0.gguf)) & halaman file ([contoh](https://huggingface.co/TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF/tree/main?show_tensors=mixtral-8x7b-instruct-v0.1.Q5_K_M.gguf)).

## Penggunaan dengan alat sumber terbuka

* [llama.cpp](./gguf-llamacpp)
* [LM Studio](./lmstudio)
* [GPT4All](./gguf-gpt4all)
* [Ollama](./ollama)

## Menganalisis metadata dengan @huggingface/gguf

Kami juga telah membuat parser GGUF javascript yang berfungsi pada file yang di-hosting secara jarak jauh (misalnya Hugging Face Hub).

```bash
npm install @huggingface/gguf
```

```ts
import { gguf } from "@huggingface/gguf";
// remote GGUF file from https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF
const URL_LLAMA = "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/191239b/llama-2-7b-chat.Q2_K.gguf";
const { metadata, tensorInfos } = await gguf(URL_LLAMA);
```

Temukan informasi lebih lanjut [di sini](https://github.com/huggingface/huggingface.js/tree/main/packages/gguf).

## Jenis Kuantisasi

| type         | source | deskripsi |
|---------------------------|--------|-------------|
| F64 | [Wikipedia](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) | Angka floating-point presisi ganda standar IEEE 754 64-bit. |
| I64 | [GH](https://github.com/ggerganov/llama.cpp/pull/6062) | Angka integer lebar tetap 64-bit. |
| F32  | [Wikipedia](https://en.wikipedia.org/wiki/Single-precision_floating-point_format) | Angka floating-point presisi tunggal standar IEEE 754 32-bit. |
| I32 | [GH](https://github.com/ggerganov/llama.cpp/pull/6045) | Angka integer lebar tetap 32-bit. |
| F16  | [Wikipedia](https://en.wikipedia.org/wiki/Half-precision_floating-point_format) | Angka floating-point presisi setengah standar IEEE 754 16-bit. |
| BF16 | [Wikipedia](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format) | Versi 16-bit yang dipersingkat dari bilangan floating-point presisi tunggal IEEE 754 32-bit. |
| I16 | [GH](https://github.com/ggerganov/llama.cpp/pull/6045) | Bilangan bulat lebar tetap 16-bit. |
| Q8_K | [GH](https://github.com/ggerganov/llama.cpp/pull/1684#issue-1739619305) | Kuantisasi 8-bit (`q`). Setiap blok memiliki 256 bobot. Hanya digunakan untuk mengkuantisasi hasil antara. Semua perkalian titik 2-6 bit diimplementasikan untuk tipe kuantisasi ini. Rumus bobot: `w = q * block_scale`. |
| I8 | [GH](https://github.com/ggerganov/llama.cpp/pull/6045) | Bilangan bulat lebar tetap 8-bit. |
| Q6_K | [GH](https://github.com/ggerganov/llama.cpp/pull/1684#issue-1739619305) | Kuantisasi 6-bit (`q`). Super-blok dengan 16 blok, di mana setiap blok memiliki 16 bobot. Rumus bobot: `w = q * block_scale(8-bit)`, menghasilkan 6,5625 bit-per-bobot. |
| Q5_K | [GH](https://github.com/ggerganov/llama.cpp/pull/1684#issue-1739619305) | Kuantisasi 5-bit (`q`). Super-blok dengan 8 blok, di mana setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale(6-bit) + block_min(6-bit)`, menghasilkan 5,5 bit-per-bobot. |
| Q4_K | [GH](https://github.com/ggerganov/llama.cpp/pull/1684#issue-1739619305) | Kuantisasi 4-bit (`q`). Super-blok dengan 8 blok, di mana setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale(6-bit) + block_min(6-bit)`, menghasilkan 4,5 bit-per-bobot. |
| Q3_K | [GH](https://github.com/ggerganov/llama.cpp/pull/1684#issue-1739619305) | Kuantisasi 3-bit (`q`). Super-blok dengan 16 blok, di mana setiap blok memiliki 16 bobot. Rumus bobot: `w = q * block_scale(6-bit)`, menghasilkan 3,4375 bit-per-bobot. |
| Q2_K | [GH](https://github.com/ggerganov/llama.cpp/pull/1684#issue-1739619305) | Kuantisasi 2-bit (`q`). Super-blok dengan 16 blok, di mana setiap blok memiliki 16 bobot. Rumus bobot: `w = q * block_scale(4-bit) + block_min(4-bit)`, menghasilkan 2,625 bit-per-bobot. |
| IQ4_NL | [GH](https://github.com/ggerganov/llama.cpp/pull/5590) | Kuantisasi 4-bit (`q`). Super-blok dengan 256 bobot. Bobot `w` diperoleh menggunakan `super_block_scale` & `importance matrix`. |
| IQ4_XS | [HF](https://huggingface.co/CISCai/OpenCodeInterpreter-DS-6.7B-SOTA-GGUF/blob/main/README.md?code=true#L59-L70) | Kuantisasi 4-bit (`q`). Super-blok dengan 256 bobot. Bobot `w` diperoleh menggunakan `super_block_scale` & `importance matrix`, menghasilkan 4,25 bit-per-bobot. |
| IQ3_S | [HF](https://huggingface.co/CISCai/OpenCodeInterpreter-DS-6.7B-SOTA-GGUF/blob/main/README.md?code=true#L59-L70) | 3-bit quantization (`q`). Super-blocks with 256 weights. Weight `w` is obtained using `super_block_scale` & `importance matrix`, resulting in 3.44 bits-per-weight. |
| IQ3_XXS | [HF](https://huggingface.co/CISCai/OpenCodeInterpreter-DS-6.7B-SOTA-GGUF/blob/main/README.md?code=true#L59-L70) | 3-bit quantization (`q`). Super-blocks with 256 weights. Weight `w` is obtained using `super_block_scale` & `importance matrix`, resulting in 3.06 bits-per-weight. |
| IQ2_XXS | [HF](https://huggingface.co/CISCai/OpenCodeInterpreter-DS-6.7B-SOTA-GGUF/blob/main/README.md?code=true#L59-L70) | 2-bit quantization (`q`). Super-blocks with 256 weights. Weight `w` is obtained using `super_block_scale` & `importance matrix`, resulting in 2.06 bits-per-weight. |
| IQ2_S | [HF](https://huggingface.co/CISCai/OpenCodeInterpreter-DS-6.7B-SOTA-GGUF/blob/main/README.md?code=true#L59-L70) | Kuantisasi 2-bit (`q`). Super-blok dengan 256 bobot. Bobot `w` diperoleh menggunakan `super_block_scale` & `importance matrix`, menghasilkan 2,5 bit per bobot. |
| IQ2_XS | [HF](https://huggingface.co/CISCai/OpenCodeInterpreter-DS-6.7B-SOTA-GGUF/blob/main/README.md?code=true#L59-L70) | Kuantisasi 2-bit (`q`). Super-blok dengan 256 bobot. Bobot `w` diperoleh menggunakan `super_block_scale` & `importance matrix`, menghasilkan 2,31 bit-per-bobot. |
| IQ1_S | [HF](https://huggingface.co/CISCai/OpenCodeInterpreter-DS-6.7B-SOTA-GGUF/blob/main/README.md?code=true#L59-L70) | Kuantisasi 1-bit (`q`). Super-blok dengan 256 bobot. Bobot `w` diperoleh menggunakan `super_block_scale` & `importance matrix`, menghasilkan 1,56 bit per bobot. |
| IQ1_M | [GH](https://github.com/ggerganov/llama.cpp/pull/6302) | Kuantisasi 1-bit (`q`). Super-blok dengan 256 bobot. Bobot `w` diperoleh menggunakan `super_block_scale` & `importance matrix`, menghasilkan 1,75 bit per bobot. |
| TQ1_0 | [GH](https://github.com/ggml-org/llama.cpp/pull/8151) | Kuantisasi ternary. |
| TQ2_0 | [GH](https://github.com/ggml-org/llama.cpp/pull/8151) | Kuantisasi ternary. |
| MXFP4 | [GH](https://github.com/ggml-org/llama.cpp/pull/15091) | 4-bit Microscaling Block Floating Point. |
| **Tipe lama** | | |
| Q8_0 | [GH](https://github.com/huggingface/huggingface.js/pull/615#discussion_r1557654249) | Kuantisasi pembulatan ke terdekat 8-bit (`q`). Setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale`. Metode kuantisasi lama (tidak banyak digunakan hingga saat ini). |
| Q8_1 | [GH](https://github.com/huggingface/huggingface.js/pull/615#discussion_r1557682290) | Kuantisasi pembulatan ke terdekat 8-bit (`q`). Setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale + block_minimum`. Metode kuantisasi lama (tidak banyak digunakan hingga saat ini). |
| Q5_0 | [GH](https://github.com/huggingface/huggingface.js/pull/615#discussion_r1557654249) | Kuantisasi pembulatan ke terdekat 5-bit (`q`). Setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale`. Metode kuantisasi lama (tidak banyak digunakan hingga saat ini). |
| Q5_1 | [GH](https://github.com/huggingface/huggingface.js/pull/615#discussion_r1557682290) | Kuantisasi pembulatan ke terdekat 5-bit (`q`). Setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale + block_minimum`. Metode kuantisasi lama (tidak banyak digunakan hingga saat ini). |
| Q4_0 | [GH](https://github.com/huggingface/huggingface.js/pull/615#discussion_r1557654249) | Kuantisasi 4-bit round-to-nearest (`q`). Setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale`. Metode kuantisasi lama (tidak banyak digunakan hingga saat ini). |
| Q4_1 | [GH](https://github.com/huggingface/huggingface.js/pull/615#discussion_r1557682290) | Kuantisasi 4-bit round-to-nearest (`q`). Setiap blok memiliki 32 bobot. Rumus bobot: `w = q * block_scale + block_minimum`. Metode kuantisasi lama (tidak banyak digunakan hingga saat ini). |

*jika ada ketidakakuratan pada tabel di atas, silakan buka PR pada [file ini](https://github.com/huggingface/huggingface.js/blob/main/packages/gguf/src/quant-descriptions.ts).*

