# Per-layer n-gram tables (engram): mix and match

Qwen4-35B-A3B has a large per-layer n-gram embedding table (`per_layer_token_embd.weight`, 128 x 160,003,584 = 20.5B values). Every quant in this repo is two files, and the second one (`-00002-of-00002.gguf`) holds only this table. The files in this folder hold the same table at other precisions, so you can swap the table for a more precise or a smaller one without downloading the quant's own table.

| file | table type | size | relative RMSE vs BF16 | notes |
|---|---|---|---|---|
| `Qwen4-35B-A3B-engram-BF16.gguf_file` | BF16 | 40.96 GB | 0 | lossless, exactly as in the checkpoint |
| `Qwen4-35B-A3B-engram-Q8_0.gguf_file` | Q8_0 | 21.76 GB | 0.0053 | same table as in UD-Q6_K, UD-Q6_K_XL, UD-Q8_K_XL |
| `Qwen4-35B-A3B-engram-Q5_1.gguf_file` | Q5_1 | 15.36 GB | 0.0377 | same table as in UD-Q5_K_S, UD-Q5_K_M, UD-Q5_K_XL |
| `Qwen4-35B-A3B-engram-IQ4_NL.gguf_file` | IQ4_NL | 11.52 GB | 0.0758 | same table as in UD-IQ1_S up to UD-Q4_K_XL |

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 128 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.

The Q8_0, Q5_1 and IQ4_NL files are the second file of the quants listed in the notes column, byte for byte except for three split-numbering header integers, so for example UD-Q4_K_XL with `Qwen4-35B-A3B-engram-IQ4_NL.gguf_file` gives exactly the same output as UD-Q4_K_XL alone.

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 file when swapping by hand (last section below).

## Which file is the table

Every quant keeps its table in its second file, `<quant>/Qwen4-35B-A3B-<quant>-00002-of-00002.gguf` (slot 2 of 2).

| quant | table file | slot / count | bundled table |
|---|---|---|---|
| UD-IQ1_S, UD-IQ1_M, UD-IQ2_XXS, UD-IQ2_XS, UD-IQ2_S, UD-IQ2_M, UD-Q2_K_XL, UD-IQ3_XXS, UD-IQ3_S, UD-Q3_K_XL, UD-IQ4_XS, UD-IQ4_NL, UD-Q4_K_S, UD-Q4_K_M, UD-Q4_K_XL | `-00002-of-00002` | 2 2 | IQ4_NL |
| UD-Q5_K_S, UD-Q5_K_M, UD-Q5_K_XL | `-00002-of-00002` | 2 2 | Q5_1 |
| UD-Q6_K, UD-Q6_K_XL, UD-Q8_K_XL | `-00002-of-00002` | 2 2 | Q8_0 |

## Use a table with llama.cpp `--ple`

llama.cpp `master` (any build with Qwen4 support, [ggml-org/llama.cpp#33626](https://github.com/ggml-org/llama.cpp/pull/33626), which also has `--ple` from [ggml-org/llama.cpp#31185](https://github.com/ggml-org/llama.cpp/pull/31185)) loads a table with `--ple`. Download the quant without its table file, download the table you want, and add `--ple` to your usual command. Example: UD-Q4_K_XL with the Q8_0 table (skips the 11.5 GB IQ4_NL table file):

```bash
hf download unsloth/Qwen4-35B-A3B-GGUF --include "UD-Q4_K_XL/*" "engram/*Q8_0*" \
    --exclude "UD-Q4_K_XL/*-00002-of-00002.gguf" --local-dir Qwen4-35B-A3B-GGUF
./llama.cpp/build/bin/llama-server -m Qwen4-35B-A3B-GGUF/UD-Q4_K_XL/Qwen4-35B-A3B-UD-Q4_K_XL-00001-of-00002.gguf \
    --ple Qwen4-35B-A3B-GGUF/engram/Qwen4-35B-A3B-engram-Q8_0.gguf_file \
    -ngl 999 -fa on --jinja -c 32768 -ot per_layer_token_embd=CPU \
    --temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.0
```

llama.cpp then uses the `--ple` table, and the quant's own table file may be missing (with `-v`, the log shows `GGUF split ... not found, assuming it only holds the per-layer embedding table`; if the file is present, it is skipped). Without `--ple`, the quant needs its own table file and fails to start if it is gone. `-ot per_layer_token_embd=CPU` keeps the table in system RAM, so a larger table needs more RAM, not more VRAM.

## Swap a table by hand (builds without `--ple`)

llama.cpp checks that each file's `split.no` / `split.count` match its place in the set, so a table from this folder has to be stamped as file 2 of 2 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. Example: UD-Q6_K_XL with the lossless BF16 table:

```bash
# 1. the quant without its table file, the BF16 table and the script
hf download unsloth/Qwen4-35B-A3B-GGUF --include "UD-Q6_K_XL/*" "engram/*BF16*" "engram/set_split.py" \
    --exclude "UD-Q6_K_XL/*-00002-of-00002.gguf" --local-dir Qwen4-35B-A3B-GGUF
cd Qwen4-35B-A3B-GGUF

# 2. stamp it as file 2 of 2
python engram/set_split.py engram/Qwen4-35B-A3B-engram-BF16.gguf_file 2 2

# 3. put it in the table file's place
mv engram/Qwen4-35B-A3B-engram-BF16.gguf_file UD-Q6_K_XL/Qwen4-35B-A3B-UD-Q6_K_XL-00002-of-00002.gguf

# 4. run as usual
../llama.cpp/build/bin/llama-server -m UD-Q6_K_XL/Qwen4-35B-A3B-UD-Q6_K_XL-00001-of-00002.gguf
```

If you already downloaded the quant's own table file, move it aside first (for example to `UD-Q6_K_XL/engram-Q8_0.bak`).
