Skip to content
Open
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
106 changes: 106 additions & 0 deletions docs/models/inkling.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,112 @@ benchmark:
Written after the greedy answers without them to five prompts of 19 to 5,761 tokens, 256 tokens each, setup's
settings give the same most likely token at 96.7% of the steps; a second run without them gives 98.3%.

### Setup's four settings, one at a time

These settings make the answers worse to make them faster. Setup adds all four by itself, without asking, whenever
the card cannot hold every expert of the size; as of this revision setup has no option that leaves them out.
`--attn-requant q5_0` stores the attention's matrices in fewer bits and `--loop-bf16` the loop controllers: lossy
rounding. `--tail-skip 4` does not compute some of a token's experts at all: on the 8 GB cards below, with the other
three settings, 9% to 27% of a token's expert picks. The answers differ measurably from the model's without them
(the same most likely token at 94.3-95.0% of the steps with all four, against 98.2-99.0% for a second run without
them), and with `--tail-skip` the engine's "experts from VRAM" figure counts the skipped experts as found in VRAM, so
it reads high.

To turn them off, delete `"--attn-requant", "q5_0", "--loop-bf16", "--tail-skip", "4", "--expert-swaps", "0"` from
the `"args"` list of the model's run config, `strata-inkling-<size>.json` in the install's `terminal` folder (for
example `strata-inkling-ud-q3_k_xl.json`), and restart the server. To keep the rounding but compute every expert,
change the `4` after `--tail-skip` to `0`, or add `"env": {"STRATA_ROUTE_TAIL_SKIP": "0"}` to the config. Running
setup again for the size writes the four back into `"args"`; an `"env"` entry you added stays.

Three of them round the numbers more coarsely (lossy). `--tail-skip 4` is different: it leaves experts out. For each
token, an expert that is not on the card and that the router ranks fifth or lower of the token's eight is not
computed at all. While a prompt is read, a group of tokens at a time, an expert is left out only if every token of
the group ranks it fifth or lower.

| Setting | What it does | Kind |
| --- | --- | --- |
| `--attn-requant q5_0` | the attention's matrices in 5 bits instead of 8: fewer bytes a token, and more VRAM for experts | rounding |
| `--loop-bf16` | the loop controllers in BF16 instead of F32 | rounding |
| `--expert-swaps 0` | no expert moves into VRAM while an answer is written (default 64 on their way at a time) | rounding: the same experts, but more of them on the CPU, which rounds a little differently |
| `--tail-skip 4` | a token's experts ranked 5th to 8th that are not on the card are left out | **skips computation** |

Measured on main d1f711e11, one setting at a time and all four, with ggml-org's IQ4_NL file and with UD-Q2_K_XL
(Unsloth's tensors byte for byte, in the `inkling2_loop` layout). 256 tokens written greedily at a 32K context with
an FP16 KV cache; each number is the median of two runs, in tokens/s:

| Card | Settings | Experts on the card | Writes after 302 tokens | Writes after 8,192 | Reads 2,048 |
| --- | --- | ---: | ---: | ---: | ---: |
| RTX 4060 Ti 16 GB, Threadripper 2950X | none | 2,619 of 3,072 | 49.0 | 44.6 | 997 |
| | `--expert-swaps 0` | 2,619 | 41.3 | 42.8 | 965 |
| | `--loop-bf16` | 2,632 | 49.9 | 45.5 | 1,040 |
| | `--attn-requant q5_0` | 2,666 | **54.8** | 49.4 | 1,040 |
| | `--tail-skip 4` | 2,619 | 50.9 | 46.2 | 1,011 |
| | all four | 2,678 | 53.9 | **52.5** | 1,019 |
| Quadro RTX 4000 8 GB, Ryzen 5 5600X | none | 998 of 3,072 | 30.9 | 21.7 | 341 |
| | `--expert-swaps 0` | 998 | 23.8 | 22.8 | 338 |
| | `--loop-bf16` | 1,008 | 29.6 | 20.2 | 346 |
| | `--attn-requant q5_0` | 1,045 | 30.9 | 19.6 | 355 |
| | `--tail-skip 4` | 998 | 31.0 | 19.9 | 352 |
| | all four | 1,055 | 30.9 | 18.3 | 358 |
| RTX 2070 Super 8 GB, Ryzen 5 3600XT, UD-Q2_K_XL | none | 1,986 of 3,072 | 39.3 | 32.7 | 515 |
| | `--expert-swaps 0` | 1,986 | 32.3 | 32.9 | 512 |
| | `--loop-bf16` | 2,008 | 40.0 | 33.4 | 515 |
| | `--attn-requant q5_0` | 2,039 | 43.6 | 34.8 | 517 |
| | `--tail-skip 4` | 1,986 | **43.7** | 37.4 | 516 |
| | all four | 2,061 | 43.0 | **40.5** | 515 |

On the 16 GB card `--attn-requant q5_0` brings most of the gain. With UD-Q2_K_XL on the RTX 2070 Super,
`--tail-skip 4` and `--attn-requant q5_0` bring about the same after 302 tokens (+4.4 and +4.3 tokens/s); after
8,192, `--tail-skip 4` brings +4.7 and `--attn-requant q5_0` +2.1. `--expert-swaps 0` costs speed on every card after
a short prompt: the experts the answer needs stay on the CPU (it computes 8.0 instead of 1.6 ms of experts a token on
the 16 GB card, 23 instead of 6.6 on the Quadro). After a long prompt it costs less: the cache also moves while a
prompt is read, with it or without it. On the Quadro no setting is faster than none beyond the run-to-run spread,
which is wide there (none: 29.5-32.2 tokens/s after 302 tokens, 19.1-24.3 after 8,192).

How much each one changes the answers, written after the greedy answer without any of them to four prompts (302,
112, 2,048 tokens and a short chat; 896 steps). "Again" is a second and a third run without them, the spread of
two runs of the same settings:

| Card, file | Settings | Same most likely token | Mean KL of the top 20 |
| --- | --- | ---: | ---: |
| RTX 4060 Ti 16 GB, Threadripper 2950X, IQ4_NL (2,619 experts on the card) | again | 98.2%, 99.0% | 0.002, 0.002 |
| | `--expert-swaps 0` | 98.1% | 0.011 |
| | `--loop-bf16` | 98.1% | 0.004 |
| | `--attn-requant q5_0` | 95.6% | 0.032 |
| | `--tail-skip 4` | 97.9% | 0.025 |
| | all four | 95.0% | 0.022 |
| RTX 2080 Ti 11 GB, Ryzen 9 3900X, IQ4_NL (1,582 experts on the card) | again | 98.4%, 98.9% | 0.001, 0.002 |
| | `--expert-swaps 0` | 98.9% | 0.002 |
| | `--loop-bf16` | 98.4% | 0.002 |
| | `--attn-requant q5_0` | 97.0% | 0.014 |
| | `--tail-skip 4` | 96.4% | 0.010 |
| | all four | 94.3% | 0.034 |
| Both cards, UD-Q2_K_XL (the whole file on the card) | `--attn-requant q5_0` | 94.6%, 97.0% | 0.014, 0.023 |

`--loop-bf16` and `--expert-swaps 0` give 98.1-98.9%, about as close as two default runs (98.2-99.0%).
`--attn-requant q5_0` moves the answers most of the three rounding settings. With the whole file on the card,
`--tail-skip 4`, `--expert-swaps 0` and `--loop-bf16` change nothing (100%, KL 0). On the 16 GB card one step of most
settings has a KL of 6 to 8, which sets the means there; so does the default with the doorbell off
(`STRATA_POLY_BELL=0`; the doorbell is how the card hands its misses to the CPU one token at a time). The medians
are 0.0002 and 0.0001 (again), 0.0004 (`--expert-swaps 0`), 0.0003 (`--loop-bf16`), 0.0017 (`--attn-requant
q5_0`), 0.0007 (`--tail-skip 4`) and 0.0025 (all four).

`--tail-skip 4` leaves out more the fewer experts the card holds. With it, the engine's "experts from VRAM" count
also takes the left-out experts as found in VRAM, so it reads high. The engine counts the left-out experts only with
the doorbell off. There the VRAM figure reads high too, since the left-out experts drop out of the count it divides
by. Counted that way, of a token's 384 expert picks (8 in each of 48 layer runs):

| Card (IQ4_NL unless named) | `--tail-skip 4` alone | All four (no swaps, so more misses) |
| --- | ---: | ---: |
| RTX 4060 Ti 16 GB | 3.3 left out (0.9%) | 10.4 (2.7%) |
| Quadro RTX 4000 8 GB | 30.8 (8.0%) | 94.1 (24.5%) |
| RTX 2070 Super 8 GB, UD-Q2_K_XL | 9.4 (2.4%) | 35.8 (9.3%) |
| RTX 2070 Super 8 GB, IQ4_NL (4 cores) | not run | 101.7 (26.5%) |

The answers above were measured on the 16 GB card, where it leaves out 0.9%, and on the 11 GB one, where it was not
counted. On an 8 GB card, where it leaves out about a quarter (24.5-26.5%) of the picks with the other three
settings, they were not measured.

A prompt is read a group of calls at a time through each layer run, so the experts that are not on the card cross
the bus once for the group instead of once for every call and every pass of the looped layers.

Expand Down
Loading