engram/README.md
5.0 KB · 83 lines · markdown Raw
1 # Per-layer n-gram tables (engram): mix and match
2
3 Qwen3.8-Flash-Next has a large per-layer n-gram embedding table (`per_layer_token_embd.weight`, 160 x 320,001,536 = 51.2B values). In a quant that keeps this table in its own shard, you can swap the table for a smaller or a lossless one without re-downloading the rest of the model.
4
5 | file | table type | size | relative RMSE vs BF16 | notes |
6 |---|---|---|---|---|
7 | `Qwen3.8-Flash-Next-engram-BF16.gguf_file` | BF16 | 102.4 GB | 0 | lossless, exactly as in the checkpoint |
8 | `Qwen3.8-Flash-Next-engram-Q8_0.gguf_file` | Q8_0 | 54.4 GB | 0.0053 | |
9 | `Qwen3.8-Flash-Next-engram-Q5_1.gguf_file` | Q5_1 | 38.4 GB | 0.0376 | |
10 | `Qwen3.8-Flash-Next-engram-IQ4_NL.gguf_file` | IQ4_NL | 28.8 GB | 0.0757 | |
11
12 Sizes are GB = 10^9 bytes. Relative RMSE is the root-mean-square error of a dequantized table row divided by the RMS of the same BF16 row, median over 3,000 random rows. The table rows are 160 values wide, and K-quants (Q5_K, Q6_K) need rows that are a multiple of 256, so this table cannot be stored as Q5_K or Q6_K. Q5_1 and Q8_0 are the types llama.cpp itself falls back to for Q5_K and Q6_K on such tensors.
13
14 The files end in `.gguf_file` so tools that scan the repo for models do not pick them up; you rename one to your quant's table shard name when swapping (step 3 below).
15
16 ## Which shard is the table
17
18 | quant | table shard | slot / count | bundled table |
19 |---|---|---|---|
20 | UD-IQ1_S, UD-IQ1_M, UD-Q2_0, UD-IQ2_XS | `-00003-of-00003` | 3 3 | IQ4_NL |
21 | UD-Q2_K_XL, UD-IQ3_XXS, UD-Q3_K_XL, UD-IQ4_XS, UD-Q4_K_XL | `-00004-of-00004` | 4 4 | IQ4_NL |
22 | UD-Q5_K_XL, UD-Q6_K_XL, Q8_0 | `-00003-of-00006` | 3 6 | Q8_0 |
23 | BF16 | `-00003-of-00008` | 3 8 | BF16 |
24
25 ## Simpler with llama.cpp b12233 or newer
26
27 llama.cpp b12233 or newer can load a table directly with `--ple` ([ggml-org/llama.cpp#31185](https://github.com/ggml-org/llama.cpp/pull/31185)), with no `set_split.py` or renaming. Download the table you want and add `--ple` to your usual command. Example: UD-Q4_K_XL with the Q8_0 table:
28
29 ```bash
30 hf download unsloth/Qwen3.8-Flash-Next-GGUF --include "engram/*Q8_0*" --local-dir .
31 llama-server -m UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf \
32 --ple engram/Qwen3.8-Flash-Next-engram-Q8_0.gguf_file
33 ```
34
35 llama.cpp then ignores the quant's own table, which is the shard listed in the table above (`-00004-of-00004` for UD-Q4_K_XL). Deleting that file, or not downloading it with `--exclude "UD-Q4_K_XL/*-00004-of-00004.gguf"`, saves 28.8 GB. Without `--ple`, the quant goes back to its own table, or fails to start if that file is gone. The two sections below are the manual method for builds without `--ple`.
36
37 ## Download a quant without its bundled table
38
39 You do not need to download the table a quant ships with if you want a different one. Exclude the quant's table shard and fetch the table you want from this folder instead. Example: UD-Q4_K_XL with the Q8_0 table (saves the 28.8 GB IQ4_NL shard):
40
41 ```bash
42 # 1. UD-Q4_K_XL without its table shard (-00004-of-00004)
43 hf download unsloth/Qwen3.8-Flash-Next-GGUF \
44 --include "UD-Q4_K_XL/*" --exclude "UD-Q4_K_XL/*-00004-of-00004.gguf" --local-dir .
45
46 # 2. the Q8_0 table + the script
47 hf download unsloth/Qwen3.8-Flash-Next-GGUF \
48 --include "engram/*Q8_0*" "engram/set_split.py" --local-dir .
49
50 # 3. stamp it as shard 4 of 4 and put it in the table shard's place
51 python engram/set_split.py engram/Qwen3.8-Flash-Next-engram-Q8_0.gguf_file 4 4
52 mv engram/Qwen3.8-Flash-Next-engram-Q8_0.gguf_file \
53 UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00004-of-00004.gguf
54
55 # 4. run as usual
56 llama-server -m UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf
57 ```
58
59 For another quant, use its table shard and slot / count from the table above.
60
61 ## How to swap a table you already downloaded (example: UD-Q6_K_XL with the lossless BF16 table)
62
63 llama.cpp checks that each shard's `split.no` / `split.count` match its place in the set, so the table file has to be stamped for your quant first. `set_split.py` (in this folder, plain Python, no dependencies) changes those two header values in place in milliseconds; nothing else in the file changes.
64
65 ```bash
66 # 1. get the table + the script
67 hf download unsloth/Qwen3.8-Flash-Next-GGUF \
68 --include "engram/*BF16*" "engram/set_split.py" --local-dir .
69
70 # 2. stamp it as shard 3 of 6 (UD-Q6_K_XL's table slot)
71 python engram/set_split.py engram/Qwen3.8-Flash-Next-engram-BF16.gguf_file 3 6
72
73 # 3. keep the old table aside, then rename the new one to the table shard's name
74 mv UD-Q6_K_XL/Qwen3.8-Flash-Next-UD-Q6_K_XL-00003-of-00006.gguf UD-Q6_K_XL/engram-Q8_0.bak
75 mv engram/Qwen3.8-Flash-Next-engram-BF16.gguf_file \
76 UD-Q6_K_XL/Qwen3.8-Flash-Next-UD-Q6_K_XL-00003-of-00006.gguf
77
78 # 4. run as usual
79 llama-server -m UD-Q6_K_XL/Qwen3.8-Flash-Next-UD-Q6_K_XL-00001-of-00006.gguf
80 ```
81
82 For another quant only the two numbers and the file name change (table above). The files here are stamped as shard 1 of 1, so using one without `set_split.py` fails to load with `invalid split file idx` instead of loading the wrong thing.
83