[MRG] Fix device placement in batch Sinkhorn (solve_batch on GPU) - #851
Open
tomMoral wants to merge 4 commits into
Open
[MRG] Fix device placement in batch Sinkhorn (solve_batch on GPU)#851tomMoral wants to merge 4 commits into
tomMoral wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #851 +/- ##
==========================================
- Coverage 96.85% 96.84% -0.01%
==========================================
Files 128 128
Lines 26160 26195 +35
==========================================
+ Hits 25337 25369 +32
- Misses 823 826 +3 🚀 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
Motivation and context / Related issue
ot.solve_batch(M, reg=..., method="sinkhorn")crashes on GPU withwhenever the torch default device is CPU while the inputs are on CUDA. In
bregman_projection_batch, the scaling vectorsf/gwere allocated with abare
nx.ones((B, n)), so they landed on the default (CPU) device and clashedwith the GPU
Kon the first iteration. The log-domain and proximal solverswere unaffected (their
u/vinits already usetype_as).Reproduced and both the fix and the refactor verified on an NVIDIA V100S
(torch 2.6.0+cu118): all batch paths now run on
cuda:0, and a marginal passedon the wrong device now raises a clear
assert_same_dtype_deviceerror insteadof a deep
RuntimeError.How has this been tested (if it applies)
test_solve_batch_deviceexercises every method on each available device.test_unif_shape/test_check_marginalcover the utility additions.Description
Two commits:
f/g(and the defaulta/b) the input backend/device viatype_asinbregman_projection_batch.if a is None: a = nx.ones(...) / nidiom was duplicatedacross all five batch solvers (each an opportunity to forget
type_as).Add
ot.utils.check_marginal(fills a uniform marginal on the inputs'backend/device when
None, otherwise validates shape + dtype/device), extendot.utils.unifto accept a shape tuple (normalized over the last axis, fullybackward compatible), and route all five sites through
check_marginal.PR checklist
🤖 Generated with Claude Code