-
Notifications
You must be signed in to change notification settings - Fork 223
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
Input type (torch.FloatTensor) and weight type (torch.cuda.HalfTensor) should be the same or input should be a MKLDNN tensor and weight is a dense tensor #84
Comments
Hi Nanjun, This typically means your input and model are not on the same device (i.e., one on CPU, another on GPU), which can be solved by device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
input = model.to(device) May I ask which demo script you are running? We have a colab demo at https://colab.research.google.com/github/YuanGongND/ast/blob/master/colab/AST_Inference_Demo.ipynb, which should be bug-free. -Yuan |
Dear Yuan, The file I run was src/demo.py, I also run the jupyter notbook demo and didn't have this issue. Best Regards, |
And this error is still there after I set both the model and input to cuda. |
What if you run the jupyter script with your environment instead of the Google Colab one? If no error, then it's not your environment's problem. |
I also think setting the pretrain flag could also help:
|
I failed to run the Jupiter script on my local machine, it said it can't find the path '/content/ast/', seems my IDE failed to connect to colab. |
Yes, you need to change the filepath and maybe something else to run on local machine. |
Thank you it solves the issue and may I know why? |
I think this again means your input and model are not in the same device. Which specific method solved your issue? |
|
The reason is it avoids the pretrained weights being load to cpu. No one reported this issue before about the input/model device, maybe not many people actually ran this demo. But since you have GPU, you could try run ESC-50 recipe and see if the error still there. I don't think cuda/torch version is the problem. |
I tried it on another machine. it was not reproduced. |
But changed line 132 in ast_models.py to |
In the previous machine, the error can still be reproduced by applying the workaround. |
I see, it is a bit weird to me. Thanks for reporting this. I actually don't think Let's see if anyone else has the same issue. |
Dear Yuan,
I met this issue when running the demo.py, it occurred in line 29, ast_models.py,
self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)
with error msg as followed:
Input type (torch.FloatTensor) and weight type (torch.cuda.HalfTensor) should be the same or input should be a MKLDNN tensor and weight is a dense tensor.
Would you like to have a look at it?
I use 👍
timm=0.4.5
torch = 1.10.1+cu102
torchaudio = 0.10.1+cu102
torchvision = 0.11.2+cu102
Thank you
Best Regards,
Nanjun
The text was updated successfully, but these errors were encountered: