BayraktarLab / cell2location

Comprehensive mapping of tissue cell architecture via integrated single cell and spatial transcriptomics (cell2location model)
https://cell2location.readthedocs.io/en/latest/
Apache License 2.0
324 stars 58 forks source link

RuntimeError: PyTorch is not linked with support for mps devices #209

Closed SunYong0821 closed 1 year ago

SunYong0821 commented 2 years ago

I run two spatial samples with same method and py, one successed, the other one failed with RuntimeError: PyTorch is not linked with support for mps devices

detailed:

Epoch 20000/20000: 100%|██████████| 20000/20000 [12:31:38<00:00,  2.25s/it, v_num=1, elbo_train=1.82e+7]
Sampling local variables, batch:   0%|          | 0/1 [00:00<?, ?it/s]
File "/home/ksd/bin/Python-3.10.4/lib/python3.10/site-packages/cell2location/models/_cell2location_model.py", line 338, in export_posterior
  self.samples = self.sample_posterior(**sample_kwargs)
File "/home/ksd/bin/Python-3.10.4/lib/python3.10/site-packages/scvi/model/base/_pyromixin.py", line 483, in sample_posterior
  samples = self._posterior_samples_minibatch(
File "/home/ksd/bin/Python-3.10.4/lib/python3.10/site-packages/scvi/model/base/_pyromixin.py", line 365, in _posterior_samples_minibatch
  args = [a.to(device) for a in args]
File "/home/ksd/bin/Python-3.10.4/lib/python3.10/site-packages/scvi/model/base/_pyromixin.py", line 365, in <listcomp>
  args = [a.to(device) for a in args]
RuntimeError: PyTorch is not linked with support for mps devices

my code is failed on this step:

adata_vis = mod.export_posterior(adata_vis, sample_kwargs={'num_samples': 1000, 'batch_size': mod.adata.n_obs, 'use_gpu': True})
vitkl commented 2 years ago

Is this error reproducible? What happens if you train the model again or simply restart the notebook and load the model?

SunYong0821 commented 2 years ago

Is this error reproducible? What happens if you train the model again or simply restart the notebook and load the model?

no,i finally found it must be run one by one,may be CPU is not enough, but my cpu is 72C 144T

vitkl commented 1 year ago

What do you mean by "run one by one"? You can also try changing batch size for mod.export_posterior

stupidstupidstupidstupid commented 1 year ago

It 's a CPU problem. You must set 'use_gpu' as false