Repository navigation
[MRG] Reuse quadratic gradients in GW/FGW conditional-gradient solvers - #935
xihaian251 wants to merge 2 commits into
Conversation
The exact GW line search already computes dot = hC1 @ deltaG @ hC2.T. Carry the gradient forward with df(G + alpha*deltaG) = df(G) - 2*alpha*dot instead of recomputing tensor_product on every conditional-gradient iteration. Enabled only for symmetric structures with the closed-form line search; the public solve_gromov_linesearch keeps its three-value contract and asymmetric/Armijo paths are unchanged. Adds focused regression tests and a RELEASES.md entry.
Fix the two E731 lint errors reported by the upstream Lint job without changing the tested numerical behaviour.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #935 +/- ##
=======================================
Coverage 97.09% 97.09%
=======================================
Files 130 131 +1
Lines 27229 27320 +91
=======================================
+ Hits 26437 26527 +90
- Misses 792 793 +1 🚀 New features to boost your workflow:
|
|
Hi POT maintainers, PR #935 is ready for technical review. All GitHub Actions checks have completed successfully (16 passed, 1 skipped), including Lint, source builds, cross-platform tests, and doctests. The only remaining red statuses are from the legacy CircleCI I investigated this without modifying the PR:
These results suggest that the remaining CircleCI failure is unlikely to be caused by the latest lint-only change, although its exact cause is still unverified. Could you please rerun the CircleCI The mathematical correctness, numerical equivalence, performance measurements, and regression tests for the GW/FGW optimization have already been documented in the PR. Thank you for your consideration. |
Types of changes
Performance improvement of an existing core solver. Public API unchanged.
Motivation and context
In every iteration of the conditional-gradient solvers for Gromov-Wasserstein
and fused Gromov-Wasserstein, the exact line search in
solve_gromov_linesearchalready computesin order to form the coefficients of the 1-D quadratic step. The resulting
matrix is discarded when the function returns
(alpha, 1, cost_G).On the next iteration, the generic conditional-gradient solver recomputes
df(G) = 2 * (constC - hC1 @ G @ hC2.T)from scratch, which evaluates the samepair of matrix products again. For symmetric structures this work is redundant.
Issue #491 discusses the cost of the line search for GW descent. This PR does
not implement the "skip line search" option requested there, and leaves the
default step size and the
[0, 1]step constraint untouched. It only avoidsrecomputing a matrix product that is already available.
Mathematical identity
With POT's convention
tensor_product(G) = constC - hC1 G hC2.Tandgwggrad(G) = 2 * tensor_product(G), writingD = hC1 deltaG hC2.Tgives, forany step
alpha(including a clipped one):The quadratic model remains
The linear feature cost in FGW changes
bbut not the identity above. Theidentity is independent of the marginals and holds for both
square_lossandkl_loss. Exact rational algebra was verified in Wolfram; an independentfour-index summation oracle agrees with the fast objective to 8.9e-16 and with
the cached gradient to 3.6e-15 relative error.
Implementation
returns
dot. The publicsolve_gromov_linesearchkeeps its three-valuecontract and its exact numerical behaviour.
df(G_next) = df(G) - 2 * alpha * dot, consumed by the existing four-valuebranch of
generic_conditional_gradient.symmetric=Trueandarmijo=Falseingromov_wassersteinandfused_gromov_wasserstein. Asymmetric and Armijopaths are untouched, since the asymmetric gradient needs a second cross term
that the line search does not compute.
Diff: two production files (
ot/gromov/_gw.py,RELEASES.md) plus focusedregression tests.
Results
Numerical: 18 end-to-end cases (NumPy/PyTorch/JAX, float32/float64,
square/kl, GW/FGW, symmetric/asymmetric/Armijo, user
G0, near-degenerate)produce bit-identical plans and identical objectives and iteration counts.
A 14-case, 150-iteration drift audit shows a maximum relative gradient
difference of 8.2e-16 with no trajectory divergence, so no periodic refresh is
needed.
Performance (single BLAS thread, 9 paired repetitions, two independent random
orders, bootstrap 95% CI):
EMD still accounts for 53-80% of the wall time, so gains at sizes below 100 are
within measurement noise and are not claimed.
How has this been tested
pytest test/gromov/ test/test_optim.py: 511 passed, 135 skipped, 6 xfailed.pytest: 3644 passed, 468 skipped, 6 xfailed, 1 failure unrelated to this change (test_helpers.py::test_helpers, a distutils MSVC compiler-probe failure in this Windows environment; reproduced on the unmodified base commit).2022 and the repository's Eigen submodule.
PR checklist