[GH-ISSUE #609] ds4: DS4_RING_MB=128 instead of the default 400 reads prompts 6-12 % faster on 2x 64 GB cards (and leaves ~33 more experts a card in VRAM). Should the prompt ring be sized by VRAM / link speed? #253

Open
opened 2026-10-29 21:23:21 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @SeriousRising on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/609

Platform-specific: we measured this on one rig only: 2x CMP 170HX 64 GB, card 1 on PCIe Gen2 x4. The gain may come
from the slow link. This is a finding with a question, not a patch.

Finding

The prompt flow's expert ring is a fixed DS4_RING_MB (default 400) of slots in Chunk::kParts batches, allocated on
each flow device before expert placement (ds4_model.cu:4287-4292 in v1.1.34). Unchanged in v1.1.35 per its release
notes, which list no DeepSeek changes; not checked in source. At ~8.8-9 MB an expert blob, 400 MiB is roughly 48
slots, and 128 MiB is 16, still in 4 batches.

Setting DS4_RING_MB=128 made every prompt length faster in all our arms. The 272 MiB a card it frees also goes to the
experts at placement: 6811 vs 6775 experts in VRAM on CUDA0, 6762 vs 6731 on CUDA1.

Measured

Hardware: 2x CMP 170HX 64 GB (sm_80, CUDA 12.8); card 0 is PCIe Gen2 x16 (6.2 GB/s measured), card 1 Gen2 x4
(1.63 GB/s). Host VM: 16 vCPU Xeon E5-2697 v4 (AVX2), 106 GiB DDR4-2133. Model: DeepSeek-V4.1-Flash-1017 GSQ-RCO
IQ2_XXS, layer split, 64K context, --dspark on, --cpu-threads 14, default --prefill-chunk. About 2200 experts
on the CPU lane, so every prompt chunk streams many experts.

How measured: Strata's community speed suite through the server (fresh 4K / 16K / 32K prompts, prompt tok/s; an
agent session with prefix reuse, time to first token), plus our own 8K prefill. Each pair runs the same binary and
env; only DS4_RING_MB differs.

build (base) ring 4K 16K 32K 8K prefill agent TTFT
ours on v1.1.29 400 975.8 1567.3 1732.8 603.1 7.90 s
128 1093.6 (+12.1 %) 1683.4 (+7.4 %) 1833.8 (+5.8 %) 650.0 (+7.8 %) 6.51 s
ours on v1.1.29, more patches 400 1000.4 1584.6 1746.7 611.0 7.76 s
128, r1 / r2 1119.4 / 1117.9 (+12 %) 1709.5 / 1701.3 (+7.6 %) 1858.5 / 1849.7 (+6.1 %) 652.4 / 652.4 (+6.8 %) 6.86 / 6.76 s
  • Decode: --dspark none 24.13 vs 24.28 ms a step (-0.6 %). The DSpark text changes because placement changes, so
    its ms a window is not matched work.
  • Quality and two chats: 12/12; two chats in flight 67.6 / 65.2 tok/s.
  • We have served with 128 since 2026-10-27.

What we did not isolate

The extra experts alone cannot explain this. ~33 more a card is ~3 % fewer of the ~1100 a card that a chunk
streams. That bounds their share near 3 % on a link-bound card, below the 12 % at 4K. Our own audit estimated well
under 1 % for decode from them. The gain also shrinks with prompt length
(12 % at 4K, 6 % at 32K). That fits a fixed per-chunk or per-layer start-up cost of the larger ring better: for
example, the first batch of ~12 blobs must arrive before compute starts, against ~4. The x4 link makes that wait
longest. This is a guess. We did not run DS4_FLOW_STATS on the pair, nor try 128 at a fixed placement.

Question / proposal

  • Is 400 MiB tuned for a specific case (fast links, small cards)? On 64 GB cards with a slow link, 128 is faster at
    every prompt length we tried.
  • Options: size the ring from the measured link speed and the blob size (the flow already measures the link). Or
    include DS4_RING_MB in --calibrate's prompt tuning. Or simply default to fewer slots where a card's link is
    slow.
  • We can run more sizes (64 / 96 / 192 / 256) and a stats pair on this rig if useful.
Originally created by @SeriousRising on GitHub (Oct 28, 2026). Original GitHub issue: https://github.com/mw00/project-maya/issues/609 **Platform-specific:** we measured this on one rig only: 2x CMP 170HX 64 GB, card 1 on PCIe Gen2 x4. The gain may come from the slow link. This is a finding with a question, not a patch. ## Finding The prompt flow's expert ring is a fixed `DS4_RING_MB` (default 400) of slots in `Chunk::kParts` batches, allocated on each flow device before expert placement (`ds4_model.cu:4287-4292` in v1.1.34). Unchanged in v1.1.35 per its release notes, which list no DeepSeek changes; not checked in source. At ~8.8-9 MB an expert blob, 400 MiB is roughly 48 slots, and 128 MiB is 16, still in 4 batches. Setting `DS4_RING_MB=128` made every prompt length faster in all our arms. The 272 MiB a card it frees also goes to the experts at placement: 6811 vs 6775 experts in VRAM on CUDA0, 6762 vs 6731 on CUDA1. ## Measured **Hardware:** 2x CMP 170HX 64 GB (sm_80, CUDA 12.8); card 0 is PCIe Gen2 x16 (6.2 GB/s measured), card 1 Gen2 x4 (1.63 GB/s). Host VM: 16 vCPU Xeon E5-2697 v4 (AVX2), 106 GiB DDR4-2133. Model: DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XXS, layer split, 64K context, `--dspark on`, `--cpu-threads 14`, default `--prefill-chunk`. About 2200 experts on the CPU lane, so every prompt chunk streams many experts. **How measured:** Strata's community speed suite through the server (fresh 4K / 16K / 32K prompts, prompt tok/s; an agent session with prefix reuse, time to first token), plus our own 8K prefill. Each pair runs the same binary and env; only `DS4_RING_MB` differs. | build (base) | ring | 4K | 16K | 32K | 8K prefill | agent TTFT | |---|---|---|---|---|---|---| | ours on v1.1.29 | 400 | 975.8 | 1567.3 | 1732.8 | 603.1 | 7.90 s | | | 128 | 1093.6 (+12.1 %) | 1683.4 (+7.4 %) | 1833.8 (+5.8 %) | 650.0 (+7.8 %) | 6.51 s | | ours on v1.1.29, more patches | 400 | 1000.4 | 1584.6 | 1746.7 | 611.0 | 7.76 s | | | 128, r1 / r2 | 1119.4 / 1117.9 (+12 %) | 1709.5 / 1701.3 (+7.6 %) | 1858.5 / 1849.7 (+6.1 %) | 652.4 / 652.4 (+6.8 %) | 6.86 / 6.76 s | - **Decode:** `--dspark none` 24.13 vs 24.28 ms a step (-0.6 %). The DSpark text changes because placement changes, so its ms a window is not matched work. - **Quality and two chats:** 12/12; two chats in flight 67.6 / 65.2 tok/s. - We have served with 128 since 2026-10-27. ## What we did not isolate The extra experts alone cannot explain this. ~33 more a card is ~3 % fewer of the ~1100 a card that a chunk streams. That bounds their share near 3 % on a link-bound card, below the 12 % at 4K. Our own audit estimated well under 1 % for decode from them. The gain also shrinks with prompt length (12 % at 4K, 6 % at 32K). That fits a fixed per-chunk or per-layer start-up cost of the larger ring better: for example, the first batch of ~12 blobs must arrive before compute starts, against ~4. The x4 link makes that wait longest. This is a guess. We did not run `DS4_FLOW_STATS` on the pair, nor try 128 at a fixed placement. ## Question / proposal - Is 400 MiB tuned for a specific case (fast links, small cards)? On 64 GB cards with a slow link, 128 is faster at every prompt length we tried. - Options: size the ring from the measured link speed and the blob size (the flow already measures the link). Or include `DS4_RING_MB` in `--calibrate`'s prompt tuning. Or simply default to fewer slots where a card's link is slow. - We can run more sizes (64 / 96 / 192 / 256) and a stats pair on this rig if useful.
Author
Owner

@talisp commented on GitHub (Oct 28, 2026):

A data point from a different case: one GPU, with big MXFP4 expert blobs and most of them on the CPU lane. Here DS4_RING_MB=128 makes long prompts ~10% slower. So we'd size the ring in slots (blob size), not in MB.

Why it differs from yours: our experts are DeepSeek's MXFP4 (unsloth's UD-Q8_K_XL), ~19.4 MB a blob against your ~8.8 MB. With the code in ds4_model.cu:4287-4292, 400 MiB is 20 slots (5 a batch), but 128 MiB is only 4, the kParts minimum, one slot a batch. Yours kept 16.

Measured (1× L40S 48 GB, Xeon Platinum 8580 VM with 32 vCPUs, ~504 GB RAM, Maya v1.1.34, --tp 2 --threads on --cpu-threads 28 --mmap-experts off --dspark on, 262K context; ~91% of the experts on the CPU lane). Four starts in the order A B A B, page cache dropped before each; fresh prompts, prompt tok/s from the server's timings:

DS4_RING_MB Experts in VRAM 10.4K 42.8K 174K 42.8K, second prompt Decode tok/s
400 (default) 1,357 563 / 710 1,214 / 1,412 1,893 / 1,952 1,436 / 1,458 40.9 / 41.0
128 1,373 633 / 636 1,229 / 1,232 1,705 / 1,711 1,304 / 1,315 41.6 / 41.7
  • Long prompts: 128 is ~10% slower at 174K and on the second 42.8K prompt, in both pairs.
  • Short prompts: within our run-to-run spread at 10.4K and the first 42.8K. The 400 starts vary more (563-710); 128 is steadier, but not faster on average.
  • Decode: the freed VRAM buys 16 more experts here (yours bought ~33 a card, since your blobs are half the size), worth ~1.5%.

So on your question: sizing by link speed might explain your slow Gen2 x4 card. Sizing by blob size would avoid our case, where 128 MiB drops the ring to one slot a batch. Something like "N slots a batch" (yours: 4 a batch at 128 MiB) rather than a fixed MB could get you your gain without costing big-blob packs theirs.

