Repository navigation
[MRG] Check for device mismatch with a meta default device and fix bare allocations (#852) - #883
Open
raashish1601 wants to merge 2 commits into
Open
raashish1601 wants to merge 2 commits into
raashish1601 wants to merge 2 commits into
Conversation
This branch has not been deployed
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
Bug fix and tests.
Motivation and context / Related issue
Closes #852.
This adds the
meta_default_devicefixture suggested in the issue. It sets the torch default device tometafor the test and puts it back afterwards. Inputs are built withtorch.from_numpy, so they stay on CPU, and any array a solver creates withouttype_asends up onmetaand raises a device error. That is the same failure you get with GPU inputs, but it shows up on CPU-only CI.test/test_device.pyruns this check on a list of functions. Besides a few solvers that already worked (emd, sinkhorn, unbalanced sinkhorn,ot.solve*, 1D), it found these bare allocations, which this PR fixes by passingtype_as:ot.partial.partial_wasserstein/partial_wasserstein2: zero blocks of the extended cost matrixot.binary_search_circle, so alsoot.wasserstein_circleandot.sliced_wasserstein_sphere: thedonemaskot.gaussian.bures_wasserstein_mapping_hdandbures_wasserstein_distance_hd:nx.eye(p)ot.gmm.gmm_pdf,gmm_ot_apply_map(both methods) andgmm_ot_plan_densityot.lowrank_sinkhornwithinit="deterministic": the initialgot.gromov.semirelaxed_gromov_barycenters/semirelaxed_fgw_barycenters: defaultlambdasot.utils.projection_sparse_simplex: the indexaranges andz. The index aranges use an integer array astype_asso they stay integer even ifarangestarts following the dtype oftype_as(Backend.arange(..., type_as=...) silently ignores type_as for dtype (and device, in some backends) #864).I did not cover every function in the library here. The fixture makes it easy to add more cases to the list later.
How has this been tested (if it applies)
The new test fails for 12 of the 20 cases on master and passes with the fix. I also ran
test_utils.py,test_gmm.py,test_gaussian.py,test_partial.py,test_circle_solver.py,test_lowrank.py,test_ot.py,test_solvers.py,test/gromovandtest/slicedwith the numpy and torch backends (CPU), andpre-commiton the changed files.PR checklist