[PR #188] EXL3 on one GPU: the CPU lane's experts in split-K pieces, prompts' lightest experts on the CPU #383

Closed
opened 2026-10-29 21:24:54 +07:00 by bsakaguchi · 0 comments
Owner

Original Pull Request: https://github.com/mw00/project-maya/pull/188

State: closed
Merged: Yes


Summary

On one GPU, most of an EXL3 model's routed experts run on the CPU. With EXL3-4.05bpw on an RTX 3090, that's ~210 of the ~350 experts per token and ~34 of ~54 ms per token. This PR makes that CPU work faster for decode, and gives EXL3 prompts a CPU share of their experts.

  • Decode: experts in split-K pieces (exl3_cpu_rows_acc[_n]). The CPU lane's EXL3 kernel was limited by its DRAM read pattern, not by compute. A job of 128 output columns reads 1 KB runs a whole tile row (16-32 KB) apart, which reaches ~60 GB/s on this box. A contiguous read reaches ~90. Each job now takes a piece of the inputs over every column, so it streams its tile rows in memory order: gate/up pieces of 256 inputs, down pieces of 128 (one gate/up band). The pieces are fixed, so neither the thread count nor the window lanes change the sums. A verify window's tokens stay the token path's bit for bit.
  • Decode: one batch of jobs per route (x3_jobs). An expert's down pieces wait only for its own gate/up pieces, and its output bands only for its own down pieces. There are no barriers between phases. With ~6 RAM-tier experts on 40 threads, the down phase alone used to take three rounds for 2.3 rounds' work.
  • Prompts: EXL3 experts on the CPU too. The prompt path's CPU share (the least-routed RAM-tier experts computed on the CPU while the x8 link uploads the rest) was GGUF only. EXL3 now takes it as well:
    • It runs on a helper thread from the plan. The host thread's enqueue loop blocks once the launch queue is full, and the CPU experts queued behind it started near the end of the copies they were meant to overlap (a layer: CPU done at plan + ~400 ms after ~110 ms of work).
    • Experts with more than 8 rows go through exl3_cpu_band_gemm. Each 256-input chunk of a band is decoded once to F32, then a 6-token x 64-column FMA tile runs over it, in groups of 4 bands so the rows' input chunk stays in L2. The sums come out in the band kernel's order, bit for bit.
    • Jobs are per expert and band group, largest expert first. One job per row and band had been ~175K claims of a single counter per layer.
  • Vectorised helpers. The 128-point transform, the FP16 scales and the block sums in exl3_cpu_prepare_block / exl3_cpu_band_out now run in AVX-512. The transform gives the same bits.

exllamav3 solves the same read pattern differently: it re-lays its CPU-side experts out band by band and undoes that when an expert goes to the GPU. Split-K gets the same reads while leaving the RAM/VRAM tiers and every GPU kernel as they are.

Numbers

RTX 3090 alone (PCIe 3.0 x8), Xeon Gold 6152 x2, 183 GB RAM. Settings as the setup writes them: --max-context 32768 --prefill auto --kv-streaming on, the shipped expert profile. Greedy decoding: a warm second pass of three questions (256 tokens each), then two different 8K documents (128 tokens each). Values are tok/s, v1.1.9 -> this branch.

EXL3-4.05bpw

hash table story TCP/UDP 8K doc decode 8K doc prompt
plain 14.4 -> 18.9 14.7 -> 19.4 15.1 -> 19.6 14.8 / 14.0 -> 18.4 / 18.2 299 / 307 -> 358 / 374
DFlash2 19.5 -> 23.5 15.8 -> 20.0 18.3 -> 22.6 14.5 / 14.8 -> 17.8 / 18.6 299 / 305 -> 329 / 399

Prompts vary between runs: 380-407 tok/s in documents-only runs.

EXL3-3.05bpw

hash table story TCP/UDP 8K doc decode 8K doc prompt
plain 14.3 -> 20.9 15.8 -> 22.0 16.8 -> 22.1 15.9 / 16.5 -> 21.5 / 21.3 384 / 396 -> 422 / 489
DFlash2 22.4 -> 29.2 20.8 -> 23.6 19.1 -> 26.1 15.9 / 17.5 -> 20.8 / 21.3 385 / 395 -> 416 / 489

DFlash2 runs vary by up to about 15% per question, with draft acceptance.

CPU lane, one RAM-tier expert in decode (4.05bpw): 0.233 -> 0.165 ms. A standalone bench of the engine's call shape (5 experts, 44 threads) gives 0.214 ms for band jobs and 0.138 ms for split-K.

Where an 8K prompt's CPU share went (4.05bpw, the two documents):

experts on the CPU rows on the CPU staged over the link after the plan learned balance
CPU work in line 2464 / 2392 158K / 145K 1858 / 1938 3.85
this branch 3569 / 3984 461K / 572K 750 / 343 0.77

The learned balance (kappa) dropped to ~0.8, so the CPU and the link now finish together.

Decode on this box is close to what this design allows. The GPU's own work is ~20 ms per token, and the CPU's share of experts needs ~29 ms at the box's full DRAM bandwidth. The two don't overlap within a layer.

Tried and dropped, no measurable gain:

  • huge pages for the RAM tier
  • pinning the lane's threads
  • 44 lane threads instead of 40 (slower)
  • one window pool instead of two
  • cheaper state extraction, and floats made by OR-ing the byte sum into a mantissa (both 0-5%)
  • the GEMM for the window lanes (slower at 4 tokens)

Tests

  • exl3_test passes on the RTX 3090. New checks:
    • split-K pieces against the band kernel, and N activations against one call each: 0 bits differ, K 2/3/4/5/8
    • the GEMM against the band kernel: 0 differ, band groups of 1 and 2
    • the vectorised transform against the scalar loop: 0 of 8192 differ
  • glm_pack_test window exactness on the 3090 with EXL3-4.05bpw, the DFlash2 drafter loaded and the CPU plan pinned all-CPU: windows of 4, 416 of 416 picks match token-at-a-time decoding; windows of 8, 469 of 469.
  • The CPU lane check (STRATA_GLM_CPU_LANE_CHECK=1): relative L2 error 0.00052 against the reference, as before.
  • serve/ unit tests pass. tools/ unit tests pass except the 7 test_hip_archs cases, which need cmake on PATH and fail the same way on main.

Not tested

  • Splits of 2 or more GPUs (the 9-GPU and 3090 + 5060 Ti configs). The CPU lane code they share changed, but I only benchmarked one GPU.
  • GGUF packs. Their prompt CPU code moved into the else branch unchanged, but it was not re-run.
  • A CPU without AVX-512 (the scalar fallbacks), HIP, Windows.
**Original Pull Request:** https://github.com/mw00/project-maya/pull/188 **State:** closed **Merged:** Yes --- ## Summary On one GPU, most of an EXL3 model's routed experts run on the CPU. With EXL3-4.05bpw on an RTX 3090, that's ~210 of the ~350 experts per token and ~34 of ~54 ms per token. This PR makes that CPU work faster for decode, and gives EXL3 prompts a CPU share of their experts. - **Decode: experts in split-K pieces** (`exl3_cpu_rows_acc[_n]`). The CPU lane's EXL3 kernel was limited by its DRAM read pattern, not by compute. A job of 128 output columns reads 1 KB runs a whole tile row (16-32 KB) apart, which reaches ~60 GB/s on this box. A contiguous read reaches ~90. Each job now takes a piece of the inputs over every column, so it streams its tile rows in memory order: gate/up pieces of 256 inputs, down pieces of 128 (one gate/up band). The pieces are fixed, so neither the thread count nor the window lanes change the sums. A verify window's tokens stay the token path's bit for bit. - **Decode: one batch of jobs per route** (`x3_jobs`). An expert's down pieces wait only for its own gate/up pieces, and its output bands only for its own down pieces. There are no barriers between phases. With ~6 RAM-tier experts on 40 threads, the down phase alone used to take three rounds for 2.3 rounds' work. - **Prompts: EXL3 experts on the CPU too.** The prompt path's CPU share (the least-routed RAM-tier experts computed on the CPU while the x8 link uploads the rest) was GGUF only. EXL3 now takes it as well: - It runs on a helper thread from the plan. The host thread's enqueue loop blocks once the launch queue is full, and the CPU experts queued behind it started near the end of the copies they were meant to overlap (a layer: CPU done at plan + ~400 ms after ~110 ms of work). - Experts with more than 8 rows go through `exl3_cpu_band_gemm`. Each 256-input chunk of a band is decoded once to F32, then a 6-token x 64-column FMA tile runs over it, in groups of 4 bands so the rows' input chunk stays in L2. The sums come out in the band kernel's order, bit for bit. - Jobs are per expert and band group, largest expert first. One job per row and band had been ~175K claims of a single counter per layer. - **Vectorised helpers.** The 128-point transform, the FP16 scales and the block sums in `exl3_cpu_prepare_block` / `exl3_cpu_band_out` now run in AVX-512. The transform gives the same bits. exllamav3 solves the same read pattern differently: it re-lays its CPU-side experts out band by band and undoes that when an expert goes to the GPU. Split-K gets the same reads while leaving the RAM/VRAM tiers and every GPU kernel as they are. ## Numbers RTX 3090 alone (PCIe 3.0 x8), Xeon Gold 6152 x2, 183 GB RAM. Settings as the setup writes them: `--max-context 32768 --prefill auto --kv-streaming on`, the shipped expert profile. Greedy decoding: a warm second pass of three questions (256 tokens each), then two different 8K documents (128 tokens each). Values are tok/s, v1.1.9 -> this branch. **EXL3-4.05bpw** | | hash table | story | TCP/UDP | 8K doc decode | 8K doc prompt | |---|---:|---:|---:|---:|---:| | plain | 14.4 -> 18.9 | 14.7 -> 19.4 | 15.1 -> 19.6 | 14.8 / 14.0 -> 18.4 / 18.2 | 299 / 307 -> 358 / 374 | | DFlash2 | 19.5 -> 23.5 | 15.8 -> 20.0 | 18.3 -> 22.6 | 14.5 / 14.8 -> 17.8 / 18.6 | 299 / 305 -> 329 / 399 | Prompts vary between runs: 380-407 tok/s in documents-only runs. **EXL3-3.05bpw** | | hash table | story | TCP/UDP | 8K doc decode | 8K doc prompt | |---|---:|---:|---:|---:|---:| | plain | 14.3 -> 20.9 | 15.8 -> 22.0 | 16.8 -> 22.1 | 15.9 / 16.5 -> 21.5 / 21.3 | 384 / 396 -> 422 / 489 | | DFlash2 | 22.4 -> 29.2 | 20.8 -> 23.6 | 19.1 -> 26.1 | 15.9 / 17.5 -> 20.8 / 21.3 | 385 / 395 -> 416 / 489 | DFlash2 runs vary by up to about 15% per question, with draft acceptance. **CPU lane, one RAM-tier expert in decode (4.05bpw):** 0.233 -> 0.165 ms. A standalone bench of the engine's call shape (5 experts, 44 threads) gives 0.214 ms for band jobs and 0.138 ms for split-K. **Where an 8K prompt's CPU share went (4.05bpw, the two documents):** | | experts on the CPU | rows on the CPU | staged over the link after the plan | learned balance | |---|---:|---:|---:|---:| | CPU work in line | 2464 / 2392 | 158K / 145K | 1858 / 1938 | 3.85 | | this branch | 3569 / 3984 | 461K / 572K | 750 / 343 | 0.77 | The learned balance (kappa) dropped to ~0.8, so the CPU and the link now finish together. Decode on this box is close to what this design allows. The GPU's own work is ~20 ms per token, and the CPU's share of experts needs ~29 ms at the box's full DRAM bandwidth. The two don't overlap within a layer. Tried and dropped, no measurable gain: - huge pages for the RAM tier - pinning the lane's threads - 44 lane threads instead of 40 (slower) - one window pool instead of two - cheaper state extraction, and floats made by OR-ing the byte sum into a mantissa (both 0-5%) - the GEMM for the window lanes (slower at 4 tokens) ## Tests - `exl3_test` passes on the RTX 3090. New checks: - split-K pieces against the band kernel, and N activations against one call each: 0 bits differ, K 2/3/4/5/8 - the GEMM against the band kernel: 0 differ, band groups of 1 and 2 - the vectorised transform against the scalar loop: 0 of 8192 differ - `glm_pack_test` window exactness on the 3090 with EXL3-4.05bpw, the DFlash2 drafter loaded and the CPU plan pinned all-CPU: windows of 4, 416 of 416 picks match token-at-a-time decoding; windows of 8, 469 of 469. - The CPU lane check (`STRATA_GLM_CPU_LANE_CHECK=1`): relative L2 error 0.00052 against the reference, as before. - `serve/` unit tests pass. `tools/` unit tests pass except the 7 `test_hip_archs` cases, which need `cmake` on PATH and fail the same way on main. ## Not tested - Splits of 2 or more GPUs (the 9-GPU and 3090 + 5060 Ti configs). The CPU lane code they share changed, but I only benchmarked one GPU. - GGUF packs. Their prompt CPU code moved into the else branch unchanged, but it was not re-run. - A CPU without AVX-512 (the scalar fallbacks), HIP, Windows.
bsakaguchi 2026-10-29 21:24:54 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#383
No description provided.