Skip to content

Commit

Permalink
bug: CUDA fix in decipher (#3110)
Browse files Browse the repository at this point in the history
@justjhong  I already fixed one of the tests (but you should review it)

close #3109

---------

Co-authored-by: Can Ergen <[email protected]>
Co-authored-by: Justin Hong <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 24, 2024
1 parent cf0af33 commit 5bd1b59
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/scvi/external/decipher/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def compute_imputed_gene_expression(
mu = self.module.decoder_z_to_x(z_loc)
mu = F.softmax(mu, dim=-1)
library_size = x.sum(axis=-1, keepdim=True)
imputed_gene_expr = (library_size * mu).detach().cpu().numpy()
imputed_gene_expr = (library_size * mu.detach().cpu()).numpy()
imputed_gene_expression_batches.append(imputed_gene_expr)
imputed_gene_expression = np.concatenate(imputed_gene_expression_batches, axis=0)

Expand Down Expand Up @@ -300,19 +300,20 @@ def compute_gene_patterns(
t_points = trajectory.trajectory_latent
t_times = trajectory.trajectory_time

t_points = torch.FloatTensor(t_points)
t_points = torch.FloatTensor(t_points).to(self.module.device)
z_mean, z_scale = self.module.decoder_v_to_z(t_points)
z_scale = F.softplus(z_scale)

z_samples = torch.distributions.Normal(z_mean, z_scale).sample(sample_shape=(n_samples,))

gene_patterns = {}
gene_patterns["mean"] = (
F.softmax(self.module.decoder_z_to_x(z_mean), dim=-1).detach().numpy() * l_scale
F.softmax(self.module.decoder_z_to_x(z_mean), dim=-1).detach().cpu().numpy() * l_scale
)

gene_expression_samples = (
F.softmax(self.module.decoder_z_to_x(z_samples), dim=-1).detach().numpy() * l_scale
F.softmax(self.module.decoder_z_to_x(z_samples), dim=-1).detach().cpu().numpy()
* l_scale
)
gene_patterns["q25"] = np.quantile(gene_expression_samples, 0.25, axis=0)
gene_patterns["q75"] = np.quantile(gene_expression_samples, 0.75, axis=0)
Expand Down

0 comments on commit 5bd1b59

Please sign in to comment.