theislab/scarches

Runtime error using scPoli - Tensors must have same number of dimensions: got 1 and 2

Closed this issue · 2 comments

Hi,
I am trying to follow this tutorial: https://github.com/theislab/scarches/blob/master/notebooks/scpoli_surgery_pipeline.ipynb.

matplotlib==3.8.2 numpy==1.24.4 pandas==1.5.3 scArches==0.5.10 scanpy==1.9.6 scikit-learn==1.3.2 seaborn==0.13.1 torch==2.1.2

When I try to train the model I run into this error:
Traceback (most recent call last):
File "/home/lifesci/data/scPoli_test.py", line 103, in
scpoli_query.train(
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/models/scpoli/scpoli_model.py", line 307, in train
self.trainer.train(n_epochs, lr, eps)
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 298, in train
self.on_epoch_begin(lr, eps)
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 515, in on_epoch_begin
self.initialize_prototypes()
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 395, in initialize_prototypes
latent = self.get_latent_train()
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/trainers/scpoli/trainer.py", line 382, in get_latent_train
latent = self.model.get_latent(
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/models/scpoli/scpoli.py", line 354, in get_latent
z_mean, z_log_var = self.encoder(x_, embed_c)
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "/home/lifesci/miniconda3/envs/scarches_new/lib/python3.9/site-packages/scarches/models/scpoli/scpoli.py", line 459, in forward
x = torch.cat((x, batch), dim=-1)
RuntimeError: Tensors must have same number of dimensions: got 1 and 2

Has anyone run into this error and been able to fix it?

Hm, can't reproduce this. Do you just run the tutorial with the same data etc? Could you try with the latest version of scarches?

Thanks, When I try with the latest version of scarches, the problem can be solved.