AttributeError: 'str' object has no attribute 'contiguous'
Nevrous opened this issue · 9 comments
Traceback (most recent call last):
File "D:\UESTC\Code\Mamba4Rec-main\Mamba4Rec-main\run.py", line 45, in
flops = get_flops(model, dataset, config["device"], logger, transform)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\recbole\utils\utils.py", line 347, in get_flops
wrapper(*inputs)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\recbole\utils\utils.py", line 288, in forward
return self.model.predict(interaction)
File "D:\UESTC\Code\Mamba4Rec-main\Mamba4Rec-main\mamba4rec.py", line 91, in predict
seq_output = self.forward(item_seq, item_seq_len)
File "D:\UESTC\Code\Mamba4Rec-main\Mamba4Rec-main\mamba4rec.py", line 63, in forward
item_emb = self.mamba_layersi
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "D:\UESTC\Code\Mamba4Rec-main\Mamba4Rec-main\mamba4rec.py", line 122, in forward
hidden_states = self.mamba(input_tensor)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl
return forward_call(*args, **kwargs)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\mamba_ssm\modules\mamba_simple.py", line 146, in forward
out = mamba_inner_fn(
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\mamba_ssm\ops\selective_scan_interface.py", line 307, in mamba_inner_fn
return mamba_inner_ref(xz, conv1d_weight, conv1d_bias, x_proj_weight, delta_proj_weight,
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\mamba_ssm\ops\selective_scan_interface.py", line 323, in mamba_inner_ref
x = causal_conv1d_fn(x, rearrange(conv1d_weight, "d 1 w -> d w"), conv1d_bias, "silu")
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\causal_conv1d\causal_conv1d_interface.py", line 49, in causal_conv1d_fn
return CausalConv1dFn.apply(x, weight, bias, seq_idx, activation)
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\torch\autograd\function.py", line 553, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
File "D:\Software\Anaconda\envs\mamba2\lib\site-packages\causal_conv1d\causal_conv1d_interface.py", line 19, in forward
seq_idx = seq_idx.contiguous() if seq_idx is not None else None
AttributeError: 'str' object has no attribute 'contiguous'
The training is much slower than SASRec, I can't find the reason. My GPU is 4060 8G
In "selective_scan_interface.py " , the input missing the "seq_idx",the "None" was added by myself. Only by adding the "None" can the code run. Could you tell me the right solution.I would appreciate it if you can help me solve the problem. THX
In shows that the error is within the mamba-ssm
library. Please ensure that your mamba installation is working properly. Can you please try running a basic mamba and confirm if it executes successfully?
import torch
from mamba_ssm import Mamba
batch, length, dim = 2, 64, 16
x = torch.randn(batch, length, dim).to("cuda")
model = Mamba(
# This module uses roughly 3 * expand * d_model^2 parameters
d_model=dim, # Model dimension d_model
d_state=16, # SSM state expansion factor
d_conv=4, # Local convolution width
expand=2, # Block expansion factor
).to("cuda")
y = model(x)
assert y.shape == x.shape
I would also suggest discussing these errors within the Issues of mamba.
Q1: Is the training time normal?(ML-1M 4060 8G)
Q2:In the original code, there is no "seq_idx" in the input, but "seq_idx" is required in the function "casual_conv1d_fn". To get the code to work, I put "seq_idx=None" in the input (shown in the blue box). I would like to know how to correct this issue?
The demo you gave me needs to comment out the original code (red box) and use the modified code (blue box) to work properly. The cause of the problem is that the input of the original code lacks "seq_idx", which causes the name of the incoming activation function "silu" to be treated as "seq_idx". The error "AttributeError: 'str' object has no attribute 'contiguous'" was generated.
I will try this solution by downgrading casual_conv1d to v1.0.2, I'm currently using casual_conv1d v1.1.1 (as I can't install v1.2.0) but you need causal-conv1d >= 1.2.0, not sure if doing this will create other issues. reference: state-spaces/mamba#183
On an Nvidia A5000, each training epoch for ML-1M requires approximately 60-70 seconds. So your training time is abnormal. For the environment, I would suggest discuss and resolve any Mamba-related issues in the repository of Mamba. You can also refer to the discussions in Mamba's issues for guidance on using nn.conv or earlier versions of causal-conv1d as alternatives to causal-conv1d>=1.2.0.
Did you do the experiment on linux or windows? Thank you very much for your answer, I will try my best to try to modify it and may need to bother you again if I have any further questions. Sincerely thank you.
My experiments are conducted on a Linux server.
I also encountered the same problem. Have you finally solved it and what method did you use? Is it to assign seq_idx the value of None?
The authors of Mamba have updated their implementation, which may be the problem. If you fail to run causal_conv1d
, you can uninstall it and use nn.conv1d
as an alternative. causal_conv1d
is not a necessity in the current version of Mamba. However, I am not sure whether you can reproduce the results of Mamba4Rec if you use nn.conv1d
instead.