Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
connorclouddevine opened this issue Nov 12, 2024 · 1 comment

Comments

@connorclouddevine
Copy link

connorclouddevine commented Nov 12, 2024

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_tissue_cluster/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:

  • defaults
    dependencies:
  • python=3.12.2
  • pytorch=2.4.1
  • leidenalg=0.10.2
  • python-igraph=0.11.6
  • scanpy=1.10.3
  • scikit-learn=1.5.2
  • numpy=1.26.4
    '''

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

@connorclouddevine
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant