Skip to content

Accelerate dense NumPy Sinkhorn with Brenier-inspired residual checks - #940

Draft
hys-ops wants to merge 1 commit into
PythonOT:masterfrom
hys-ops:residual-sinkhorn/ordinary-warm-checks
Draft

hys-ops wants to merge 1 commit into
PythonOT:masterfrom
hys-ops:residual-sinkhorn/ordinary-warm-checks

Conversation

@hys-ops

@hys-ops hys-ops commented Nov 27, 2026

Copy link
Copy Markdown

Types of changes

Performance improvement to classical dense NumPy Sinkhorn, an optional accuracy parameter, documentation, and regression tests.

Motivation and context / Related issue

This PR brings Residual Sinkhorn to supported dense NumPy calls in ot.sinkhorn and ot.bregman.sinkhorn_knopp. It reduces work at the same requested marginal tolerance, without requiring users to change their calls.

The approach grew out of our work on Brenier maps: a residual-based check lets supported solves stop earlier at the same marginal tolerance. The implementation also avoids a second kernel allocation and reuses matrix products and fixed-cost kernels. See the Residual Sinkhorn project page for the mathematical derivation and how the idea transfers from Brenier maps to Sinkhorn.

This PR also extends the earlier adapter to a case where it did not help. In repeated solves such as point-cloud registration, the previous plan’s scalings can be a good warm start, but the next marginal check after the first update may not occur until update 11. Supported warm calls check the same marginal target after updates 2–4 as well. Before an early return, both marginals are checked on the actual returned array; calls requesting a scaling log retain the scalings for the next solve. Shared input and residual checks reuse work without changing the schedule. Unsupported ordinary requests use POT's existing path. Other backends and sinkhorn2 are outside this change.

The optional plan_tol argument is for callers who explicitly need a whole-plan error target. It is unset in all default-call benchmarks below.

Related: #934. Thanks to @xihaian251 for independently checking the mathematical argument and for an independent port and timing study of two earlier implementation changes. Reproduction archive.

How has this been tested?

Same marginal tolerance, no additional accuracy request

These are direct reruns of stock POT, the original standalone adapter, and the final candidate (source tree from 66ce7cc). All used the same marginal tolerance and iteration budget within a workload, with plan_tol unset. Twelve order-balanced single-core, single-BLAS-thread trials were used; grouped figures sum per-setting medians. For the 56-frame jobs, each solver evolves its own poses from identical starting inputs.

Workload Stock POT (ms) Adapter 0.2.0 (ms) Final candidate (ms)
Original 27 dense settings 108.12 63.83 62.72
MNIST, 900 pairs × 3 regularizations 1,714.68 866.22 861.95
RGB palette, 64 dense solves 1,045.57 686.04 646.85
graspologic graph alignment, 400 solves 802.46 740.73 735.14
Bunny, 192 points, final 8 frames, reg 0.08 2.96 2.98 1.73

Most gains in the first four rows were already present in the adapter. In the 192-point warm-start example, total updates dropped from 58 to 13. In a prior controlled comparison, changing only the check schedule in the same implementation took 2.33 to 1.88 ms. In the final direct rerun, all eight targeted registration settings had shorter medians than stock, and the five complete 56-frame runs took 16–38% less time. All 304 registration plans met stopThr=1e-7 on both marginals. Across the additional 160 settings the final candidate returned another 5,417 plans meeting their requested marginal tolerances. Earlier exits can change the plan and its error against a tighter numerical reference even when marginal tolerances match.

Final integrated candidate

Separately, we measured the effect of removing shared validation work in the final candidate. A separate matched replay against 0460680 reduced time across the 168 archived application settings by 2.21% in aggregate. The two dense MNIST batches took 2.75% and 3.03% less time; the four terminal registration settings took 3.86% less. These percentages are from the direct final-versus-previous comparison; they are not inferred from or added to the direct three-way timings above.

Two of 186 settings were initially more than 3% slower than the preceding candidate; neither reproduced that slowdown in 36 paired reruns. Very small problems that already converge on update one can still favor stock. In this follow-up, the cold-cache identical-seed 8×8 case took 29.8 µs in stock and 38.4 µs in the final candidate; the 32×128 case took 47.2 and 53.6 µs. These are controlled stress tests. A separate repeated-call stream retained roughly 1 µs of overhead per 8×8 call after the check cleanup. None of these measurements implies a universal speedup.

The final public entry point matched 0460680 on returned plan contents, marginal residuals and warning messages over 5,739 calls across 186 settings. The earlier native Linux suite of this exact source tree with GCC completed with 1,585 passed, 170 skipped, and 4 expected failures. The focused coverage includes warm starts that exit on updates 2–4, logged scalings, unsupported inputs and numerical rollback. Separate explicit-TV regressions test supported requests and failure to meet the requested bound. A fresh checkout of the final Python code also passed 126 focused tests (10 skipped) using the released binaries for unchanged extensions. The local HTML build completed with gallery execution disabled, and the new full-plan example ran separately.

Full benchmark tables and case studies. The reusable RGB summary and the MNIST grid experiment on the project page are separate research implementations, not included in this patch.

PR checklist

  • The contributing guide and repository template were reviewed.
  • Rendered the local HTML docs without running the full gallery; hosted CI has not run.
  • Local native tests passed and changes have focused test coverage.
  • Updated RELEASES.md.
  • All configured pre-commit hooks passed on the full repository.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant