Skip to content

CUDA: linearize MoE data layout for MMQ/MMF - #31047

Merged
ggerganov merged 3 commits into
ggml-org:masterfrom
JohannesGaessler:cuda-mmq-linearized-2
Nov 5, 2026
Merged

ggerganov merged 3 commits into
ggml-org:masterfrom
JohannesGaessler:cuda-mmq-linearized-2

Conversation

@JohannesGaessler

Copy link
Copy Markdown
Contributor

This PR changes the data layout for the MMQ and MMF CUDA kernels. Instead of just lower and upper bounds for the columns assigned to each expert the helper kernel in mmid.cu now pre-computes the assignment of tiles. This way you can get by with fewer tiles that can potentially run in the main kernel so there is less overhead. Also you can more flexibly distribute the tiles across experts which is needed as a prerequisite for a simple implementation of duplicate expert IDs in the CUDA backend (without causing a 10-20% performance regression). Other than the expert tile layout the only other functional change is that I am also enabling the optimization for RDNA 3/4 that prefers smaller tiles for other GPUs as well; previously this was not beneficial due to the increased overhead. The performance improvements from the new data layout are 2-4%, the rest is from the smaller tiles (so less compute is wasted). For Granite 3.0 the performance changes are relatively noisy because whether or not the fixup kernel runs has a large impact on the total runtime. Other than the previous points I have refactored the MMQ code a bit more generally to fit better with the new data structures.

Performance tiny MoE

Table generated with scripts/compare-llama-bench.py

GPU Model Microbatch size Test t/s master t/s bea596f Speedup
MI60 / MI50 granitemoe 3B.A800M F16 1 pp8192 142.08 141.03 0.99
MI60 / MI50 granitemoe 3B.A800M F16 2 pp8192 203.24 203.54 1.00
MI60 / MI50 granitemoe 3B.A800M F16 4 pp8192 243.78 244.86 1.00
MI60 / MI50 granitemoe 3B.A800M F16 8 pp8192 263.04 259.96 0.99
MI60 / MI50 granitemoe 3B.A800M F16 16 pp8192 138.87 139.20 1.00
MI60 / MI50 granitemoe 3B.A800M F16 32 pp8192 233.66 233.06 1.00
MI60 / MI50 granitemoe 3B.A800M F16 64 pp8192 404.03 403.30 1.00
MI60 / MI50 granitemoe 3B.A800M F16 128 pp8192 687.96 687.95 1.00
MI60 / MI50 granitemoe 3B.A800M F16 256 pp8192 1082.72 1082.92 1.00
MI60 / MI50 granitemoe 3B.A800M F16 512 pp8192 1574.76 1573.66 1.00
MI60 / MI50 granitemoe 3B.A800M F16 1024 pp8192 2046.15 2046.23 1.00
MI60 / MI50 granitemoe 3B.A800M F16 2048 pp8192 2405.09 2407.95 1.00
MI60 / MI50 granitemoe 3B.A800M F16 4096 pp8192 2396.40 2400.15 1.00
MI60 / MI50 granitemoe 3B.A800M Q4_0 1 pp8192 179.40 178.15 0.99
MI60 / MI50 granitemoe 3B.A800M Q4_0 2 pp8192 322.46 321.44 1.00
MI60 / MI50 granitemoe 3B.A800M Q4_0 4 pp8192 500.62 498.62 1.00
MI60 / MI50 granitemoe 3B.A800M Q4_0 8 pp8192 696.16 688.87 0.99
MI60 / MI50 granitemoe 3B.A800M Q4_0 16 pp8192 824.18 795.24 0.96
MI60 / MI50 granitemoe 3B.A800M Q4_0 32 pp8192 1119.69 1164.79 1.04
MI60 / MI50 granitemoe 3B.A800M Q4_0 64 pp8192 1343.37 1657.04 1.23
MI60 / MI50 granitemoe 3B.A800M Q4_0 128 pp8192 2047.50 2265.17 1.11
MI60 / MI50 granitemoe 3B.A800M Q4_0 256 pp8192 2809.05 2814.50 1.00
MI60 / MI50 granitemoe 3B.A800M Q4_0 512 pp8192 3234.54 3216.87 0.99
MI60 / MI50 granitemoe 3B.A800M Q4_0 1024 pp8192 3539.36 3505.40 0.99
MI60 / MI50 granitemoe 3B.A800M Q4_0 2048 pp8192 3636.58 3601.27 0.99
MI60 / MI50 granitemoe 3B.A800M Q4_0 4096 pp8192 3617.34 3589.61 0.99
MI100 granitemoe 3B.A800M F16 1 pp8192 155.13 152.83 0.99
MI100 granitemoe 3B.A800M F16 2 pp8192 227.78 222.68 0.98
MI100 granitemoe 3B.A800M F16 4 pp8192 296.60 291.08 0.98
MI100 granitemoe 3B.A800M F16 8 pp8192 372.69 368.54 0.99
MI100 granitemoe 3B.A800M F16 16 pp8192 1017.08 1012.52 1.00
MI100 granitemoe 3B.A800M F16 32 pp8192 1768.86 1536.52 0.87
MI100 granitemoe 3B.A800M F16 64 pp8192 2565.18 2438.64 0.95
MI100 granitemoe 3B.A800M F16 128 pp8192 3479.99 3400.21 0.98
MI100 granitemoe 3B.A800M F16 256 pp8192 4117.87 4105.18 1.00
MI100 granitemoe 3B.A800M F16 512 pp8192 4846.85 4934.05 1.02
MI100 granitemoe 3B.A800M F16 1024 pp8192 6016.02 5981.00 0.99
MI100 granitemoe 3B.A800M F16 2048 pp8192 7410.03 7379.20 1.00
MI100 granitemoe 3B.A800M F16 4096 pp8192 7399.93 7336.99 0.99
MI100 granitemoe 3B.A800M Q4_0 1 pp8192 181.28 178.60 0.99
MI100 granitemoe 3B.A800M Q4_0 2 pp8192 326.49 328.74 1.01
MI100 granitemoe 3B.A800M Q4_0 4 pp8192 505.41 508.95 1.01
MI100 granitemoe 3B.A800M Q4_0 8 pp8192 715.87 706.72 0.99
MI100 granitemoe 3B.A800M Q4_0 16 pp8192 1181.06 1102.60 0.93
MI100 granitemoe 3B.A800M Q4_0 32 pp8192 1884.63 1826.45 0.97
MI100 granitemoe 3B.A800M Q4_0 64 pp8192 2421.22 2654.80 1.10
MI100 granitemoe 3B.A800M Q4_0 128 pp8192 3249.69 3825.40 1.18
MI100 granitemoe 3B.A800M Q4_0 256 pp8192 4396.38 5505.08 1.25
MI100 granitemoe 3B.A800M Q4_0 512 pp8192 5067.98 6970.53 1.38
MI100 granitemoe 3B.A800M Q4_0 1024 pp8192 5576.18 8228.29 1.48
MI100 granitemoe 3B.A800M Q4_0 2048 pp8192 5971.27 9274.42 1.55
MI100 granitemoe 3B.A800M Q4_0 4096 pp8192 5965.38 9242.61 1.55
P40 granitemoe 3B.A800M F16 1 pp8192 70.41 70.36 1.00
P40 granitemoe 3B.A800M F16 2 pp8192 82.79 82.53 1.00
P40 granitemoe 3B.A800M F16 4 pp8192 112.70 112.53 1.00
P40 granitemoe 3B.A800M F16 8 pp8192 131.67 131.66 1.00
P40 granitemoe 3B.A800M F16 16 pp8192 196.38 196.55 1.00
P40 granitemoe 3B.A800M F16 32 pp8192 303.04 303.30 1.00
P40 granitemoe 3B.A800M F16 64 pp8192 458.25 458.60 1.00
P40 granitemoe 3B.A800M F16 128 pp8192 685.76 685.83 1.00
P40 granitemoe 3B.A800M F16 256 pp8192 938.39 937.72 1.00
P40 granitemoe 3B.A800M F16 512 pp8192 1213.79 1212.82 1.00
P40 granitemoe 3B.A800M F16 1024 pp8192 1479.79 1476.92 1.00
P40 granitemoe 3B.A800M F16 2048 pp8192 1640.28 1634.49 1.00
P40 granitemoe 3B.A800M F16 4096 pp8192 1636.72 1635.23 1.00
P40 granitemoe 3B.A800M Q4_0 1 pp8192 132.66 132.86 1.00
P40 granitemoe 3B.A800M Q4_0 2 pp8192 246.95 247.27 1.00
P40 granitemoe 3B.A800M Q4_0 4 pp8192 352.91 353.03 1.00
P40 granitemoe 3B.A800M Q4_0 8 pp8192 543.18 535.13 0.99
P40 granitemoe 3B.A800M Q4_0 16 pp8192 828.03 832.59 1.01
P40 granitemoe 3B.A800M Q4_0 32 pp8192 1130.91 1256.65 1.11
P40 granitemoe 3B.A800M Q4_0 64 pp8192 1430.45 1670.86 1.17
P40 granitemoe 3B.A800M Q4_0 128 pp8192 1920.64 1987.66 1.03
P40 granitemoe 3B.A800M Q4_0 256 pp8192 2290.27 2298.20 1.00
P40 granitemoe 3B.A800M Q4_0 512 pp8192 2489.39 2502.59 1.01
P40 granitemoe 3B.A800M Q4_0 1024 pp8192 2697.45 2715.35 1.01
P40 granitemoe 3B.A800M Q4_0 2048 pp8192 2795.39 2820.41 1.01
P40 granitemoe 3B.A800M Q4_0 4096 pp8192 2794.50 2819.89 1.01
RTX 3090 granitemoe 3B.A800M F16 1 pp8192 238.88 238.72 1.00
RTX 3090 granitemoe 3B.A800M F16 2 pp8192 396.92 396.85 1.00
RTX 3090 granitemoe 3B.A800M F16 4 pp8192 656.26 656.42 1.00
RTX 3090 granitemoe 3B.A800M F16 8 pp8192 1078.10 1079.39 1.00
RTX 3090 granitemoe 3B.A800M F16 16 pp8192 1674.40 1673.57 1.00
RTX 3090 granitemoe 3B.A800M F16 32 pp8192 2655.92 2111.88 0.80
RTX 3090 granitemoe 3B.A800M F16 64 pp8192 3652.59 3280.32 0.90
RTX 3090 granitemoe 3B.A800M F16 128 pp8192 4549.63 4455.06 0.98
RTX 3090 granitemoe 3B.A800M F16 256 pp8192 4969.25 5075.41 1.02
RTX 3090 granitemoe 3B.A800M F16 512 pp8192 5898.96 6281.97 1.06
RTX 3090 granitemoe 3B.A800M F16 1024 pp8192 6894.18 6920.33 1.00
RTX 3090 granitemoe 3B.A800M F16 2048 pp8192 7939.88 8056.56 1.01
RTX 3090 granitemoe 3B.A800M F16 4096 pp8192 8025.58 8031.24 1.00
RTX 3090 granitemoe 3B.A800M Q4_0 1 pp8192 353.77 356.00 1.01
RTX 3090 granitemoe 3B.A800M Q4_0 2 pp8192 635.32 639.28 1.01
RTX 3090 granitemoe 3B.A800M Q4_0 4 pp8192 979.27 987.39 1.01
RTX 3090 granitemoe 3B.A800M Q4_0 8 pp8192 1392.44 1402.05 1.01
RTX 3090 granitemoe 3B.A800M Q4_0 16 pp8192 2298.61 2372.02 1.03
RTX 3090 granitemoe 3B.A800M Q4_0 32 pp8192 3571.24 3204.86 0.90
RTX 3090 granitemoe 3B.A800M Q4_0 64 pp8192 4980.77 4833.15 0.97
RTX 3090 granitemoe 3B.A800M Q4_0 128 pp8192 5853.11 6315.78 1.08
RTX 3090 granitemoe 3B.A800M Q4_0 256 pp8192 8619.13 8889.29 1.03
RTX 3090 granitemoe 3B.A800M Q4_0 512 pp8192 11182.37 11391.96 1.02
RTX 3090 granitemoe 3B.A800M Q4_0 1024 pp8192 12865.22 13212.38 1.03
RTX 3090 granitemoe 3B.A800M Q4_0 2048 pp8192 13314.15 13862.24 1.04
RTX 3090 granitemoe 3B.A800M Q4_0 4096 pp8192 12989.12 14608.90 1.12
RTX 4090 granitemoe 3B.A800M F16 1 pp8192 304.01 304.12 1.00
RTX 4090 granitemoe 3B.A800M F16 2 pp8192 478.07 477.95 1.00
RTX 4090 granitemoe 3B.A800M F16 4 pp8192 792.15 791.80 1.00
RTX 4090 granitemoe 3B.A800M F16 8 pp8192 1325.31 1325.33 1.00
RTX 4090 granitemoe 3B.A800M F16 16 pp8192 2162.54 2163.85 1.00
RTX 4090 granitemoe 3B.A800M F16 32 pp8192 3686.06 3096.57 0.84
RTX 4090 granitemoe 3B.A800M F16 64 pp8192 5898.60 5596.00 0.95
RTX 4090 granitemoe 3B.A800M F16 128 pp8192 8678.66 9152.36 1.05
RTX 4090 granitemoe 3B.A800M F16 256 pp8192 8232.67 8591.55 1.04
RTX 4090 granitemoe 3B.A800M F16 512 pp8192 11816.74 12208.56 1.03
RTX 4090 granitemoe 3B.A800M F16 1024 pp8192 10656.18 10644.40 1.00
RTX 4090 granitemoe 3B.A800M F16 2048 pp8192 12459.90 12373.92 0.99
RTX 4090 granitemoe 3B.A800M F16 4096 pp8192 12394.65 12458.74 1.01
RTX 4090 granitemoe 3B.A800M Q4_0 1 pp8192 442.87 442.88 1.00
RTX 4090 granitemoe 3B.A800M Q4_0 2 pp8192 819.72 819.64 1.00
RTX 4090 granitemoe 3B.A800M Q4_0 4 pp8192 1422.40 1421.19 1.00
RTX 4090 granitemoe 3B.A800M Q4_0 8 pp8192 2403.09 2405.05 1.00
RTX 4090 granitemoe 3B.A800M Q4_0 16 pp8192 3244.58 3040.75 0.94
RTX 4090 granitemoe 3B.A800M Q4_0 32 pp8192 5419.43 5362.25 0.99
RTX 4090 granitemoe 3B.A800M Q4_0 64 pp8192 8481.36 8545.59 1.01
RTX 4090 granitemoe 3B.A800M Q4_0 128 pp8192 11133.84 12127.38 1.09
RTX 4090 granitemoe 3B.A800M Q4_0 256 pp8192 17719.55 20045.91 1.13
RTX 4090 granitemoe 3B.A800M Q4_0 512 pp8192 28925.94 27556.59 0.95
RTX 4090 granitemoe 3B.A800M Q4_0 1024 pp8192 34771.76 33857.35 0.97
RTX 4090 granitemoe 3B.A800M Q4_0 2048 pp8192 33675.70 33631.94 1.00
RTX 4090 granitemoe 3B.A800M Q4_0 4096 pp8192 33765.33 33605.86 1.00
RTX 5090 granitemoe 3B.A800M F16 1 pp8192 420.35 420.49 1.00
RTX 5090 granitemoe 3B.A800M F16 2 pp8192 622.93 622.76 1.00
RTX 5090 granitemoe 3B.A800M F16 4 pp8192 1074.35 1073.45 1.00
RTX 5090 granitemoe 3B.A800M F16 8 pp8192 1851.78 1851.94 1.00
RTX 5090 granitemoe 3B.A800M F16 16 pp8192 2952.94 2950.80 1.00
RTX 5090 granitemoe 3B.A800M F16 32 pp8192 5148.04 4505.09 0.88
RTX 5090 granitemoe 3B.A800M F16 64 pp8192 7798.65 7605.97 0.98
RTX 5090 granitemoe 3B.A800M F16 128 pp8192 10679.19 11065.87 1.04
RTX 5090 granitemoe 3B.A800M F16 256 pp8192 8304.20 8478.25 1.02
RTX 5090 granitemoe 3B.A800M F16 512 pp8192 12471.40 12771.35 1.02
RTX 5090 granitemoe 3B.A800M F16 1024 pp8192 10509.64 10545.21 1.00
RTX 5090 granitemoe 3B.A800M F16 2048 pp8192 13770.99 13589.98 0.99
RTX 5090 granitemoe 3B.A800M F16 4096 pp8192 13826.39 13781.34 1.00
RTX 5090 granitemoe 3B.A800M Q4_0 1 pp8192 566.06 566.04 1.00
RTX 5090 granitemoe 3B.A800M Q4_0 2 pp8192 1027.02 1027.23 1.00
RTX 5090 granitemoe 3B.A800M Q4_0 4 pp8192 1800.69 1800.47 1.00
RTX 5090 granitemoe 3B.A800M Q4_0 8 pp8192 3107.25 3107.16 1.00
RTX 5090 granitemoe 3B.A800M Q4_0 16 pp8192 4185.93 3945.35 0.94
RTX 5090 granitemoe 3B.A800M Q4_0 32 pp8192 6865.57 6337.57 0.92
RTX 5090 granitemoe 3B.A800M Q4_0 64 pp8192 10424.48 9967.43 0.96
RTX 5090 granitemoe 3B.A800M Q4_0 128 pp8192 13311.17 13490.83 1.01
RTX 5090 granitemoe 3B.A800M Q4_0 256 pp8192 23417.86 23822.66 1.02
RTX 5090 granitemoe 3B.A800M Q4_0 512 pp8192 32720.92 33260.11 1.02
RTX 5090 granitemoe 3B.A800M Q4_0 1024 pp8192 40404.58 39411.93 0.98
RTX 5090 granitemoe 3B.A800M Q4_0 2048 pp8192 43607.75 43131.19 0.99
RTX 5090 granitemoe 3B.A800M Q4_0 4096 pp8192 43678.85 43092.44 0.99
RX 6800 granitemoe 3B.A800M F16 1 pp8192 74.14 74.17 1.00
RX 6800 granitemoe 3B.A800M F16 2 pp8192 100.22 100.35 1.00
RX 6800 granitemoe 3B.A800M F16 4 pp8192 125.85 125.77 1.00
RX 6800 granitemoe 3B.A800M F16 8 pp8192 143.86 143.84 1.00
RX 6800 granitemoe 3B.A800M F16 16 pp8192 99.76 98.65 0.99
RX 6800 granitemoe 3B.A800M F16 32 pp8192 167.30 165.58 0.99
RX 6800 granitemoe 3B.A800M F16 64 pp8192 269.79 268.33 0.99
RX 6800 granitemoe 3B.A800M F16 128 pp8192 426.00 427.32 1.00
RX 6800 granitemoe 3B.A800M F16 256 pp8192 688.47 689.15 1.00
RX 6800 granitemoe 3B.A800M F16 512 pp8192 825.71 828.29 1.00
RX 6800 granitemoe 3B.A800M F16 1024 pp8192 1194.24 1197.00 1.00
RX 6800 granitemoe 3B.A800M F16 2048 pp8192 1505.15 1508.39 1.00
RX 6800 granitemoe 3B.A800M F16 4096 pp8192 1503.01 1506.44 1.00
RX 6800 granitemoe 3B.A800M Q4_0 1 pp8192 126.62 127.05 1.00
RX 6800 granitemoe 3B.A800M Q4_0 2 pp8192 232.00 231.16 1.00
RX 6800 granitemoe 3B.A800M Q4_0 4 pp8192 393.84 394.74 1.00
RX 6800 granitemoe 3B.A800M Q4_0 8 pp8192 579.17 579.80 1.00
RX 6800 granitemoe 3B.A800M Q4_0 16 pp8192 554.61 570.12 1.03
RX 6800 granitemoe 3B.A800M Q4_0 32 pp8192 810.99 871.87 1.08
RX 6800 granitemoe 3B.A800M Q4_0 64 pp8192 976.00 1129.35 1.16
RX 6800 granitemoe 3B.A800M Q4_0 128 pp8192 1424.97 1531.83 1.07
RX 6800 granitemoe 3B.A800M Q4_0 256 pp8192 1952.05 1957.08 1.00
RX 6800 granitemoe 3B.A800M Q4_0 512 pp8192 2197.71 2206.71 1.00
RX 6800 granitemoe 3B.A800M Q4_0 1024 pp8192 2292.05 2300.70 1.00
RX 6800 granitemoe 3B.A800M Q4_0 2048 pp8192 2459.84 2469.44 1.00
RX 6800 granitemoe 3B.A800M Q4_0 4096 pp8192 2459.85 2468.90 1.00
RX 9060 XT granitemoe 3B.A800M F16 1 pp8192 78.96 79.03 1.00
RX 9060 XT granitemoe 3B.A800M F16 2 pp8192 114.57 114.21 1.00
RX 9060 XT granitemoe 3B.A800M F16 4 pp8192 150.82 150.18 1.00
RX 9060 XT granitemoe 3B.A800M F16 8 pp8192 180.33 179.28 0.99
RX 9060 XT granitemoe 3B.A800M F16 16 pp8192 532.54 531.65 1.00
RX 9060 XT granitemoe 3B.A800M F16 32 pp8192 892.42 727.82 0.82
RX 9060 XT granitemoe 3B.A800M F16 64 pp8192 1154.69 1028.58 0.89
RX 9060 XT granitemoe 3B.A800M F16 128 pp8192 1779.33 1704.46 0.96
RX 9060 XT granitemoe 3B.A800M F16 256 pp8192 1939.24 1966.84 1.01
RX 9060 XT granitemoe 3B.A800M F16 512 pp8192 2278.26 2404.94 1.06
RX 9060 XT granitemoe 3B.A800M F16 1024 pp8192 1844.25 1830.83 0.99
RX 9060 XT granitemoe 3B.A800M F16 2048 pp8192 2011.49 2007.68 1.00
RX 9060 XT granitemoe 3B.A800M F16 4096 pp8192 2026.64 1989.81 0.98
RX 9060 XT granitemoe 3B.A800M Q4_0 1 pp8192 130.29 130.07 1.00
RX 9060 XT granitemoe 3B.A800M Q4_0 2 pp8192 273.24 272.85 1.00
RX 9060 XT granitemoe 3B.A800M Q4_0 4 pp8192 482.45 482.35 1.00
RX 9060 XT granitemoe 3B.A800M Q4_0 8 pp8192 678.99 677.03 1.00
RX 9060 XT granitemoe 3B.A800M Q4_0 16 pp8192 948.71 943.33 0.99
RX 9060 XT granitemoe 3B.A800M Q4_0 32 pp8192 1839.40 1824.24 0.99
RX 9060 XT granitemoe 3B.A800M Q4_0 64 pp8192 2257.18 2282.81 1.01
RX 9060 XT granitemoe 3B.A800M Q4_0 128 pp8192 3579.88 3614.19 1.01
RX 9060 XT granitemoe 3B.A800M Q4_0 256 pp8192 5124.57 5110.67 1.00
RX 9060 XT granitemoe 3B.A800M Q4_0 512 pp8192 5949.61 5897.05 0.99
RX 9060 XT granitemoe 3B.A800M Q4_0 1024 pp8192 6399.83 6397.71 1.00
RX 9060 XT granitemoe 3B.A800M Q4_0 2048 pp8192 6530.89 6547.10 1.00
RX 9060 XT granitemoe 3B.A800M Q4_0 4096 pp8192 6534.38 6545.96 1.00
Strix Halo granitemoe 3B.A800M F16 1 pp8192 57.10 57.03 1.00
Strix Halo granitemoe 3B.A800M F16 2 pp8192 79.21 78.78 0.99
Strix Halo granitemoe 3B.A800M F16 4 pp8192 106.70 105.92 0.99
Strix Halo granitemoe 3B.A800M F16 8 pp8192 126.89 125.75 0.99
Strix Halo granitemoe 3B.A800M F16 16 pp8192 391.97 391.69 1.00
Strix Halo granitemoe 3B.A800M F16 32 pp8192 629.62 509.88 0.81
Strix Halo granitemoe 3B.A800M F16 64 pp8192 959.04 834.12 0.87
Strix Halo granitemoe 3B.A800M F16 128 pp8192 1363.72 1281.25 0.94
Strix Halo granitemoe 3B.A800M F16 256 pp8192 1507.09 1534.68 1.02
Strix Halo granitemoe 3B.A800M F16 512 pp8192 1885.23 2033.41 1.08
Strix Halo granitemoe 3B.A800M F16 1024 pp8192 2059.09 2064.74 1.00
Strix Halo granitemoe 3B.A800M F16 2048 pp8192 2424.17 2413.19 1.00
Strix Halo granitemoe 3B.A800M F16 4096 pp8192 2420.23 2430.79 1.00
Strix Halo granitemoe 3B.A800M Q4_0 1 pp8192 91.39 91.37 1.00
Strix Halo granitemoe 3B.A800M Q4_0 2 pp8192 168.64 169.30 1.00
Strix Halo granitemoe 3B.A800M Q4_0 4 pp8192 285.73 286.39 1.00
Strix Halo granitemoe 3B.A800M Q4_0 8 pp8192 420.90 422.33 1.00
Strix Halo granitemoe 3B.A800M Q4_0 16 pp8192 708.03 705.91 1.00
Strix Halo granitemoe 3B.A800M Q4_0 32 pp8192 1079.85 1082.12 1.00
Strix Halo granitemoe 3B.A800M Q4_0 64 pp8192 1653.95 1676.08 1.01
Strix Halo granitemoe 3B.A800M Q4_0 128 pp8192 1995.42 1981.90 0.99
Strix Halo granitemoe 3B.A800M Q4_0 256 pp8192 3117.32 3113.71 1.00
Strix Halo granitemoe 3B.A800M Q4_0 512 pp8192 3427.32 3404.58 0.99
Strix Halo granitemoe 3B.A800M Q4_0 1024 pp8192 3714.63 3732.50 1.00
Strix Halo granitemoe 3B.A800M Q4_0 2048 pp8192 3801.90 3849.72 1.01
Strix Halo granitemoe 3B.A800M Q4_0 4096 pp8192 3801.66 3856.28 1.01
V100-PCIE-32GB granitemoe 3B.A800M F16 1 pp8192 173.28 173.26 1.00
V100-PCIE-32GB granitemoe 3B.A800M F16 2 pp8192 280.48 280.48 1.00
V100-PCIE-32GB granitemoe 3B.A800M F16 4 pp8192 505.69 505.60 1.00
V100-PCIE-32GB granitemoe 3B.A800M F16 8 pp8192 815.37 815.03 1.00
V100-PCIE-32GB granitemoe 3B.A800M F16 16 pp8192 1224.61 1224.34 1.00
V100-PCIE-32GB granitemoe 3B.A800M F16 32 pp8192 1750.13 1623.70 0.93
V100-PCIE-32GB granitemoe 3B.A800M F16 64 pp8192 2505.75 2422.90 0.97
V100-PCIE-32GB granitemoe 3B.A800M F16 128 pp8192 3269.45 3292.93 1.01
V100-PCIE-32GB granitemoe 3B.A800M F16 256 pp8192 3633.29 3704.23 1.02
V100-PCIE-32GB granitemoe 3B.A800M F16 512 pp8192 4354.16 4533.91 1.04
V100-PCIE-32GB granitemoe 3B.A800M F16 1024 pp8192 4307.95 4298.78 1.00
V100-PCIE-32GB granitemoe 3B.A800M F16 2048 pp8192 5006.68 4993.08 1.00
V100-PCIE-32GB granitemoe 3B.A800M F16 4096 pp8192 5008.94 5008.59 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 1 pp8192 231.99 232.06 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 2 pp8192 392.29 393.45 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 4 pp8192 699.80 700.01 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 8 pp8192 1026.37 1027.15 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 16 pp8192 1285.64 1356.63 1.06
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 32 pp8192 1879.68 1956.70 1.04
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 64 pp8192 993.39 993.42 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 128 pp8192 1497.21 1499.55 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 256 pp8192 2175.23 2185.01 1.00
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 512 pp8192 2875.32 2902.83 1.01
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 1024 pp8192 3658.41 3712.94 1.01
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 2048 pp8192 4449.60 4525.71 1.02
V100-PCIE-32GB granitemoe 3B.A800M Q4_0 4096 pp8192 4445.87 4524.16 1.02
Performance mid-sized MoE

Table generated with scripts/compare-llama-bench.py

GPU Model Microbatch size Test t/s master t/s bea596f Speedup
MI60 / MI50 gemma4 26B.A4B Q4_0 1 pp8192 105.84 106.27 1.00
MI60 / MI50 gemma4 26B.A4B Q4_0 2 pp8192 177.40 178.03 1.00
MI60 / MI50 gemma4 26B.A4B Q4_0 4 pp8192 233.59 234.47 1.00
MI60 / MI50 gemma4 26B.A4B Q4_0 8 pp8192 305.02 304.55 1.00
MI60 / MI50 gemma4 26B.A4B Q4_0 16 pp8192 382.15 384.63 1.01
MI60 / MI50 gemma4 26B.A4B Q4_0 32 pp8192 448.11 529.37 1.18
MI60 / MI50 gemma4 26B.A4B Q4_0 64 pp8192 453.58 649.18 1.43
MI60 / MI50 gemma4 26B.A4B Q4_0 128 pp8192 654.68 862.01 1.32
MI60 / MI50 gemma4 26B.A4B Q4_0 256 pp8192 922.57 1169.79 1.27
MI60 / MI50 gemma4 26B.A4B Q4_0 512 pp8192 1146.99 1295.78 1.13
MI60 / MI50 gemma4 26B.A4B Q4_0 1024 pp8192 1311.30 1335.93 1.02
MI60 / MI50 gemma4 26B.A4B Q4_0 2048 pp8192 1312.45 1334.35 1.02
MI60 / MI50 gemma4 26B.A4B Q4_0 4096 pp8192 1311.72 1335.88 1.02
MI100 gemma4 26B.A4B Q4_0 1 pp8192 113.87 116.43 1.02
MI100 gemma4 26B.A4B Q4_0 2 pp8192 190.12 191.43 1.01
MI100 gemma4 26B.A4B Q4_0 4 pp8192 201.14 202.64 1.01
MI100 gemma4 26B.A4B Q4_0 8 pp8192 271.97 271.09 1.00
MI100 gemma4 26B.A4B Q4_0 16 pp8192 445.14 400.39 0.90
MI100 gemma4 26B.A4B Q4_0 32 pp8192 683.16 646.11 0.95
MI100 gemma4 26B.A4B Q4_0 64 pp8192 765.78 962.42 1.26
MI100 gemma4 26B.A4B Q4_0 128 pp8192 1138.81 1413.16 1.24
MI100 gemma4 26B.A4B Q4_0 256 pp8192 1616.64 1968.83 1.22
MI100 gemma4 26B.A4B Q4_0 512 pp8192 2000.83 2502.16 1.25
MI100 gemma4 26B.A4B Q4_0 1024 pp8192 2222.72 2575.79 1.16
MI100 gemma4 26B.A4B Q4_0 2048 pp8192 2397.11 2930.21 1.22
MI100 gemma4 26B.A4B Q4_0 4096 pp8192 2405.10 2927.35 1.22
P40 gemma4 26B.A4B Q4_0 1 pp8192 71.36 71.35 1.00
P40 gemma4 26B.A4B Q4_0 2 pp8192 124.16 124.14 1.00
P40 gemma4 26B.A4B Q4_0 4 pp8192 173.39 173.46 1.00
P40 gemma4 26B.A4B Q4_0 8 pp8192 248.70 245.13 0.99
P40 gemma4 26B.A4B Q4_0 16 pp8192 328.42 352.79 1.07
P40 gemma4 26B.A4B Q4_0 32 pp8192 370.75 477.08 1.29
P40 gemma4 26B.A4B Q4_0 64 pp8192 428.34 600.66 1.40
P40 gemma4 26B.A4B Q4_0 128 pp8192 563.83 687.15 1.22
P40 gemma4 26B.A4B Q4_0 256 pp8192 720.42 800.51 1.11
P40 gemma4 26B.A4B Q4_0 512 pp8192 823.42 853.47 1.04
P40 gemma4 26B.A4B Q4_0 1024 pp8192 919.36 929.12 1.01
P40 gemma4 26B.A4B Q4_0 2048 pp8192 918.48 939.79 1.02
P40 gemma4 26B.A4B Q4_0 4096 pp8192 921.54 946.81 1.03
RTX 3090 gemma4 26B.A4B Q4_0 1 pp8192 173.84 176.33 1.01
RTX 3090 gemma4 26B.A4B Q4_0 2 pp8192 306.92 307.82 1.00
RTX 3090 gemma4 26B.A4B Q4_0 4 pp8192 414.51 410.70 0.99
RTX 3090 gemma4 26B.A4B Q4_0 8 pp8192 497.24 485.01 0.98
RTX 3090 gemma4 26B.A4B Q4_0 16 pp8192 953.91 975.60 1.02
RTX 3090 gemma4 26B.A4B Q4_0 32 pp8192 1280.14 1444.16 1.13
RTX 3090 gemma4 26B.A4B Q4_0 64 pp8192 1611.88 1950.45 1.21
RTX 3090 gemma4 26B.A4B Q4_0 128 pp8192 1694.53 2347.33 1.39
RTX 3090 gemma4 26B.A4B Q4_0 256 pp8192 2502.55 3203.28 1.28
RTX 3090 gemma4 26B.A4B Q4_0 512 pp8192 3447.13 3975.99 1.15
RTX 3090 gemma4 26B.A4B Q4_0 1024 pp8192 4212.04 4628.98 1.10
RTX 3090 gemma4 26B.A4B Q4_0 2048 pp8192 4596.75 4760.57 1.04
RTX 3090 gemma4 26B.A4B Q4_0 4096 pp8192 4680.22 4885.39 1.04
RTX 4090 gemma4 26B.A4B Q4_0 1 pp8192 236.98 237.19 1.00
RTX 4090 gemma4 26B.A4B Q4_0 2 pp8192 414.69 414.79 1.00
RTX 4090 gemma4 26B.A4B Q4_0 4 pp8192 682.60 683.04 1.00
RTX 4090 gemma4 26B.A4B Q4_0 8 pp8192 1098.66 1099.31 1.00
RTX 4090 gemma4 26B.A4B Q4_0 16 pp8192 1556.49 1560.11 1.00
RTX 4090 gemma4 26B.A4B Q4_0 32 pp8192 2471.48 2515.17 1.02
RTX 4090 gemma4 26B.A4B Q4_0 64 pp8192 3785.17 3906.79 1.03
RTX 4090 gemma4 26B.A4B Q4_0 128 pp8192 4628.30 5421.68 1.17
RTX 4090 gemma4 26B.A4B Q4_0 256 pp8192 7654.02 8996.73 1.18
RTX 4090 gemma4 26B.A4B Q4_0 512 pp8192 10728.30 12131.91 1.13
RTX 4090 gemma4 26B.A4B Q4_0 1024 pp8192 12982.87 14186.25 1.09
RTX 4090 gemma4 26B.A4B Q4_0 2048 pp8192 13551.67 14389.62 1.06
RTX 4090 gemma4 26B.A4B Q4_0 4096 pp8192 13545.09 14379.03 1.06
RTX 5090 gemma4 26B.A4B Q4_0 1 pp8192 334.05 334.25 1.00
RTX 5090 gemma4 26B.A4B Q4_0 2 pp8192 580.65 580.93 1.00
RTX 5090 gemma4 26B.A4B Q4_0 4 pp8192 954.97 955.29 1.00
RTX 5090 gemma4 26B.A4B Q4_0 8 pp8192 1461.09 1461.36 1.00
RTX 5090 gemma4 26B.A4B Q4_0 16 pp8192 2016.98 2012.48 1.00
RTX 5090 gemma4 26B.A4B Q4_0 32 pp8192 3202.95 3259.99 1.02
RTX 5090 gemma4 26B.A4B Q4_0 64 pp8192 4690.15 4870.64 1.04
RTX 5090 gemma4 26B.A4B Q4_0 128 pp8192 5544.64 6311.30 1.14
RTX 5090 gemma4 26B.A4B Q4_0 256 pp8192 9473.86 11079.74 1.17
RTX 5090 gemma4 26B.A4B Q4_0 512 pp8192 13215.72 14903.69 1.13
RTX 5090 gemma4 26B.A4B Q4_0 1024 pp8192 16214.86 18093.72 1.12
RTX 5090 gemma4 26B.A4B Q4_0 2048 pp8192 17422.32 18727.29 1.07
RTX 5090 gemma4 26B.A4B Q4_0 4096 pp8192 17402.29 18684.08 1.07
RX 6800 gemma4 26B.A4B Q4_0 1 pp8192 75.13 75.14 1.00
RX 6800 gemma4 26B.A4B Q4_0 2 pp8192 136.91 136.93 1.00
RX 6800 gemma4 26B.A4B Q4_0 4 pp8192 210.76 210.90 1.00
RX 6800 gemma4 26B.A4B Q4_0 8 pp8192 284.82 284.84 1.00
RX 6800 gemma4 26B.A4B Q4_0 16 pp8192 288.07 306.58 1.06
RX 6800 gemma4 26B.A4B Q4_0 32 pp8192 363.77 447.23 1.23
RX 6800 gemma4 26B.A4B Q4_0 64 pp8192 408.49 601.58 1.47
RX 6800 gemma4 26B.A4B Q4_0 128 pp8192 584.44 753.16 1.29
RX 6800 gemma4 26B.A4B Q4_0 256 pp8192 831.58 994.06 1.20
RX 6800 gemma4 26B.A4B Q4_0 512 pp8192 1047.83 1146.26 1.09
RX 6800 gemma4 26B.A4B Q4_0 1024 pp8192 1187.38 1198.36 1.01
RX 9060 XT gemma4 26B.A4B Q4_0 1 pp8192 70.38 70.49 1.00
RX 9060 XT gemma4 26B.A4B Q4_0 2 pp8192 119.65 119.77 1.00
RX 9060 XT gemma4 26B.A4B Q4_0 4 pp8192 183.61 183.57 1.00
RX 9060 XT gemma4 26B.A4B Q4_0 8 pp8192 268.70 267.22 0.99
RX 9060 XT gemma4 26B.A4B Q4_0 16 pp8192 425.86 423.85 1.00
RX 9060 XT gemma4 26B.A4B Q4_0 32 pp8192 592.38 597.42 1.01
RX 9060 XT gemma4 26B.A4B Q4_0 64 pp8192 920.30 936.63 1.02
RX 9060 XT gemma4 26B.A4B Q4_0 128 pp8192 1262.04 1296.76 1.03
RX 9060 XT gemma4 26B.A4B Q4_0 256 pp8192 1698.68 1769.28 1.04
RX 9060 XT gemma4 26B.A4B Q4_0 512 pp8192 2108.68 2187.33 1.04
RX 9060 XT gemma4 26B.A4B Q4_0 1024 pp8192 2364.09 2442.25 1.03
Strix Halo gemma4 26B.A4B Q4_0 1 pp8192 47.08 47.14 1.00
Strix Halo gemma4 26B.A4B Q4_0 2 pp8192 85.52 85.64 1.00
Strix Halo gemma4 26B.A4B Q4_0 4 pp8192 138.21 138.20 1.00
Strix Halo gemma4 26B.A4B Q4_0 8 pp8192 203.35 203.00 1.00
Strix Halo gemma4 26B.A4B Q4_0 16 pp8192 305.74 304.27 1.00
Strix Halo gemma4 26B.A4B Q4_0 32 pp8192 425.41 428.59 1.01
Strix Halo gemma4 26B.A4B Q4_0 64 pp8192 631.28 647.92 1.03
Strix Halo gemma4 26B.A4B Q4_0 128 pp8192 837.72 870.88 1.04
Strix Halo gemma4 26B.A4B Q4_0 256 pp8192 1043.51 1085.88 1.04
Strix Halo gemma4 26B.A4B Q4_0 512 pp8192 1065.47 1092.23 1.03
Strix Halo gemma4 26B.A4B Q4_0 1024 pp8192 1332.65 1350.83 1.01
Strix Halo gemma4 26B.A4B Q4_0 2048 pp8192 1341.83 1352.81 1.01
Strix Halo gemma4 26B.A4B Q4_0 4096 pp8192 1344.60 1354.01 1.01
V100-PCIE-32GB gemma4 26B.A4B Q4_0 1 pp8192 124.01 124.01 1.00
V100-PCIE-32GB gemma4 26B.A4B Q4_0 2 pp8192 225.54 225.59 1.00
V100-PCIE-32GB gemma4 26B.A4B Q4_0 4 pp8192 346.52 346.41 1.00
V100-PCIE-32GB gemma4 26B.A4B Q4_0 8 pp8192 452.70 461.22 1.02
V100-PCIE-32GB gemma4 26B.A4B Q4_0 16 pp8192 609.07 636.30 1.04
V100-PCIE-32GB gemma4 26B.A4B Q4_0 32 pp8192 811.59 930.75 1.15
V100-PCIE-32GB gemma4 26B.A4B Q4_0 64 pp8192 625.76 625.11 1.00
V100-PCIE-32GB gemma4 26B.A4B Q4_0 128 pp8192 877.18 878.15 1.00
V100-PCIE-32GB gemma4 26B.A4B Q4_0 256 pp8192 1216.73 1222.87 1.01
V100-PCIE-32GB gemma4 26B.A4B Q4_0 512 pp8192 1562.38 1576.86 1.01
V100-PCIE-32GB gemma4 26B.A4B Q4_0 1024 pp8192 1864.54 1861.25 1.00
V100-PCIE-32GB gemma4 26B.A4B Q4_0 2048 pp8192 2120.88 2104.03 0.99
V100-PCIE-32GB gemma4 26B.A4B Q4_0 4096 pp8192 2117.45 2100.71 0.99
Performance check dense

