Skip to content

Commit

Permalink
set rng device (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordabayevy authored May 22, 2024
1 parent 3b61899 commit 54b827f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cellarium/ml/models/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def __init__(
self.log_metrics = log_metrics

def reset_parameters(self) -> None:
rng = torch.Generator()
rng_device = self.W_gc.device.type if self.W_gc.device.type != "meta" else "cpu"
rng = torch.Generator(device=rng_device)
rng.manual_seed(self.seed)
self.W_prior_scale.fill_(self._W_prior_scale)
self.W_gc.data.normal_(0, self.W_init_scale, generator=rng)
Expand Down
3 changes: 2 additions & 1 deletion cellarium/ml/models/probabilistic_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def __init__(
self.reset_parameters()

def reset_parameters(self) -> None:
rng = torch.Generator()
rng_device = self.W_kg.device.type if self.W_kg.device.type != "meta" else "cpu"
rng = torch.Generator(device=rng_device)
rng.manual_seed(self.seed)
if isinstance(self.mean_g, torch.nn.Parameter):
self.mean_g.data.zero_()
Expand Down

0 comments on commit 54b827f

Please sign in to comment.