xianglin226 / scMDC

Single Cell Multi-omics deep clustering
Apache License 2.0
24 stars 4 forks source link

RuntimeError: mat1 and mat2 must have the same dtype, but got Double and Float #15

Open connorclouddevine opened 2 weeks ago

connorclouddevine commented 2 weeks ago

Hi,

I wasn't able to find channels for some of the dependencies you specified so I'm running scMDC in an environment with newest package versions. When I perform run_scMDC_batch.py I do not get this error. When I perform run_scMDC.py: ''' python -u ./scMDC/scMDC/src/run_scMDC.py \ --data_file error_test_set.h5 \ --save_dir error_test_out \ --embedding_file --prediction_file \ --batch_size 256 \ --device cpu \ --no_labels \ --n_clusters 5 '''

I get the following error after the pre-training stage: ''' Pretrain epoch 391, Total loss:14.063442, ZINB loss1:5.921021, ZINB loss2:8.142051, KL loss:0.370482 Pretraining time: 149 seconds. Traceback (most recent call last): File "/pool0/scratch/devine/YG_tissue_cluster/./scMDC/scMDC/src/run_scMDC.py", line 145, in latent = model.encodeBatch(torch.tensor(adata1.X).to(args.device), torch.tensor(adata2.X).to(args.device)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/pool0/scratch/devine/YG_tissuecluster/scMDC/scMDC/src/scMDC.py", line 146, in encodeBatch z,,,,,,,,_ = self.forwardAE(inputs1, inputs2) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/pool0/scratch/devine/YG_tissue_cluster/scMDC/scMDC/src/scMDC.py", line 116, in forwardAE h = self.encoder(x) ^^^^^^^^^^^^^^^ File "/scratch/devine/envs/.conda/envs/scMDC/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/scratch/devine/envs/.conda/envs/scMDC/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl return forward_call(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/scratch/devine/envs/.conda/envs/scMDC/lib/python3.12/site-packages/torch/nn/modules/container.py", line 219, in forward input = module(input) ^^^^^^^^^^^^^ File "/scratch/devine/envs/.conda/envs/scMDC/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1553, in _wrapped_call_impl return self._call_impl(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/scratch/devine/envs/.conda/envs/scMDC/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1562, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/scratch/devine/envs/.conda/envs/scMDC/lib/python3.12/site-packages/torch/nn/modules/linear.py", line 117, in forward return F.linear(input, self.weight, self.bias) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: mat1 and mat2 must have the same dtype, but got Double and Float '''

The error is reproducible using the following code block: ''' np.random.seed(123) with h5py.File('error_test_set.h5', 'w') as f: f.create_dataset('X1', data=np.random.randint(low=1, high=300, size=(3148, 512)).astype(np.float64)) f.create_dataset('X2', data=np.random.randint(low=1, high=1000, size=(3148, 18)).astype(np.float64)) '''

and my environment package versions are listed here (should be most current): ''' name: scMDC channels:

Would love to be able to deploy this algorithm, let me know how to proceed, thanks!

connorclouddevine commented 1 week ago

I'm hoping there's a small rewrite I can make so it's compatible with my (newer) package versions.

Otherwise, a working YAML file would be great.

xianglin226 commented 1 day ago

Hi, thank you so much for trying our method, and I apologize for the delayed response. I believe this is a common issue that we often encounter. Have you tried setting a consistent dtype for both mat1 and mat2, such as float32?