Table generated with scripts/compare-llama-bench.py

GPU Model Microbatch size Test t/s master t/s bea596f Speedup
MI60 / MI50 llama 8B Q4_0 1 pp1024 109.49 109.77 1.00
MI60 / MI50 llama 8B Q4_0 2 pp1024 185.97 184.83 0.99
MI60 / MI50 llama 8B Q4_0 4 pp1024 249.77 249.74 1.00
MI60 / MI50 llama 8B Q4_0 8 pp1024 314.74 316.56 1.01
MI60 / MI50 llama 8B Q4_0 16 pp1024 451.89 453.60 1.00
MI60 / MI50 llama 8B Q4_0 32 pp1024 603.47 604.27 1.00
MI60 / MI50 llama 8B Q4_0 64 pp1024 670.15 672.21 1.00
MI60 / MI50 llama 8B Q4_0 128 pp1024 910.35 912.63 1.00
MI60 / MI50 llama 8B Q4_0 256 pp1024 1045.71 1048.43 1.00
MI60 / MI50 llama 8B Q4_0 512 pp1024 1117.51 1117.92 1.00
MI100 llama 8B Q4_0 1 pp1024 146.95 145.31 0.99
MI100 llama 8B Q4_0 2 pp1024 230.41 229.44 1.00
MI100 llama 8B Q4_0 4 pp1024 316.23 314.62 0.99
MI100 llama 8B Q4_0 8 pp1024 531.92 528.76 0.99
MI100 llama 8B Q4_0 16 pp1024 996.09 986.58 0.99
MI100 llama 8B Q4_0 32 pp1024 1484.81 1486.38 1.00
MI100 llama 8B Q4_0 64 pp1024 1802.86 1803.48 1.00
MI100 llama 8B Q4_0 128 pp1024 2139.47 2134.78 1.00
MI100 llama 8B Q4_0 256 pp1024 2344.82 2337.50 1.00
MI100 llama 8B Q4_0 512 pp1024 2412.51 2403.34 1.00
P40 llama 8B Q4_0 1 pp1024 59.32 59.39 1.00
P40 llama 8B Q4_0 2 pp1024 114.39 114.42 1.00
P40 llama 8B Q4_0 4 pp1024 191.15 191.26 1.00
P40 llama 8B Q4_0 8 pp1024 226.26 226.31 1.00
P40 llama 8B Q4_0 16 pp1024 472.38 473.01 1.00
P40 llama 8B Q4_0 32 pp1024 583.95 582.91 1.00
P40 llama 8B Q4_0 64 pp1024 775.45 771.05 0.99
P40 llama 8B Q4_0 128 pp1024 895.04 892.35 1.00
P40 llama 8B Q4_0 256 pp1024 982.20 976.06 0.99
P40 llama 8B Q4_0 512 pp1024 1021.30 1014.67 0.99
RTX 3090 llama 8B Q4_0 1 pp1024 168.89 169.41 1.00
RTX 3090 llama 8B Q4_0 2 pp1024 316.27 317.41 1.00
RTX 3090 llama 8B Q4_0 4 pp1024 464.48 471.19 1.01
RTX 3090 llama 8B Q4_0 8 pp1024 591.62 600.06 1.01
RTX 3090 llama 8B Q4_0 16 pp1024 1408.75 1417.60 1.01
RTX 3090 llama 8B Q4_0 32 pp1024 2196.90 2197.75 1.00
RTX 3090 llama 8B Q4_0 64 pp1024 3165.64 3229.87 1.02
RTX 3090 llama 8B Q4_0 128 pp1024 3781.70 3813.88 1.01
RTX 3090 llama 8B Q4_0 256 pp1024 4471.19 4422.33 0.99
RTX 3090 llama 8B Q4_0 512 pp1024 4412.97 4542.32 1.03
RTX 4090 llama 8B Q4_0 1 pp1024 197.47 197.40 1.00
RTX 4090 llama 8B Q4_0 2 pp1024 375.22 375.31 1.00
RTX 4090 llama 8B Q4_0 4 pp1024 733.28 735.18 1.00
RTX 4090 llama 8B Q4_0 8 pp1024 1366.54 1364.29 1.00
RTX 4090 llama 8B Q4_0 16 pp1024 2198.97 2189.79 1.00
RTX 4090 llama 8B Q4_0 32 pp1024 3868.52 3863.07 1.00
RTX 4090 llama 8B Q4_0 64 pp1024 6484.89 6477.98 1.00
RTX 4090 llama 8B Q4_0 128 pp1024 8642.42 8635.14 1.00
RTX 4090 llama 8B Q4_0 256 pp1024 11181.45 11354.76 1.02
RTX 4090 llama 8B Q4_0 512 pp1024 12316.68 12412.69 1.01
RTX 5090 llama 8B Q4_0 1 pp1024 316.93 316.95 1.00
RTX 5090 llama 8B Q4_0 2 pp1024 590.16 590.40 1.00
RTX 5090 llama 8B Q4_0 4 pp1024 1135.99 1136.15 1.00
RTX 5090 llama 8B Q4_0 8 pp1024 1833.15 1835.33 1.00
RTX 5090 llama 8B Q4_0 16 pp1024 3003.64 2997.91 1.00
RTX 5090 llama 8B Q4_0 32 pp1024 5106.48 5107.78 1.00
RTX 5090 llama 8B Q4_0 64 pp1024 7710.82 7711.88 1.00
RTX 5090 llama 8B Q4_0 128 pp1024 9713.91 9739.10 1.00
RTX 5090 llama 8B Q4_0 256 pp1024 12896.82 12928.64 1.00
RTX 5090 llama 8B Q4_0 512 pp1024 14658.18 14717.13 1.00
RX 6800 llama 8B Q4_0 1 pp1024 80.64 80.67 1.00
RX 6800 llama 8B Q4_0 2 pp1024 143.42 143.50 1.00
RX 6800 llama 8B Q4_0 4 pp1024 199.30 199.37 1.00
RX 6800 llama 8B Q4_0 8 pp1024 225.86 225.91 1.00
RX 6800 llama 8B Q4_0 16 pp1024 324.77 324.73 1.00
RX 6800 llama 8B Q4_0 32 pp1024 461.68 462.09 1.00
RX 6800 llama 8B Q4_0 64 pp1024 586.81 586.82 1.00
RX 6800 llama 8B Q4_0 128 pp1024 744.53 744.84 1.00
RX 6800 llama 8B Q4_0 256 pp1024 878.49 878.45 1.00
RX 6800 llama 8B Q4_0 512 pp1024 936.00 935.91 1.00
RX 9060 XT llama 8B Q4_0 1 pp1024 67.85 67.85 1.00
RX 9060 XT llama 8B Q4_0 2 pp1024 100.06 99.97 1.00
RX 9060 XT llama 8B Q4_0 4 pp1024 180.63 180.48 1.00
RX 9060 XT llama 8B Q4_0 8 pp1024 197.74 197.70 1.00
RX 9060 XT llama 8B Q4_0 16 pp1024 668.53 667.42 1.00
RX 9060 XT llama 8B Q4_0 32 pp1024 997.53 994.85 1.00
RX 9060 XT llama 8B Q4_0 64 pp1024 1662.05 1650.61 0.99
RX 9060 XT llama 8B Q4_0 128 pp1024 2330.71 2303.77 0.99
RX 9060 XT llama 8B Q4_0 256 pp1024 2613.22 2603.78 1.00
RX 9060 XT llama 8B Q4_0 512 pp1024 2629.19 2620.40 1.00
Strix Halo llama 8B Q4_0 1 pp1024 43.67 43.62 1.00
Strix Halo llama 8B Q4_0 2 pp1024 82.52 82.81 1.00
Strix Halo llama 8B Q4_0 4 pp1024 148.60 148.91 1.00
Strix Halo llama 8B Q4_0 8 pp1024 227.22 229.78 1.01
Strix Halo llama 8B Q4_0 16 pp1024 456.42 459.94 1.01
Strix Halo llama 8B Q4_0 32 pp1024 504.28 510.01 1.01
Strix Halo llama 8B Q4_0 64 pp1024 948.42 965.39 1.02
Strix Halo llama 8B Q4_0 128 pp1024 1057.07 1074.88 1.02
Strix Halo llama 8B Q4_0 256 pp1024 1198.78 1230.19 1.03
Strix Halo llama 8B Q4_0 512 pp1024 1199.99 1228.24 1.02
V100-PCIE-32GB llama 8B Q4_0 1 pp1024 136.79 136.78 1.00
V100-PCIE-32GB llama 8B Q4_0 2 pp1024 262.73 262.76 1.00
V100-PCIE-32GB llama 8B Q4_0 4 pp1024 448.84 449.03 1.00
V100-PCIE-32GB llama 8B Q4_0 8 pp1024 613.23 613.16 1.00
V100-PCIE-32GB llama 8B Q4_0 16 pp1024 803.00 809.14 1.01
V100-PCIE-32GB llama 8B Q4_0 32 pp1024 1166.42 1166.03 1.00
V100-PCIE-32GB llama 8B Q4_0 64 pp1024 629.72 629.87 1.00
V100-PCIE-32GB llama 8B Q4_0 128 pp1024 1093.97 1092.43 1.00
V100-PCIE-32GB llama 8B Q4_0 256 pp1024 1995.09 1996.79 1.00
V100-PCIE-32GB llama 8B Q4_0 512 pp1024 2905.41 2911.60 1.00

