Skip to content

Reduce per-iteration work in entropic_semirelaxed_gromov_wasserstein #915

Open

Description

@dexhunter

🚀 Feature

Make each mirror-descent iteration of ot.gromov.entropic_semirelaxed_gromov_wasserstein do less work, with identical results.

Motivation

Each iteration builds two kinds of avoidable arrays. It forms a full (ns, nt) matrix with nx.outer(ones_p, v) only to add the same row to every row. It also multiplies the gradient by 2 in gwggrad, multiplies by 0.5 in the asymmetric case, and negates the result. For small and medium problems, these extra array operations take a large share of the runtime.

Measured on one CPU core with 1000 iterations and epsilon=0.1 (median of three runs):

Situation Before After Change
5 x 5, symmetric costs 14.08 ms 11.18 ms 20.6% less time
50 x 20, symmetric costs 24.51 ms 20.48 ms 16.4% less time
50 x 20, asymmetric costs 36.68 ms 29.18 ms 20.4% less time
1000 x 200, symmetric costs, 200 iterations 2202 ms 2183 ms No material change

The transport plans are bit-for-bit identical in all cases.

Pitch

Add the marginal row through broadcasting instead of an outer product. Call the existing tensor_product helper and apply the factor 2 and the sign once, through the scalar step size.

Alternatives

Keeping the current code avoids any change. Binding backend methods to local names gives a little more speed, but it makes the code harder to read.

Additional context

The calls in test_entropic_semirelaxed_gromov_dtype_device[numpy], plus short extra cases, take 63.10 ms before and 51.13 ms after. The four related test files pass with 160 passed, 15 skipped and 3 expected failures. Environment: Linux x86_64, Python 3.12.13, POT 0.9.8.dev, NumPy 2.5.4, SciPy 1.18.1, one BLAS thread.

Prepared with Codex gpt-6.1-sol and Weco Observe; measurements and validation were automated.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions