YubiaoYue / MedMamba

This is the official code repository for "MedMamba: Vision Mamba for Medical Image Classification"
297 stars 24 forks source link

Selective Scan Import Issue #3

Open MarioPaps opened 6 months ago

MarioPaps commented 6 months ago

Hello,

I made a new environment and installed Pytorch 2.1 with cuda 11.8, alongside the recommended causal-conv1d and mamba-ssm. However, the model does not train because of 'selective_scan'. Could you help me with this?

This is the full error: Traceback (most recent call last): File "/rds/general/user/kp4718/home/code/MedMamba/trainpynew.py", line 129, in main() File "/rds/general/user/kp4718/home/code/MedMamba/trainpynew.py", line 88, in main outputs = net(images) ^^^^^^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/code/MedMamba/MedMamba.py", line 734, in forward x = self.forward_backbone(x) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/code/MedMamba/MedMamba.py", line 730, in forward_backbone x = layer(x) ^^^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(*args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/code/MedMamba/MedMamba.py", line 570, in forward x = blk(x) ^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/code/MedMamba/MedMamba.py", line 503, in forward x = input_right + self.drop_path(self.self_attention(self.ln_1(input_right))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/anaconda3/envs/cleanmamba/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl return forward_call(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/code/MedMamba/MedMamba.py", line 464, in forward y1, y2, y3, y4 = self.forward_core(x) ^^^^^^^^^^^^^^^^^^^^ File "/rds/general/user/kp4718/home/code/MedMamba/MedMamba.py", line 379, in forward_corev0 self.selective_scan = selective_scan_fn ^^^^^^^^^^^^^^^^^ NameError: name 'selective_scan_fn' is not defined

YubiaoYue commented 6 months ago

Hello! A reliable solution is to upgrade Cuda's version to 12.0 and then reinstall mamba-ssm.

MarioPaps commented 5 months ago

I figured out that I have to use a different version of causal conv1d and mamba-ssm for cuda 11.8 to work.

MarioPaps commented 5 months ago

I think you need to change the recommended versions in the description. Also, it's not possible to use torch 1.13 with cuda 11.8 according to pip

YubiaoYue commented 5 months ago

Thank you for the reminder! I will change the description.

MarioPaps commented 5 months ago

FYI, I used causal conv1d version 1.1.0 and mamba-ssm version 1.1.0 on cuda 11.8. The code runs fine in a Linux cluster on this setup. To use the latest versions, we need careful experimentation, which I have not done yet.

CrineCS commented 1 month ago

FYI, I used causal conv1d version 1.1.0 and mamba-ssm version 1.1.0 on cuda 11.8. The code runs fine in a Linux cluster on this setup. To use the latest versions, we need careful experimentation, which I have not done yet.

May I know your torch and torchvision version in this model? I'm using cuda 11.8 too.

MarioPaps commented 1 month ago

My versions are: torch 2.0.0+cu118 torchvision 0.15.1+cu118 torchaudio 2.0.1+cu118

CrineCS commented 1 month ago

My versions are: torch 2.0.0+cu118 torchvision 0.15.1+cu118 torchaudio 2.0.1+cu118

Thanks a lot.