Conversation
Adds solver='torch' to wda: PyTorch autodiff with Riemannian gradient descent on the Stiefel manifold, using a QR retraction and backtracking with an adaptive initial step. It mirrors what pymanopt's SteepestDescent does, so both solvers target the same optimum rather than two different algorithms. The torch path needs only torch, so it works on installations without autograd or pymanopt, and accepts torch tensors directly, keeping their device and dtype. To make that possible, ot.dr's dependencies are now imported optionally and each function raises an ImportError naming what it needs, rather than the module failing to import unless all of them are present. Verified that the torch objective and its gradient match the autograd ones at the same point, and that both solvers reach a comparable objective from the same starting point. Also raises a clear ValueError when the between-class transport cost underflows to zero, which previously produced a divide-by-zero warning and an undefined objective.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #858 +/- ##
==========================================
- Coverage 96.85% 96.64% -0.21%
==========================================
Files 128 128
Lines 26161 26384 +223
==========================================
+ Hits 25337 25499 +162
- Misses 824 885 +61 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
New feature (non-breaking change which adds functionality).
Motivation and context / Related issue
Addresses #806, following @rflamary's request for
solver='torch'alongside the defaultsolver='autograd'.solver='torch'runs PyTorch autodiff with Riemannian gradient descent on Stiefel — QR retraction, backtracking with an adaptive initial step — mirroring pymanopt'sSteepestDescentso both solvers target the same optimum. It needs only torch, and accepts torch tensors directly, keeping device and dtype.ot.drdependencies are now imported optionally, each function raising anImportErrornaming what it needs. This changesimport ot.drfrom raising to succeeding on a partial install — flagging it in case you prefer the old behaviour.On speed: pymanopt is 0.6–1.8% of runtime and this solver is 1.0–1.75× faster, so the dependency choice is the real benefit. A frozen-plan gradient for a larger win stalls at a worse objective; numbers on the issue.
Also raises a clear
ValueErrorwhen the between-class cost underflows to zero, previously a divide-by-zero.How has this been tested (if it applies)
New tests assert the torch objective and gradient match the autograd ones (rtol 1e-10, 1e-8) and that both solvers reach a comparable objective from the same start; ratio 0.997–1.004 across n, k, C and
sinkhorn_method. Also covered: tensor input dtype,sinkhorn_log, input not mutated, error path.test_dr.py16 passed; full suite 2668 passed, 62 skipped, 6 xfailed; pre-commit clean.PR checklist