Skip to content

Commit

Permalink
🐞 Fix mps float64 tensor conversion issue (#1644)
Browse files Browse the repository at this point in the history
Fix leftover
  • Loading branch information
samet-akcay authored Jan 17, 2024
1 parent 7587d88 commit 5220f69
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _sparse_random_matrix(self, n_features: int) -> torch.Tensor:

else:
# Sparse matrix is not being generated here as it is stored as dense anyways
components = torch.zeros((self.n_components, n_features), dtype=torch.float64)
components = torch.zeros((self.n_components, n_features), dtype=torch.float32)
for i in range(self.n_components):
# find the indices of the non-zero components for row i
nnz_idx = torch.distributions.Binomial(total_count=n_features, probs=density).sample()
Expand All @@ -89,11 +89,11 @@ def _sparse_random_matrix(self, n_features: int) -> torch.Tensor:
n_samples=nnz_idx,
random_state=self.random_state,
),
dtype=torch.int64,
dtype=torch.int32,
)
data = torch.distributions.Binomial(total_count=1, probs=0.5).sample(sample_shape=c_idx.size()) * 2 - 1
# assign data to only those columns
components[i, c_idx] = data.double()
components[i, c_idx] = data

components *= np.sqrt(1 / density) / np.sqrt(self.n_components)

Expand Down

0 comments on commit 5220f69

Please sign in to comment.