-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vectorize cost and gradient for ot.da.sinkhorn_l1l2_gl
#507
Merged
rflamary
merged 15 commits into
PythonOT:master
from
kachayev:feat-sinkhorn-l1l2-vectorize-cost
Sep 21, 2023
Merged
Vectorize cost and gradient for ot.da.sinkhorn_l1l2_gl
#507
rflamary
merged 15 commits into
PythonOT:master
from
kachayev:feat-sinkhorn-l1l2-vectorize-cost
Sep 21, 2023
Conversation
This file contains 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
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #507 +/- ##
==========================================
+ Coverage 96.07% 96.08% +0.01%
==========================================
Files 65 65
Lines 13735 13784 +49
==========================================
+ Hits 13196 13245 +49
Misses 539 539 |
Tests are okay, finally. |
4 tasks
4 tasks
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
Computation of the cost and gradient callbacks for generalized conditional gradient used by
ot.da.sinkhorn_l1l2_gl
are now vectorized.One potential issue here is that
norm
function for backends were implemented as a direct computation of Euclidean 2-norm without leveraging built-innorm
s. I don't know if that was done on purpose (maybe there's a known problem with the one exposed by each library). I switched the call to make access to additional arguments, likeaxis
andkeepdims
. Still could be implemented manually here, if necessary.Motivation and context / Related issue
Overall sequential code is much harder to optimize compared to vectorized execution, specifically when working with GPUs. In this particular case, it's also easy to spot that
labels_a == lab
indices here are recomputed within nested for-loop per each call of the function (n_samples * n_labels * n_calls) despite being static. New implementation prepares matrix with proper indexing (only once) and then computes the result by leveraging normalization/summation operations on matrices defined by the corresponding backend.Also, it seems like now we can have this function working normally on JAX backend (previous version didn't work because of immutability of JAX tensors).
How has this been tested (if it applies)
New unit test
test_sinkhorn_l1l2_gl_cost_vectorized
is defined fortest_da.py
test suite. This might be not the best way to do a unit testing but for this specific use case seems fair: it just contains 2 implementations (old and new one) to make sure those function return the same result.PR checklist