<!-- gh-comment-id:6475044447 --> @talisp commented on GitHub (Oct 28, 2026): A data point from a different case: one GPU, with big MXFP4 expert blobs and most of them on the CPU lane. **Here `DS4_RING_MB=128` makes long prompts ~10% slower.** So we'd size the ring in slots (blob size), not in MB. **Why it differs from yours:** our experts are DeepSeek's MXFP4 (unsloth's UD-Q8_K_XL), ~19.4 MB a blob against your ~8.8 MB. With the code in `ds4_model.cu:4287-4292`, 400 MiB is 20 slots (5 a batch), but 128 MiB is only 4, the `kParts` minimum, one slot a batch. Yours kept 16. **Measured** (1× L40S 48 GB, Xeon Platinum 8580 VM with 32 vCPUs, ~504 GB RAM, Maya v1.1.34, `--tp 2 --threads on --cpu-threads 28 --mmap-experts off --dspark on`, 262K context; ~91% of the experts on the CPU lane). Four starts in the order A B A B, page cache dropped before each; fresh prompts, prompt tok/s from the server's timings: | `DS4_RING_MB` | Experts in VRAM | 10.4K | 42.8K | 174K | 42.8K, second prompt | Decode tok/s | |---|---|---|---|---|---|---| | 400 (default) | 1,357 | 563 / 710 | 1,214 / 1,412 | **1,893 / 1,952** | **1,436 / 1,458** | 40.9 / 41.0 | | 128 | 1,373 | 633 / 636 | 1,229 / 1,232 | **1,705 / 1,711** | **1,304 / 1,315** | 41.6 / 41.7 | - **Long prompts:** 128 is ~10% slower at 174K and on the second 42.8K prompt, in both pairs. - **Short prompts:** within our run-to-run spread at 10.4K and the first 42.8K. The 400 starts vary more (563-710); 128 is steadier, but not faster on average. - **Decode:** the freed VRAM buys 16 more experts here (yours bought ~33 a card, since your blobs are half the size), worth ~1.5%. So on your question: sizing by link speed might explain your slow Gen2 x4 card. Sizing by blob size would avoid our case, where 128 MiB drops the ring to one slot a batch. Something like "N slots a batch" (yours: 4 a batch at 128 MiB) rather than a fixed MB could get you your gain without costing big-blob packs theirs.
Author
Owner

@SeriousRising commented on GitHub (Oct 28, 2026):

Thanks - that pins the unit down. Confirming your reading of the code on v1.1.35 (ds4_model.cu:4287-4292):
ring_n = max(kParts, ((mb << 20) / stride) / kParts * kParts) with kParts = 4 and stride = the device's
largest trunk-layer expert blob. One correction to my numbers above: on the GSQ-RCO pack the largest blob is
8.97 MiB (CUDA0's layers) / 9.76 MiB (CUDA1's), so 128 MiB is 12 slots = 3 a batch here, not 16 / 4.

The slot curve on this rig

Same setup as the issue (2x CMP 170HX 64 GB, card 1 on PCIe Gen2 x4 at 1.63 GB/s measured, DeepSeek-V4.1-Flash-1017
GSQ-RCO IQ2_XXS, layer split, ~2200 experts on the CPU lane), one binary, one run each except 128 and 72 MiB,
which ran twice. Fresh prompts:
our 8K prefill plus the community suite's 4K / 16K / 32K, prompt tok/s.

DS4_RING_MB slots a batch (CUDA0 / CUDA1) 8K 4K 16K 32K decode tok/s
400 (default) 11 / 10 694.7 1036.8 1609.7 1756.1 52.0
280 7 / 7 721.6 1106.7 1641.9 1774.1 53.7
128 3 / 3 738.1 1187.3 1727.5 1860.0 53.2
72 2 / 1 (the floor) 753.9 1206.5 1755.4 1881.2 52.9

The repeats: 128 MiB 724.9 / 1189.4 / 1746.0 / 1876.4 and 72 MiB 725.3 / 1205.8 / 1764.9 / 1886.4 (8K / 4K / 16K /
32K) - 72 MiB stays 0.5-1.6 % ahead of 128 on prompts across both pairs and 0.6-1.3 % behind on decode, inside our
spread at the long end. Experts in VRAM move very little across the sweep (CUDA1: 6731 at 400 MiB -> 6771 at 72, of
7680 a card), so the prompt gain is not the freed VRAM; and decode shows no trend (52.0-53.7).

So the two rigs sit at opposite ends: yours (one fast-link card, 19.4 MB blobs, ~91 % streamed) wants ~5 a batch
and loses ~10 % at 1; this one (the second card on Gen2 x4, ~9 MB blobs, ~14 % streamed) keeps gaining down to
1 a batch on the slow card (+16 % at 4K, +7 % at 32K against the default). I have not isolated why - smaller
batches presumably let a layer's first experts compute while the slow link is still delivering the rest, where on
a fast link the same small batch only serializes copy against compute. That part is a guess.

Either way MB is the wrong unit for the setting: the default 400 lands at 1 a batch on a hypothetical 25 MB-blob
pack and at 11 here. Sizing in slots a batch, as you suggest, with the MB derived from the stride, would make the
default mean the same thing on every pack; something like 4 a batch (16 slots) would be ~140-155 MiB on this pack
and ~310 MiB on yours - close to both measured good regions (this rig gains only 1-2 % more below 3 a batch).

<!-- gh-comment-id:6477384329 --> @SeriousRising commented on GitHub (Oct 28, 2026): Thanks - that pins the unit down. Confirming your reading of the code on v1.1.35 (`ds4_model.cu:4287-4292`): `ring_n = max(kParts, ((mb << 20) / stride) / kParts * kParts)` with `kParts = 4` and `stride` = the device's largest trunk-layer expert blob. One correction to my numbers above: on the GSQ-RCO pack the largest blob is 8.97 MiB (CUDA0's layers) / 9.76 MiB (CUDA1's), so 128 MiB is 12 slots = 3 a batch here, not 16 / 4. ### The slot curve on this rig Same setup as the issue (2x CMP 170HX 64 GB, card 1 on PCIe Gen2 x4 at 1.63 GB/s measured, DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XXS, layer split, ~2200 experts on the CPU lane), one binary, one run each except 128 and 72 MiB, which ran twice. Fresh prompts: our 8K prefill plus the community suite's 4K / 16K / 32K, prompt tok/s. | `DS4_RING_MB` | slots a batch (CUDA0 / CUDA1) | 8K | 4K | 16K | 32K | decode tok/s | |---|---|---|---|---|---|---| | 400 (default) | 11 / 10 | 694.7 | 1036.8 | 1609.7 | 1756.1 | 52.0 | | 280 | 7 / 7 | 721.6 | 1106.7 | 1641.9 | 1774.1 | 53.7 | | 128 | 3 / 3 | 738.1 | 1187.3 | 1727.5 | 1860.0 | 53.2 | | 72 | 2 / **1 (the floor)** | 753.9 | 1206.5 | 1755.4 | 1881.2 | 52.9 | The repeats: 128 MiB 724.9 / 1189.4 / 1746.0 / 1876.4 and 72 MiB 725.3 / 1205.8 / 1764.9 / 1886.4 (8K / 4K / 16K / 32K) - 72 MiB stays 0.5-1.6 % ahead of 128 on prompts across both pairs and 0.6-1.3 % behind on decode, inside our spread at the long end. Experts in VRAM move very little across the sweep (CUDA1: 6731 at 400 MiB -> 6771 at 72, of 7680 a card), so the prompt gain is not the freed VRAM; and decode shows no trend (52.0-53.7). So the two rigs sit at opposite ends: yours (one fast-link card, 19.4 MB blobs, ~91 % streamed) wants ~5 a batch and loses ~10 % at 1; this one (the second card on Gen2 x4, ~9 MB blobs, ~14 % streamed) keeps gaining down to 1 a batch on the slow card (+16 % at 4K, +7 % at 32K against the default). I have not isolated why - smaller batches presumably let a layer's first experts compute while the slow link is still delivering the rest, where on a fast link the same small batch only serializes copy against compute. That part is a guess. Either way MB is the wrong unit for the setting: the default 400 lands at 1 a batch on a hypothetical 25 MB-blob pack and at 11 here. Sizing in slots a batch, as you suggest, with the MB derived from the stride, would make the default mean the same thing on every pack; something like 4 a batch (16 slots) would be ~140-155 MiB on this pack and ~310 MiB on yours - close to both measured good regions (this rig gains only 1-2 % more below 3 a batch).
Author
Owner

@talisp commented on GitHub (Oct 29, 2026):

Two more points, on v1.1.36 (same box and pack as my table above; one start each, page cache dropped before each), in case they help size the ring in slots. Slots from ring_n = max(4, (mb<<20) / stride / 4 * 4) with our 18,800,640 B blobs:

DS4_RING_MB Slots (a batch) Experts in VRAM 10.4K 42.7K 174K Decode tok/s
400 (default) 20 (5) 1,357 712 1,420 1,965 40.4
310 16 (4) 1,361 612 1,279 1,881 40.9
233 12 (3) 1,365 693 1,368 1,893 41.3
128 (v1.1.34, from above) 4 (1) 1,373 633-636 1,229-1,232 1,705-1,711 41.6

On this pack, every ring below the default reads long prompts slower (-4% at 174K with 3-4 a batch, -13% with 1), while decode gains only 1-3% from the 4-16 extra experts. Short prompts are noisy here (the 400 starts ranged 563-712 at 10.4K). So a fixed slot count wouldn't settle it either: 4 a batch is about what you gained with, and it costs us ~4%. The link and the CPU lane seem to matter as much as the blob size, so maybe it could be measured at start, as lane-times.txt is.

<!-- gh-comment-id:6491388629 --> @talisp commented on GitHub (Oct 29, 2026): Two more points, on v1.1.36 (same box and pack as my table above; one start each, page cache dropped before each), in case they help size the ring in slots. Slots from `ring_n = max(4, (mb<<20) / stride / 4 * 4)` with our 18,800,640 B blobs: | `DS4_RING_MB` | Slots (a batch) | Experts in VRAM | 10.4K | 42.7K | 174K | Decode tok/s | |---|---|---|---|---|---|---| | 400 (default) | 20 (5) | 1,357 | 712 | 1,420 | **1,965** | 40.4 | | 310 | 16 (4) | 1,361 | 612 | 1,279 | 1,881 | 40.9 | | 233 | 12 (3) | 1,365 | 693 | 1,368 | 1,893 | 41.3 | | 128 (v1.1.34, from above) | 4 (1) | 1,373 | 633-636 | 1,229-1,232 | 1,705-1,711 | 41.6 | On this pack, every ring below the default reads long prompts slower (-4% at 174K with 3-4 a batch, -13% with 1), while decode gains only 1-3% from the 4-16 extra experts. Short prompts are noisy here (the 400 starts ranged 563-712 at 10.4K). So a fixed slot count wouldn't settle it either: 4 a batch is about what you gained with, and it costs us ~4%. The link and the CPU lane seem to matter as much as the blob size, so maybe it could be measured at start, as `lane-times.txt` is.
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#253
No description provided.