Requirements

@JohannesGaessler
JohannesGaessler requested a review from a team as a code owner October 23, 2026 15:41
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Oct 23, 2026
francisab added a commit to francisab/llama.cpp that referenced this pull request Oct 23, 2026
…screens

Assisted-by: GitHub Copilot

Co-authored-by: Copilot App <[email protected]>
francisab added a commit to francisab/llama.cpp that referenced this pull request Oct 24, 2026
…screens

Assisted-by: GitHub Copilot

Co-authored-by: Copilot App <[email protected]>
@am17an

am17an commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

For the F16 slow-down:

diff --git a/ggml/src/ggml-cuda/mmf.cuh b/ggml/src/ggml-cuda/mmf.cuh
index bc3931481..c49f6c47a 100644
--- a/ggml/src/ggml-cuda/mmf.cuh
+++ b/ggml/src/ggml-cuda/mmf.cuh
@@ -361,6 +361,10 @@ static __global__ void mul_mat_f_ids(
     const int expert_end   = ts.col_high;
     const int ncols_expert = expert_end - expert_start;
 
+    if (ncols_expert == 0) {
+        return;
+    }
+
     GGML_UNUSED(channel_ratio);
 
     const int channel_x   = expert_idx;

The rest LGTM

@IMbackK IMbackK self-assigned this Oct 25, 2026
@IMbackK

IMbackK commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

I think this is good, but it needs to be rebased and has significant conflicts.

francisab added a commit to francisab/llama.cpp that referenced this pull request Oct 28, 2026
…ash-Next and 27B

Assisted-by: GitHub Copilot

Co-authored-by: Copilot App <[email protected]>
@francisab

Copy link
Copy Markdown

I found this PR while doing research and deployed and tested.

Qwen3.8-Flash-Next (512 experts) - Have ~6.1 gain on prompt processing (2,048 tokens).

francisab added a commit to francisab/llama.cpp that referenced this pull request Oct 28, 2026
Assisted-by: GitHub Copilot

Co-authored-by: Copilot App <[email protected]>
@JohannesGaessler

Copy link
Copy Markdown
Contributor Author

I pushed a rebased version with the conflicts resolved, please re-review.

@JohannesGaessler

Copy link
Copy Markdown
Contributor Author

I forgot: I also applied the patch suggested by @am17an .

@JohannesGaessler JohannesGaessler added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Nov 5, 2026
@ggerganov
ggerganov merged commit 69ee2ec into ggml-org:master Nov 5, 2026
18 of 19 checks passed
@ggerganov

ggerganov commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Ran a few queries on my RTX 5090 machine - haven't spotted any problems and the PP perf is slightly better.

adderek pushed a commit to adderek/llama.cpp that referenced this pull request Nov 5, 2026
350 upstream commits. Conflicts and how they were resolved:

- ggml type ids: upstream numbers GGML_TYPE_F8_E4M3 43, which the fork's
  TURBO3_0 already holds (TURBO2/3/4 and TQ3_1S/TQ4_1S are 43-47). The
  fork keeps its ids so existing TQ*_1S GGUFs still load; F8_E4M3 is 48,
  GGML_TYPE_COUNT 49, and gguf-py's GGMLQuantizationType.F8_E4M3 matches.
  An upstream-written FP8 GGUF would therefore read its type-43 tensors as
  turbo3; the model loader now refuses any weight of a turbo KV type with
  a message naming the cause. LLAMA_FTYPE_MOSTLY_F8_E4M3 (42) does not
  collide.
- MUL_MAT_ID: upstream lets id -1 skip a slot on CPU (ggml-org#26631, CUDA left
  out). The CPU and repack paths take both: -1 always, and any id < 0 for
  the fork's partial mul_mat_id (MoE tiering).
- CUDA MoE layout: upstream replaced expert_bounds with tile_spec (ggml-org#31047).
  The fork's partial mul_mat_id skips rows, so the compact column range is
  shorter and the seam tiles past its end are never written; mmq.cu and
  mmf.cu zero tile_spec for partial calls (a zero tile has col_low ==
  col_high and the kernels skip it). The forward/inverse id map memsets
  are kept.
- CUDA graphs: upstream captures in chunks and launches each chunk as soon
  as it is captured (ggml-org#30804). The fork's out-of-memory fallback moves into
  ggml_cuda_graph_launch_chunk: an OOM instantiation returns false without
  launching, the graph is marked disable_due_to_oom, its executables are
  destroyed, the capture lock released, and evaluation restarts directly
  from the first node of the failed chunk (the chunks before it have run).
  Checked by faking the OOM at a mid-graph chunk and at the last one:
  greedy output identical to graphs on and off, warning printed once.
- mmq: IQ1_M stays off MMQ on RDNA3 (fork); its tile loader gains
  upstream's x_gate parameter and its write-back the has_fusion flag.
- fattn-mma-f16: upstream's AMD_WMMA_256B_AVAILABLE guard with the fork's
  VKQ_C sizing.
- llama-graph: TurboQuant Q pre-rotation kept on every attention path,
  with upstream's kv_rows argument and per-layer self_v_rot. Sparse MLA
  takes upstream's n_embd_v (v_cur may be null) for the V view and for the
  padded-head trim. build_lora_mm_id: partial assert, then upstream's
  cur_mm (Hadamard input for the folded weight, raw cur for LoRA).
- kv-cache: buffers go through upstream's llama_memory_bufs::emplace,
  which clears them; the TurboQuant rotation matrices are filled after it,
  gated on the cache's own no_alloc (hparams.no_alloc is gone).
- hybrid-idx: no-turbo indexer types with upstream's no_alloc and without
  the removed n_pad.
- qwen4exp: turbo Q pre-rotation before upstream's per-stream selection.
- server: keep_heap_mapped() moved into upstream's refactored
  llama_server(); the prompt-cache retire list uses common_state_data.
- tests/CMakeLists.txt: upstream moved the model tests out of the
  non-Windows-shared block; the fork's moe-tier and turbo-kv tests stay
  guarded by it. test-moe-tier writes its keys with llama_arch_kv_name
  since llama_model_saver lost its (arch, gguf) constructor.
- test-backend-ops: fork's partial mul_mat_id cases and upstream's small-K
  cases both kept; turbo3/turbo4 added to the new kv_rows FA cases.

kv_rows FlashAttention is NVIDIA-only upstream; on ROCm the context probe
falls back to the dense mask, so the turbo kv_rows cases report "not
supported" there, as the f16 ones do.

Tested on gfx1100: ctest 83/87, the four failures environmental (ggml-vocabs
git-lfs pointers; system python lacks jinja2 and numpy - test_conversion_fp8
passes 15/15 under uv). test-backend-ops MUL_MAT_ID 931/931, MUL_MAT
2517/2517, FLASH_ATTN_EXT 4040/4040. llama-bench turbo4 KV vs master,
pp512/tg128: Ornith-1.5-9B 3114/99.0 vs 3044/99.9, Qwen3.6-35B-A3B
3794/98.1 vs 3477/97.1 (pp noise +-160-390).
Kmic-68 pushed a commit to Kmic-68/llama.cpp that referenced this pull request Nov 7, 2026
…06) into the P100 fork

Conflicts and what was kept:
- KQ mask: upstream's llm_attn_mask / kv_rows refactor (ggml-org#29510). Our compact I32 causal mask is handled in
  llama_kv_cache_context::set_input_attn_mask; the single-sequence fast mask fill only runs when the mask
  columns are the cells (no kv_rows). kv_rows attention is MMA-only, so on sm_60 the probe reports it
  unsupported and the dense/compact mask path is used as before.
- MoE layout: took upstream's linearized MMQ/MMF MoE data layout (ggml-org#31047) in mmid.cu, mmf.cuh, mmq.cuh. It
  replaces our repeated-expert-id handling there (63924ad); upstream keeps those test cases disabled and
  top-k routers never repeat an expert. The cuBLAS sort path keeps its fix. The opt-in fp16 MoE GEMM
  (GGML_CUDA_P60_MOE_GEMM=1) now builds its jobs from the helper's tile list; the math is unchanged.
- mmq.cu: upstream applies the tokens-per-expert tile sizing to every arch (ours did it on sm_60 only).
- scale.cu: upstream's strided rewrite plus our scale == 0 -> bias rule.
- common_state_data (upstream) is an alias of our common_ckpt_buffer, so state buffers keep the pooled,
  huge-page, no-zero-fill allocator. Checkpoints are ref-counted upstream now (ggml-org#30137): our
  keep-the-just-restored-checkpoint path claims it through the const pointer, except a slot-file one.
- MTP: upstream's mem-shared (gemma4) verify rows merged with our verify_pos0/pending_pos bookkeeping;
  upstream's own MTP get_state/set_state dropped in favour of ours (position + row, resets stale state).
- fattn: the q4p kernel takes upstream's new KV_rows argument (unused). qwen35 MTP K/V-only path uses the
  per-layer K/V rotations (ggml-org#31073).

Math: with upstream's softplus log1pf change (74bca39) reverted as a diagnostic, logits match the
pre-merge build exactly (27B Q6_K -c 4096 x 8: KLD -0.000006, same top 100 %; -ub 1: KLD 0). Kept: it
moves the Qwen3.8 GDN gate (KLD 0.001-0.003) and reads no worse against the fp32 reference (Q5_K_M -ub 1:
KLD 0.001713 vs 0.001779). Upstream's q8_1 correction-sum fix (8fc0376) moves only the MTP head, whose
weights are Q4_0: greedy-draft MTP text and acceptance are identical to the base, the draft probabilities move,
and the quantized sum is the more exact one (simulated Q4_0 x q8_1 dot: RMS error 0.58 vs 1.44). Kept. OPTLOG 329.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AaVsfEiPALnEHpNH9UZbjk
thefallentree added a commit to thefallentree/llama.cpp-gp100 that referenced this pull request Nov 8, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that
  upstream ggml-org#31047 replaced by tile specs
- deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the
  llm_attn_mask raw mask, build_attn_mha's kv_rows argument
- llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is
  recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit)
- kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510)
- graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wispoffates added a commit to wispoffates/llama.cpp that referenced this pull request Nov 8, 2026
… off

Upstream ggml-org#31047 sizes the MUL_MAT_ID tile by tokens per expert on every GPU (what Kane's sm_60 tile did in v5.37). The env opt-out
stays as the A/B switch: GGML_CUDA_MMQ_MOE_TPE=0 sizes the tile against all ubatch tokens again.

Assisted-by: Claude Opus 5.5 (Claude Code)
wispoffates added a commit to wispoffates/llama.cpp that referenced this pull request Nov 8, 2026
)

ggml-org#31047 changed ggml_cuda_launch_mm_ids_helper to emit tile specs (expert, col_low, col_high) instead of per-expert bounds. The tile GEMM
keeps its own tiling: tile_mm_id_tiles now counts the ids per expert in shared memory (ids below 0 first, as the helper's compact
layout orders them) and writes the bounds next to the tile list, in the same single launch. The helper's tile specs go to a scratch
buffer. Compact layout and tiles unchanged -> same results.

Assisted-by: Claude Opus 5.5 (Claude Code)
wispoffates added a commit to wispoffates/llama.cpp that referenced this pull request Nov 8, 2026
…f659f2); Kane's MMQ tile now upstream (ggml-org#31047)

CREDITS and SETTINGS note that upstream ggml-org#31047 sizes the MoE MMQ tile per expert on every GPU, so the series carries only the
GGML_CUDA_MMQ_MOE_TPE=0 switch; SETTINGS gains the v5.41 bullet (ggml-org#31047, ggml-org#30137 shared checkpoints, llama-bench decode note).

Assisted-by: Claude Opus 5.5 (Claude Code)
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 11, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).
thefallentree added a commit to thefallentree/llama.cpp-gp100 that referenced this pull request Nov 11, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that
  upstream ggml-org#31047 replaced by tile specs
- deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the
  llm_attn_mask raw mask, build_attn_mha's kv_rows argument
- llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is
  recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit)
- kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510)
- graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
thefallentree added a commit to thefallentree/llama.cpp-gp100 that referenced this pull request Nov 12, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that
  upstream ggml-org#31047 replaced by tile specs
- deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the
  llm_attn_mask raw mask, build_attn_mha's kv_rows argument
- llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is
  recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit)
- kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510)
- graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 12, 2026
Re-based onto a691b23.  Applied clean, but its routed path called the pre-re-base
`ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only).

The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it
gained an optional `expert_bounds` output that MMB keeps using: one compaction serves
MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and
routed-GLU) allocate the tile_spec buffer they do not read.  No MMB kernel logic changed.

Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1
routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`);
`GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 12, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 12, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).
thefallentree added a commit to thefallentree/llama.cpp-gp100 that referenced this pull request Nov 12, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that
  upstream ggml-org#31047 replaced by tile specs
- deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the
  llm_attn_mask raw mask, build_attn_mha's kv_rows argument
- llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is
  recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit)
- kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510)
- graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 12, 2026
Re-based onto a691b23.  Applied clean, but its routed path called the pre-re-base
`ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only).

The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it
gained an optional `expert_bounds` output that MMB keeps using: one compaction serves
MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and
routed-GLU) allocate the tile_spec buffer they do not read.  No MMB kernel logic changed.

Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1
routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`);
`GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 12, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).
thefallentree added a commit to thefallentree/llama.cpp-gp100 that referenced this pull request Nov 12, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that
  upstream ggml-org#31047 replaced by tile specs
- deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the
  llm_attn_mask raw mask, build_attn_mha's kv_rows argument
- llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is
  recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit)
- kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510)
- graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 12, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).
@BrewTestBot BrewTestBot mentioned this pull request Nov 13, 2026
1 task done
PapyKahan added a commit to PapyKahan/llama.cpp that referenced this pull request Nov 13, 2026
Upstream's version is kept wherever it does what the branch did; the branch's stays where upstream has none:
- MoE cache: upstream's ClassLRU replaces the SLRU (ggml-org#31233) and takes the branch's pending and exclusive slots,
  tail skip and background admissions; the misses left to the CPU are upstream's (ggml-org#30966 as merged, ggml-org#31888: a second
  slot map, the scheduler prefetching the inputs), which replaces the branch's stash and CPU part registration, and
  the scheduler's copy callback is upstream's again. Host mode, phases and the service policy as before.
- build_moe_ffn: upstream's slots and CPU ids from build_moe_cache_slots, the host and batch parts before them.
- CUDA MMQ and MMF: upstream's tile specs (ggml-org#31047, ggml-org#32067) replace the branch's tile map; the counting sort of the ids
  writes them, and they are zeroed first when ids may be negative. The marker of negative ids moves to its own op
  parameter, off the accumulator precision's.
