add the README, which build-and-upload does not copy
Browse files
README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- kernel
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## ggml-quantization
|
| 8 |
+
|
| 9 |
+
GGUF quantization kernels from [llama.cpp](https://github.com/ggml-org/llama.cpp), computing directly on
|
| 10 |
+
the packed blocks of a quantized checkpoint rather than on a dense copy of its weights.
|
| 11 |
+
|
| 12 |
+
- `mul_mat_vec` — fused dequantize + gemv, for up to `MAX_GEMV_ROWS` rows
|
| 13 |
+
- `dequantize` — blocks to values
|
| 14 |
+
- `get_rows` — gathers rows, unpacking as it goes
|
| 15 |
+
- `mul_mat_id` — one dispatch for a bank of routed experts, given the router's choices
|
| 16 |
+
|
| 17 |
+
`GEMV_TYPES` lists the quantization types this build has a gemv for.
|
| 18 |
+
|
| 19 |
+
## Usage
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
import torch
|
| 23 |
+
from kernels import get_kernel
|
| 24 |
+
|
| 25 |
+
k = get_kernel("marcsun13/ggml-quantization", version=1)
|
| 26 |
+
|
| 27 |
+
Q4_K = 12 # ggml type id; `k.GEMV_TYPES` lists what this build covers
|
| 28 |
+
out_features = in_features = 4096
|
| 29 |
+
# a GGUF weight as stored: one row per output feature, 144 bytes per 256-element Q4_K block
|
| 30 |
+
blocks = torch.randint(0, 256, (out_features, in_features // 256 * 144), dtype=torch.uint8, device="mps")
|
| 31 |
+
x = torch.randn(1, in_features, device="mps")
|
| 32 |
+
|
| 33 |
+
y = k.mul_mat_vec(blocks, x, Q4_K, out_features) # (1, 4096) f32
|
| 34 |
+
w = k.dequantize(blocks, Q4_K, out_features, in_features, torch.bfloat16) # (4096, 4096)
|
| 35 |
+
rows = k.get_rows(blocks, torch.tensor([3, 7], device="mps"), Q4_K, in_features, torch.bfloat16)
|
| 36 |
+
```
|