[PR #5246] [Engine] Support capacity-aware block-aligned GGUF tensor parallelism and fix K-quant head slicing #5364

Open
opened 2026-11-07 16:34:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5246
Author: @Moeblack
Created: 11/4/2026
Status: 🔄 Open

Base: main ← Head: feat/dsv41-gguf-tp


📝 Commits (1)

  • 4168fc3 [dsv41] Support capacity-aware block-aligned GGUF tensor parallelism and fix K-quant head slicing

📊 Changes

6 files changed (+593 additions, -139 deletions)

View changed files

📝 src/dsv41/ds4_gguf.cu (+10 -4)
📝 src/dsv41/ds4_kernels.cu (+5 -4)
📝 src/dsv41/ds4_main.cpp (+4 -1)
📝 src/dsv41/ds4_model.cu (+417 -129)
➕ src/dsv41/ds4_tp_plan.hpp (+156 -0)
📝 strata_control/dsv41_fit.py (+1 -1)

📄 Description

Problem and result

GGUF DeepSeek-V4.1 packs whose expert intermediate width (n_ff = 2304) is not evenly divisible into equal 256-value quantization blocks across devices (such as the 2.25 bpw IQ2_XS set, where 2304 = 9 * 256) previously downgraded --tp 2 and --tp 4 to tp = 1 layer splitting:

ds4: tensor parallel 2 -> 1: the experts' 256-value blocks split n_ff 2304 no other way (each GPU its own layers)

In addition, when head.weight uses a K-quant type (Q4_K, Q5_K, Q6_K), mat() / mat_gg() loaded evenly divided vocabulary slices (g.vocab / nm = 32320 rows per member on tp = 4), whereas head_cols() only checked BF16 and Q8_0 and fell back to split128(129280, 4) (32384 / 32384 / 32256 / 32256), shifting gathered logits and DSpark Markov head rows for tp = 4.

With this change, --tp 2 and --tp 4 run natively on 256-block GGUF packs using block-aligned uneven FFN slices (1280/1024 on tp = 2, 768/512/512/512 or 256/768/768/512 on tp = 4) with capacity-aware block placement across devices and aligned K-quant head slicing. On 4 x RTX 4090 48 GB (sm_89) at 1M context (--parallel 4), all 15,360 trunk experts and 384 MTP experts fit in VRAM with 0 GB spilled to the CPU lane, increasing single-stream code decode throughput from 122.8 tok/s (tp = 1) to 186.6 tok/s (tp = 4, +52.0%).

none

Approach

  1. Block-aligned uneven GGUF FFN sharding (src/dsv41/ds4_model.cu, src/dsv41/ds4_main.cpp, strata_control/dsv41_fit.py)

    • Splits n_ff along whole quantization and alignment blocks (LCM(64, DS4_TP_ALIGN, routed/shared down block)), assigning contiguous [ff0, ff0 + ffn) ranges per TP member so routed and shared experts share identical column boundaries.
    • Updates GGUF expert loading, host/pinned/NUMA streaming, CPU-lane fallback, and VRAM slot sizing to use each member's actual ff0 and ffn byte spans.
  2. Capacity-aware TP block placement (src/dsv41/ds4_tp_plan.hpp, src/dsv41/ds4_model.cu)

    • Accounts for per-device fixed memory overhead (MTP drafter, output head, and vision tower on the lead GPU) before freezing per-layer FFN block assignments.
    • Exchanges whole quantization blocks among TP members within each layer (keeping maximum per-member width bounded at 768 for n_ff = 2304 on TP4) so devices with higher fixed overhead hold fewer trunk FFN blocks.
    • Setting DS4_TP_BALANCE=0 falls back to uniform round-robin rotation.
  3. K-quant LM head vocabulary partition alignment (src/dsv41/ds4_model.cu)

    • Shares a unified dense_gguf_matrix() predicate between mat() and head_cols() covering BF16, Q8_0, Q4_K, Q5_K, and Q6_K, and verifies d.head.n == vn after loading.
  4. Runtime scratch isolation (src/dsv41/ds4_gguf.cu, src/dsv41/ds4_kernels.cu)

    • Keys GGUF scratch buffers by (device, stream) and split-attention scratch buffers by (device, stream, heads).

Validation

Passed:

  • Built strata-dsv41 from source at commit 4168fc3e (rebased on main ffa80d73) on Ubuntu 22.04.5 LTS (Linux 6.8.0-138-generic, 2 x Intel Xeon Gold 6330, 251 GiB RAM, 4 x NVIDIA RTX 4090 48 GB sm_89, driver 595.99.02, CUDA 13.0.88, GCC 11.4).
  • Ran strata-dsv41 --serve --pack /data/deepseek-v41/Strata-data/packs/deepseek-v4.1-flash-ist-das-2.25bpw --max-context 1048576 --eos 1 --vision on --vision-resident --dspark auto --dspark-conf 0.65 --tp 4 --reserve-mib 900 --parallel 4:
    ds4: GGUF TP balance group 0: moved 14 blocks (256 values),
         avg blocks/layer CUDA0=1.90 CUDA1=2.35 CUDA2=2.38 CUDA3=2.38
    ds4: CUDA0 layers [0, 42] (tensor parallel 4, part 0) + head: weights 3.07 GB, experts 38.23 GB (15744 of 15744 in VRAM), caches 3.87 GB, 1933 MiB free
    ds4: CUDA1 layers [0, 39] (tensor parallel 4, part 1): weights 2.40 GB, experts 39.09 GB (15360 of 15360 in VRAM), caches 3.87 GB, 2127 MiB free
    ds4: CUDA2 layers [0, 39] (tensor parallel 4, part 2): weights 2.40 GB, experts 39.48 GB (15360 of 15360 in VRAM), caches 3.87 GB, 1751 MiB free
    ds4: CUDA3 layers [0, 39] (tensor parallel 4, part 3): weights 2.40 GB, experts 39.48 GB (15360 of 15360 in VRAM), caches 3.87 GB, 1753 MiB free
    ds4: 0 routed experts on the CPU lane (0.0 GB, in place in the model's files), 56 threads
    
  • Verified output correctness and clean single-stream (max_in_flight = 1, temperature = 0, enable_thinking = false, max_tokens = 768) throughput across --tp 1, --tp 2, and --tp 4 on deepseek-v4.1-flash-ist-das-2.25bpw:
    • Arithmetic sanity check (123 * 456): returned 56088.
    • Code generation (Python LRU cache, 768 tokens): 186.6 tok/s decode (--tp 4 capacity-balanced) vs 158.4 tok/s (--tp 2) vs 141.6 tok/s (--tp 4 round-robin) vs 122.8 tok/s (--tp 1).
    • Technical prose (768 tokens): 118.4 tok/s (Chinese) and 122.2 tok/s (English DB transactions) on --tp 4, TTFT 119.8-147.2 ms, short-prompt prefill 314.5-364.0 tok/s.
    • Cold 2,093-token prompt prefill (cache_n = 0): 729.1 tok/s (2,870.8 ms) on --tp 4.

Failed:

  • none observed

Not run:

  • HIP (ROCm), SYCL, and Metal builds and runtime checks (tested on Linux CUDA sm_89 hardware only).
  • Non-256-block GGUF packs on 3-GPU tensor-parallel groups.

Limits

  • Within a single layer, uneven block assignment (e.g. 768 vs 512 or 256 on tp = 4) leaves per-layer compute bounded by the widest member (768), while capacity balancing equalizes VRAM usage across the full 40-layer stack.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5246 **Author:** [@Moeblack](https://github.com/Moeblack) **Created:** 11/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/dsv41-gguf-tp` --- ### 📝 Commits (1) - [`4168fc3`](https://github.com/Niko1221/Strata/commit/4168fc3e458d72517d2e5391e46b87b6bb457a7e) [dsv41] Support capacity-aware block-aligned GGUF tensor parallelism and fix K-quant head slicing ### 📊 Changes **6 files changed** (+593 additions, -139 deletions) <details> <summary>View changed files</summary> 📝 `src/dsv41/ds4_gguf.cu` (+10 -4) 📝 `src/dsv41/ds4_kernels.cu` (+5 -4) 📝 `src/dsv41/ds4_main.cpp` (+4 -1) 📝 `src/dsv41/ds4_model.cu` (+417 -129) ➕ `src/dsv41/ds4_tp_plan.hpp` (+156 -0) 📝 `strata_control/dsv41_fit.py` (+1 -1) </details> ### 📄 Description ## Problem and result GGUF DeepSeek-V4.1 packs whose expert intermediate width (`n_ff = 2304`) is not evenly divisible into equal 256-value quantization blocks across devices (such as the 2.25 bpw `IQ2_XS` set, where `2304 = 9 * 256`) previously downgraded `--tp 2` and `--tp 4` to `tp = 1` layer splitting: ```text ds4: tensor parallel 2 -> 1: the experts' 256-value blocks split n_ff 2304 no other way (each GPU its own layers) ``` In addition, when `head.weight` uses a K-quant type (`Q4_K`, `Q5_K`, `Q6_K`), `mat()` / `mat_gg()` loaded evenly divided vocabulary slices (`g.vocab / nm = 32320` rows per member on `tp = 4`), whereas `head_cols()` only checked `BF16` and `Q8_0` and fell back to `split128(129280, 4)` (`32384 / 32384 / 32256 / 32256`), shifting gathered logits and DSpark Markov head rows for `tp = 4`. With this change, `--tp 2` and `--tp 4` run natively on 256-block GGUF packs using block-aligned uneven FFN slices (`1280/1024` on `tp = 2`, `768/512/512/512` or `256/768/768/512` on `tp = 4`) with capacity-aware block placement across devices and aligned K-quant head slicing. On 4 x RTX 4090 48 GB (`sm_89`) at 1M context (`--parallel 4`), all 15,360 trunk experts and 384 MTP experts fit in VRAM with 0 GB spilled to the CPU lane, increasing single-stream code decode throughput from 122.8 tok/s (`tp = 1`) to 186.6 tok/s (`tp = 4`, +52.0%). ## Related discussion none ## Approach 1. **Block-aligned uneven GGUF FFN sharding (`src/dsv41/ds4_model.cu`, `src/dsv41/ds4_main.cpp`, `strata_control/dsv41_fit.py`)** - Splits `n_ff` along whole quantization and alignment blocks (`LCM(64, DS4_TP_ALIGN, routed/shared down block)`), assigning contiguous `[ff0, ff0 + ffn)` ranges per TP member so routed and shared experts share identical column boundaries. - Updates GGUF expert loading, host/pinned/NUMA streaming, CPU-lane fallback, and VRAM slot sizing to use each member's actual `ff0` and `ffn` byte spans. 2. **Capacity-aware TP block placement (`src/dsv41/ds4_tp_plan.hpp`, `src/dsv41/ds4_model.cu`)** - Accounts for per-device fixed memory overhead (MTP drafter, output head, and vision tower on the lead GPU) before freezing per-layer FFN block assignments. - Exchanges whole quantization blocks among TP members within each layer (keeping maximum per-member width bounded at 768 for `n_ff = 2304` on TP4) so devices with higher fixed overhead hold fewer trunk FFN blocks. - Setting `DS4_TP_BALANCE=0` falls back to uniform round-robin rotation. 3. **K-quant LM head vocabulary partition alignment (`src/dsv41/ds4_model.cu`)** - Shares a unified `dense_gguf_matrix()` predicate between `mat()` and `head_cols()` covering `BF16`, `Q8_0`, `Q4_K`, `Q5_K`, and `Q6_K`, and verifies `d.head.n == vn` after loading. 4. **Runtime scratch isolation (`src/dsv41/ds4_gguf.cu`, `src/dsv41/ds4_kernels.cu`)** - Keys GGUF scratch buffers by `(device, stream)` and split-attention scratch buffers by `(device, stream, heads)`. ## Validation **Passed:** - Built `strata-dsv41` from source at commit `4168fc3e` (rebased on `main` `ffa80d73`) on Ubuntu 22.04.5 LTS (Linux 6.8.0-138-generic, 2 x Intel Xeon Gold 6330, 251 GiB RAM, 4 x NVIDIA RTX 4090 48 GB `sm_89`, driver 595.99.02, CUDA 13.0.88, GCC 11.4). - Ran `strata-dsv41 --serve --pack /data/deepseek-v41/Strata-data/packs/deepseek-v4.1-flash-ist-das-2.25bpw --max-context 1048576 --eos 1 --vision on --vision-resident --dspark auto --dspark-conf 0.65 --tp 4 --reserve-mib 900 --parallel 4`: ```text ds4: GGUF TP balance group 0: moved 14 blocks (256 values), avg blocks/layer CUDA0=1.90 CUDA1=2.35 CUDA2=2.38 CUDA3=2.38 ds4: CUDA0 layers [0, 42] (tensor parallel 4, part 0) + head: weights 3.07 GB, experts 38.23 GB (15744 of 15744 in VRAM), caches 3.87 GB, 1933 MiB free ds4: CUDA1 layers [0, 39] (tensor parallel 4, part 1): weights 2.40 GB, experts 39.09 GB (15360 of 15360 in VRAM), caches 3.87 GB, 2127 MiB free ds4: CUDA2 layers [0, 39] (tensor parallel 4, part 2): weights 2.40 GB, experts 39.48 GB (15360 of 15360 in VRAM), caches 3.87 GB, 1751 MiB free ds4: CUDA3 layers [0, 39] (tensor parallel 4, part 3): weights 2.40 GB, experts 39.48 GB (15360 of 15360 in VRAM), caches 3.87 GB, 1753 MiB free ds4: 0 routed experts on the CPU lane (0.0 GB, in place in the model's files), 56 threads ``` - Verified output correctness and clean single-stream (`max_in_flight = 1`, `temperature = 0`, `enable_thinking = false`, `max_tokens = 768`) throughput across `--tp 1`, `--tp 2`, and `--tp 4` on `deepseek-v4.1-flash-ist-das-2.25bpw`: - Arithmetic sanity check (`123 * 456`): returned `56088`. - Code generation (Python LRU cache, 768 tokens): `186.6 tok/s` decode (`--tp 4` capacity-balanced) vs `158.4 tok/s` (`--tp 2`) vs `141.6 tok/s` (`--tp 4` round-robin) vs `122.8 tok/s` (`--tp 1`). - Technical prose (768 tokens): `118.4 tok/s` (Chinese) and `122.2 tok/s` (English DB transactions) on `--tp 4`, TTFT `119.8-147.2 ms`, short-prompt prefill `314.5-364.0 tok/s`. - Cold 2,093-token prompt prefill (`cache_n = 0`): `729.1 tok/s` (`2,870.8 ms`) on `--tp 4`. **Failed:** - none observed **Not run:** - HIP (`ROCm`), SYCL, and Metal builds and runtime checks (tested on Linux CUDA `sm_89` hardware only). - Non-256-block GGUF packs on 3-GPU tensor-parallel groups. ## Limits - Within a single layer, uneven block assignment (e.g. `768` vs `512` or `256` on `tp = 4`) leaves per-layer compute bounded by the widest member (`768`), while capacity balancing equalizes VRAM usage across the full 40-layer stack. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
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
Niko1221/Strata#5364
No description provided.