- CUDA flash attention: padded head sizes (ggml-org#30285) in the kernel with the in-place quantized loaders; a quantized cache
  keeps the dense mask instead of kv_rows (ggml-org#29510), which those loaders do not take.
- lightning indexer: upstream's MMA kernel (ggml-org#31803, ggml-org#29050) with the branch's row indices.
- MMVF for few rows: upstream's rule (ggml-org#31959) after the branch's switch.
- recurrent models: upstream's conv state store in one set_rows (ggml-org#31660) with the branch's state marks; the fused
  delta net only (ggml-org#32078).
- qwen4exp: QSA without the kq_mask as upstream, with the branch's query chunks; rope through build_rope (ggml-org#31683).
- context: the scheduler is reused across reserves (ggml-org#32009) but not across the phases of the MoE cache, which give
  back each other's compute buffers; graph slots are reset with either.
- MTP: the target rows on the device (ggml-org#31927) stay off with the background catch-up, which reads them while the
  target decodes its next batch.
- server: checkpoints by reference (ggml-org#30137), a reused one is taken over through a mutable task id.

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_016qCoLqWgrDtkf9nYBJgAyJ
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 13, 2026
… allocator fixes

Groundwork block (multiple base-level concerns, by design):
- FA KV-split width invariance (launch_fattn, n_q <= 8)
- shared-NextN MTP heads keep their own KV (is_mem_shared gate)
- CPU llamafile_sgemm routes n <= 8 to vec_dot (decode/verify band unity)
- single-device -sm tensor skips the Meta wrapper
- meta-buffer compute-container headroom 16 -> 128 (recurrent snapshot views)
- multi-ubatch logits readback ordering (async D2H race)
- ggml-alloc: release view sources whose views are never consumed (W4)
- ggml-alloc: reuse the recorded layout only for the graph it was computed for
  (graph fingerprint; delivery repo issue ggml-org#183)

Sources: old 00, 05, 07, 09a(compute headroom), 06(readback), 15(W4).

Also carries two generic upstream foundation changes:
- the upstream MUL_MAT_ID duplicate-ids fix (upstream/UPSTREAM-PR-mul-mat-id-dup.patch,
  re-cut against the post-ggml-org#31047 tile_spec grid): mm_ids_helper keeps every occurrence of a
  repeated expert id as its own compact row.  The compact column count is then exactly
  n_tokens*n_expert_used, so every column has its own tile_spec entry and upstream's per-tile
  grid covers the expanded list -- the in-kernel column-tile loop this fix used to need is
  gone, and upstream's seam writer is reused verbatim (one tile_spec entry per expert against
  the n_experts trailing slots).  The host sorted fallback emits every match.  Fixes the
  test-backend-ops MUL_MAT_ID dup=1 failures and the quantize_mmq_q8_1 page fault; validated
  after the merge with `test-backend-ops -o MUL_MAT_ID` 931/931 on gfx1201.  Applied here so
  every later MUL_MAT_ID block builds on correct duplicate handling.
- cache the pre-existing upstream env reads that sit on hot paths in function-local
  statics: GGML_CUDA_CUBLAS_COMPUTE_TYPE (per cuBLAS matmul),
  GGML_CUDA_ENABLE_UNIFIED_MEMORY (per device allocation), GGML_CUDA_REGISTER_HOST,
  GGML_CUDA_NO_PINNED, LLAMA_GRAPH_INPUT_DEBUG (per graph input) and LLAMA_BATCH_DEBUG
  (per batch).  getenv() is expensive on Windows.

Also fixes delivery repo issue ggml-org#183.  ggml_gallocr_alloc_graph() re-applied the recorded
node_allocs/leaf_allocs positionally and invalidated them only on a node/leaf count or a per-node
size change, so a graph with the same node count but a different node order, op/shape set or output
marking inherited a layout computed for a different graph.  In-graph sampling (build_sampling +
ggml_build_forward_select, one chain per sequence x output row) is exactly such a graph: selecting
another sequence's chain keeps the node count and changes which top_k tensors are outputs, so with
the second scheduler on a --parallel server the newly active candidate-id tensors all landed on one
recycled block and every output row read the last computed ids.  DFlash drafting therefore produced
correct drafts only for the first slot that served a request.  The allocator now records an FNV-1a
fingerprint of the graph its layout belongs to (node/leaf order, op, type, ne[], view_src,
INPUT/OUTPUT/COMPUTE flags, node/leaf split) and re-reserves on a mismatch; it only ever adds a
re-reserve, never skips one.

Also extend the -Wshadow sweep to the remaining upstream shadowing declarations the clang
build reports (all present at the fork point): step35.cpp per-layer n_embd_k_gqa/n_embd_v_gqa,
llama-moe-cache.cpp init_ctx, llama-vocab.cpp _try_copy, llama-quant.cpp layer_info, and
llama-model.cpp make_gpu_buft_list / get_tensor.

Fold (r86): beta 13, meta-hot-dispatcher (issue ggml-org#184).  The split-state dispatcher is back to
the exact pre-ggml-org#170 shape and the ggml-org#170 alias/host resolution lives in a noinline,
cold helper.  Measured zero (-0.06 %, greedy text identical, 4 concurrent
streams on 2x R9700); the dispatcher drops 454 -> 287 B.

Rename-only -Wshadow sweeps are not carried as part of this block: they re-skin every
re-base conflict in the files later blocks also touch and silence a warning class that is
not an error (the llama target keeps -Wshadow enabled for new code).
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 13, 2026
Re-based onto a691b23.  Applied clean, but its routed path called the pre-re-base
`ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only).

The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it
gained an optional `expert_bounds` output that MMB keeps using: one compaction serves
MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and
routed-GLU) allocate the tile_spec buffer they do not read.  No MMB kernel logic changed.

Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1
routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`);
`GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 13, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 14, 2026
… allocator fixes

Groundwork block (multiple base-level concerns, by design):
- FA KV-split width invariance (launch_fattn, n_q <= 8)
- shared-NextN MTP heads keep their own KV (is_mem_shared gate)
- CPU llamafile_sgemm routes n <= 8 to vec_dot (decode/verify band unity)
- single-device -sm tensor skips the Meta wrapper
- meta-buffer compute-container headroom 16 -> 128 (recurrent snapshot views)
- multi-ubatch logits readback ordering (async D2H race)
- ggml-alloc: release view sources whose views are never consumed (W4)
- ggml-alloc: reuse the recorded layout only for the graph it was computed for
  (graph fingerprint; delivery repo issue ggml-org#183)

Sources: old 00, 05, 07, 09a(compute headroom), 06(readback), 15(W4).

Also carries two generic upstream foundation changes:
- the upstream MUL_MAT_ID duplicate-ids fix (upstream/UPSTREAM-PR-mul-mat-id-dup.patch,
  re-cut against the post-ggml-org#31047 tile_spec grid): mm_ids_helper keeps every occurrence of a
  repeated expert id as its own compact row.  The compact column count is then exactly
  n_tokens*n_expert_used, so every column has its own tile_spec entry and upstream's per-tile
  grid covers the expanded list -- the in-kernel column-tile loop this fix used to need is
  gone, and upstream's seam writer is reused verbatim (one tile_spec entry per expert against
  the n_experts trailing slots).  The host sorted fallback emits every match.  Fixes the
  test-backend-ops MUL_MAT_ID dup=1 failures and the quantize_mmq_q8_1 page fault; validated
  after the merge with `test-backend-ops -o MUL_MAT_ID` 931/931 on gfx1201.  Applied here so
  every later MUL_MAT_ID block builds on correct duplicate handling.
- cache the pre-existing upstream env reads that sit on hot paths in function-local
  statics: GGML_CUDA_CUBLAS_COMPUTE_TYPE (per cuBLAS matmul),
  GGML_CUDA_ENABLE_UNIFIED_MEMORY (per device allocation), GGML_CUDA_REGISTER_HOST,
  GGML_CUDA_NO_PINNED, LLAMA_GRAPH_INPUT_DEBUG (per graph input) and LLAMA_BATCH_DEBUG
  (per batch).  getenv() is expensive on Windows.

Also fixes delivery repo issue ggml-org#183.  ggml_gallocr_alloc_graph() re-applied the recorded
node_allocs/leaf_allocs positionally and invalidated them only on a node/leaf count or a per-node
size change, so a graph with the same node count but a different node order, op/shape set or output
marking inherited a layout computed for a different graph.  In-graph sampling (build_sampling +
ggml_build_forward_select, one chain per sequence x output row) is exactly such a graph: selecting
another sequence's chain keeps the node count and changes which top_k tensors are outputs, so with
the second scheduler on a --parallel server the newly active candidate-id tensors all landed on one
recycled block and every output row read the last computed ids.  DFlash drafting therefore produced
correct drafts only for the first slot that served a request.  The allocator now records an FNV-1a
fingerprint of the graph its layout belongs to (node/leaf order, op, type, ne[], view_src,
INPUT/OUTPUT/COMPUTE flags, node/leaf split) and re-reserves on a mismatch; it only ever adds a
re-reserve, never skips one.

Also extend the -Wshadow sweep to the remaining upstream shadowing declarations the clang
build reports (all present at the fork point): step35.cpp per-layer n_embd_k_gqa/n_embd_v_gqa,
llama-moe-cache.cpp init_ctx, llama-vocab.cpp _try_copy, llama-quant.cpp layer_info, and
llama-model.cpp make_gpu_buft_list / get_tensor.

Fold (r86): beta 13, meta-hot-dispatcher (issue ggml-org#184).  The split-state dispatcher is back to
the exact pre-ggml-org#170 shape and the ggml-org#170 alias/host resolution lives in a noinline,
cold helper.  Measured zero (-0.06 %, greedy text identical, 4 concurrent
streams on 2x R9700); the dispatcher drops 454 -> 287 B.

Rename-only -Wshadow sweeps are not carried as part of this block: they re-skin every
re-base conflict in the files later blocks also touch and silence a warning class that is
not an error (the llama target keeps -Wshadow enabled for new code).
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 14, 2026
Re-based onto a691b23.  Applied clean, but its routed path called the pre-re-base
`ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only).

The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it
gained an optional `expert_bounds` output that MMB keeps using: one compaction serves
MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and
routed-GLU) allocate the tile_spec buffer they do not read.  No MMB kernel logic changed.

Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1
routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`);
`GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 14, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).

r279 amendment (GitHub issue ggml-org#308, reported by briansp2020): drain a queued async segmented upload before the
synchronous splice.
The segmented (fused) tensor arm queues its copies on each device's stream and, when the requested range ends
mid-row, queues a zero guard of up to 512 bytes PAST the end of that range (the scheduler's `copy_experts` MMQ
pad).  A row-aligned chunk of the LOADER's chunked `--load-mode none` upload takes that same arm, and the chunk
after it usually starts mid-row, so it falls through to the synchronous splice -- and a synchronous write is not
ordered against copies already queued on a device stream.  A late guard therefore zeroes the first bytes of the
next chunk, i.e. real weight data: two loads of the same file produce different weights (each load internally
deterministic, the fingerprint changing between loads -- 2 of 6 loads on stock r273, 1 of 24 on r277 per the
report, and a needle answer flips).  The backend context now records that an async segmented upload may still be
in flight on a model/weights buffer and the synchronous arm drains it first, which also restores the intended
order (guard first, then the real bytes overwrite it).  `GGML_META_SEG_DRAIN=0` is the A/B/bisect arm and
`GGML_META_SEG_DRAIN_LOG=1` prints one census line per drain (a fix whose firing is invisible cannot be gated).
Measured on gfx1201: 90 async->sync transitions in ONE 35B-A3B `-sm tensor --load-mode none` load (the
protection is not vacuous), and 12 loads -- 6 with the drain, 6 with the kill switch -- gave ONE greedy text, so
the change is text-neutral where the race does not bite.  Gate: `scripts/gate-meta-seg-drain.sh`.  The observed
defect rate is ~1/24 loads, so a green series is evidence the ordering gap is closed, not proof it was hit here.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 14, 2026
Re-based onto a691b23.  Applied clean, but its routed path called the pre-re-base
`ggml_cuda_launch_mm_ids_helper` (which produced `expert_bounds` only).

The helper now emits upstream ggml-org#31047's `tile_spec` (block 00's re-implementation), so it
gained an optional `expert_bounds` output that MMB keeps using: one compaction serves
MMQ/MMF (tile_spec) and MMB (per-expert bounds), and both MMB call sites (routed and
routed-GLU) allocate the tile_spec buffer they do not read.  No MMB kernel logic changed.

Validated: build green; MMB_DENSE fires (GGML_CUDA_MMB_LOG=1: `MMB_CFG ... dense_geom=1
routed=0 ...`, `MMB_DENSE blk.0.ffn_gate_inp.weight type=f32 M=128 K=2048 T=512`);
`GGML_CUDA_MMB=0` byte-identical (108 chars, sha d94aef3f5033) on Qwen3-Coder-30B-A3B.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 14, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).

r279 amendment (GitHub issue ggml-org#308, reported by briansp2020): drain a queued async segmented upload before the
synchronous splice.
The segmented (fused) tensor arm queues its copies on each device's stream and, when the requested range ends
mid-row, queues a zero guard of up to 512 bytes PAST the end of that range (the scheduler's `copy_experts` MMQ
pad).  A row-aligned chunk of the LOADER's chunked `--load-mode none` upload takes that same arm, and the chunk
after it usually starts mid-row, so it falls through to the synchronous splice -- and a synchronous write is not
ordered against copies already queued on a device stream.  A late guard therefore zeroes the first bytes of the
next chunk, i.e. real weight data: two loads of the same file produce different weights (each load internally
deterministic, the fingerprint changing between loads -- 2 of 6 loads on stock r273, 1 of 24 on r277 per the
report, and a needle answer flips).  The backend context now records that an async segmented upload may still be
in flight on a model/weights buffer and the synchronous arm drains it first, which also restores the intended
order (guard first, then the real bytes overwrite it).  `GGML_META_SEG_DRAIN=0` is the A/B/bisect arm and
`GGML_META_SEG_DRAIN_LOG=1` prints one census line per drain (a fix whose firing is invisible cannot be gated).
Measured on gfx1201: 90 async->sync transitions in ONE 35B-A3B `-sm tensor --load-mode none` load (the
protection is not vacuous), and 12 loads -- 6 with the drain, 6 with the kill switch -- gave ONE greedy text, so
the change is text-neutral where the race does not bite.  Gate: `scripts/gate-meta-seg-drain.sh`.  The observed
defect rate is ~1/24 loads, so a green series is evidence the ordering gap is closed, not proof it was hit here.
thefallentree added a commit to thefallentree/llama.cpp-gp100 that referenced this pull request Nov 14, 2026
- sm_60 MUL_MAT_ID kernels: keep the per-expert-bounds ids helper (mmid-bounds.cu) that
  upstream ggml-org#31047 replaced by tile specs
- deepseek41: the graph on upstream ggml-org#31733 (model member, no_build base ctor), the
  llm_attn_mask raw mask, build_attn_mha's kv_rows argument
- llama-context: graph_params initialiser; the DFlash device-copy reader event (ggml-org#31506) is
  recorded in decode_finish (a launched-ahead decode finishes in llama_decode_commit)
- kv-cells: seq_rm_all clears the sequence's seq_bits (ggml-org#29510)
- graph slots debug: llm_attn_mask; model saver: DEEPSEEK41 in the DSV4 condition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 14, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).

r279 amendment (GitHub issue ggml-org#308, reported by briansp2020): drain a queued async segmented upload before the
synchronous splice.
The segmented (fused) tensor arm queues its copies on each device's stream and, when the requested range ends
mid-row, queues a zero guard of up to 512 bytes PAST the end of that range (the scheduler's `copy_experts` MMQ
pad).  A row-aligned chunk of the LOADER's chunked `--load-mode none` upload takes that same arm, and the chunk
after it usually starts mid-row, so it falls through to the synchronous splice -- and a synchronous write is not
ordered against copies already queued on a device stream.  A late guard therefore zeroes the first bytes of the
next chunk, i.e. real weight data: two loads of the same file produce different weights (each load internally
deterministic, the fingerprint changing between loads -- 2 of 6 loads on stock r273, 1 of 24 on r277 per the
report, and a needle answer flips).  The backend context now records that an async segmented upload may still be
in flight on a model/weights buffer and the synchronous arm drains it first, which also restores the intended
order (guard first, then the real bytes overwrite it).  `GGML_META_SEG_DRAIN=0` is the A/B/bisect arm and
`GGML_META_SEG_DRAIN_LOG=1` prints one census line per drain (a fix whose firing is invisible cannot be gated).
Measured on gfx1201: 90 async->sync transitions in ONE 35B-A3B `-sm tensor --load-mode none` load (the
protection is not vacuous), and 12 loads -- 6 with the drain, 6 with the kill switch -- gave ONE greedy text, so
the change is text-neutral where the race does not bite.  Gate: `scripts/gate-meta-seg-drain.sh`.  The observed
defect rate is ~1/24 loads, so a green series is evidence the ordering gap is closed, not proof it was hit here.
stew675 pushed a commit to stew675/llama.cpp that referenced this pull request Nov 14, 2026
Re-based onto a691b23: 8 conflicted files / 22 hunks, plus four clean-applied call
sites whose signatures moved.  The block resolves and builds, but on the re-based tree it
GPU page-faulted at -c 8192 on a plain dense 4B; this commit is the resolution plus the
four defects that debug turned up.  Three of them were silent delivery-code losses.

- mmid.cu (9 hunks): the delivery's per-occurrence compaction on upstream's tile_spec grid,
  as R01/R09 established.
- ggml-cuda.cu (3): upstream's batched set/get_tensor_n plus the delivery's
  ggml_cuda_peer_copy_staged declaration; ggml_cuda_should_fuse_mul_mat_q keeps upstream's
  NVFP4 scale params; the dispatcher moves to ggml-cuda-try-fuse.cu.
- mmq.cuh (2), mmvq.cu (2): include set and the per-shape J selection, both sides kept.
- llama-ext.h / llama-context.h/.cpp (3): both device-layer-input APIs (upstream's
  embd_row/llama_set_embeddings_layer_inp_dev and the delivery's F1 llama_lf_*), the
  GGML_FORCE_N_RS_SEQ diagnostic and upstream's !causal_attn clamp, the F1 lf_dev_rows
  inverse map plus upstream's embd_row event recording.
- tests/test-backend-ops.cpp (2): additive on both sides.

Finding and fix 1 (the fault): ggml_cuda_mul_mat_q_pair passed the pre-ggml-org#31047 value for
what upstream renamed from `ncols_max` (a column COUNT the launcher divided by J) to `ntj`
(the J-tile count, consumed directly as grid.x).  The dense gate+up pair therefore launched
grid.x = ncols instead of ncols/J (512 vs 4 on the 4B FFN) and enumerated tiles past
src1_q8_1/dst -> page fault.  Both arms now derive ntj like the single-node path; the routed
arm also builds the per-arm tile_spec it was passing as nullptr (upstream's kernel reads
tile_spec[jt] whenever ids_dst is set) and uses upstream's ids convention nchannels_y = 1
with the experts in tile_spec.  Diagnostic route: GGML_CUDA_DISABLE_FUSION=1 was clean,
GGML_PAIR_OFF=1 was clean, and a temporary launch dump showed ntj=512 on exactly the pair
launches and ntj=4 everywhere else.

Finding and fix 2 (silent, silent on top of silent): the routed-compact MoE MMQ dispatch
was unreachable -- its gate tested args.nchannels_y, which upstream's ids convention sets to
1 (n_experts now live in nchannels_x) -- and behind that, the compact kernel still passed
process_tile's old `tile_y_max_j` (inclusive max) after upstream renamed it `tile_y_j_sup`
(exclusive count), so the first column-count fix alone produced garbage text.  Both fixed:
the compact path is reachable, bit-identical to the plain path, and +1.9% prefill
(3489 vs 3423 t/s, Qwen3-Coder-30B-A3B Q4_K_M, 5256-token prompt, 2x2 reps).

Finding and fix 3 (the dispatcher merge, TODO ggml-org#290): the interim two-dispatcher split kept
upstream's inline copy as a fallback, but that copy was not upstream's arms -- it was ~490
lines of upstream's dispatcher merged with STALE DUPLICATES of delivery arms
(ssm_conv_in, op_ssm_conv_l2_gatebeta, op_rms_norm_q8_1, add_softplus_mul, shexp_down_gate,
l2_norm_pair, gate_beta_verify).  One of them, the inline SSM conv-input fold, fired on
qwen35moe decode and produced text that diverges from the unfused chain (a state-carrying
path).  Resolved by reconciling into ONE dispatcher: every arm was audited against upstream
master; all but the DSV4 hyper-connection post are already owned by the delivery's
dispatcher (or its newer equivalent), so the DSV4 HC post arm is folded in at upstream's
position and ggml_cuda_try_fuse_legacy() is deleted, together with the superseded
ggml_cuda_match_moe_weighted_reduction matcher + struct + constexpr that only it used.

Validated (gfx1201, ROCm 10.1, VMM build): build green, no `<<<<<<<`; same-seed greedy text
on the dense 4B (1472ebdadd46), Qwen3-Coder-30B-A3B (013d09f165a5) and 3-GPU -sm tensor
Qwen3.6-35B-A3B Q8_0 (90decf558d96) is identical across default / pair-off / routed-off /
fused-vs-unfused, so every fusion arm is bit-identical to the unfused chain on this tree;
gate-norm-rows-alias.sh green (180 fused, 0 declined, fused == chain f476efaac086);
test-backend-ops -o MUL_MAT_ID 931/931.  Fusion is worth +26% decode on the 4B (87.4 vs
69.0 t/s) and +38% on the 35B-A3B tensor arm (80.5 vs 58.4).

r279 amendment (GitHub issue ggml-org#308, reported by briansp2020): drain a queued async segmented upload before the
synchronous splice.
The segmented (fused) tensor arm queues its copies on each device's stream and, when the requested range ends
mid-row, queues a zero guard of up to 512 bytes PAST the end of that range (the scheduler's `copy_experts` MMQ
pad).  A row-aligned chunk of the LOADER's chunked `--load-mode none` upload takes that same arm, and the chunk
after it usually starts mid-row, so it falls through to the synchronous splice -- and a synchronous write is not
ordered against copies already queued on a device stream.  A late guard therefore zeroes the first bytes of the
next chunk, i.e. real weight data: two loads of the same file produce different weights (each load internally
deterministic, the fingerprint changing between loads -- 2 of 6 loads on stock r273, 1 of 24 on r277 per the
report, and a needle answer flips).  The backend context now records that an async segmented upload may still be
in flight on a model/weights buffer and the synchronous arm drains it first, which also restores the intended
order (guard first, then the real bytes overwrite it).  `GGML_META_SEG_DRAIN=0` is the A/B/bisect arm and
`GGML_META_SEG_DRAIN_LOG=1` prints one census line per drain (a fix whose firing is invisible cannot be gated).
Measured on gfx1201: 90 async->sync transitions in ONE 35B-A3B `-sm tensor --load-mode none` load (the
protection is not vacuous), and 12 loads -- 6 with the drain, 6 with the kill switch -- gave ONE greedy text, so
the change is text-neutral where the race does not bite.  Gate: `scripts/gate-meta-seg-drain.sh`.  The observed
defect rate is ~1/24 loads, so a green series is evidence the ordering gap is closed, not proof it was hit here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants