Skip to content

ggml: add fused sinkhorn op (eps + output-layout params)#2115

Merged
ikawrakow merged 2 commits into
ikawrakow:mainfrom
joelfarthing:filament/sinkhorn-op
Jul 12, 2026
Merged

ggml: add fused sinkhorn op (eps + output-layout params)#2115
ikawrakow merged 2 commits into
ikawrakow:mainfrom
joelfarthing:filament/sinkhorn-op

Conversation

@joelfarthing

@joelfarthing joelfarthing commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

openPangu's mHC runs Sinkhorn normalization as a graph chain at two sites per layer, roughly 240 nodes per layer of micro-ops on 4x4 matrices: 27907 graph nodes on the llama-server startup graph with the configuration below, 13463 with this PR. It adds GGML_OP_SINKHORN, which does the whole normalization in one op (CPU and CUDA), and uses it in the openPangu graph. Suggested in #2065 review as a future improvement.

The op takes the flat [S*S, T] batch, supports 1 <= S <= 8, and carries eps and output-layout parameters, so the same construction in the DeepSeek V4 port under construction in #2110 can adopt it at its pre-reshape call site. openPangu would be the only caller; no other architecture's graph changes.

Measured on the #2065 setup (RTX 4070, the #2065 Q4_K_M), warm back-to-back sweeps of llama-sweep-bench -m <model> -c 34816 -ub 2048 -fa off -ngl 999 -ot exps=CPU -ctk q8_0 -ictk q8_0, main vs this branch, condensed from the 17-row sweep:

N_KV PP main PP fused dPP% TG main TG fused dTG%
0 180.79 176.66 -2.3 11.89 13.16 +10.7
8192 133.57 131.39 -1.6 10.50 11.44 +9.0
16384 124.14 122.20 -1.6 10.46 11.39 +8.9
24576 117.84 116.32 -1.3 10.39 11.36 +9.3
32768 110.68 109.16 -1.4 10.38 11.32 +9.1

TG is up 7.6-11.1% at every measured depth here and in an 8K sweep, single warm pass per cell; PP at ub 2048 is flat within run-to-run variation. The temp-0 needle output is byte-identical to main on both the CUDA and CPU paths, and a PPL spot check matches (1.2133 +/- 0.019 main, 1.2147 +/- 0.019 fused).

Comment thread src/graphs/build_openpangu.cpp Outdated
@@ -225,34 +225,13 @@ static ggml_tensor * openpangu_causal_conv(ggml_context * ctx, ggml_cgraph * gf,
// --- mHC Sinkhorn: h_res [S*S, T] -> doubly-stochastic per token, 20 iters (ends on col norm) ---
static ggml_tensor * openpangu_sinkhorn(ggml_context * ctx, ggml_tensor * h_res_flat,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point in having this function now. You can just call ggml_sinkhorn from mhc_post.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done; wrapper removed!

@ikawrakow ikawrakow merged commit 97bc869 into ikawrakow:main Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants