CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling cublasCreate(handle)
Full error message
I got the following error when I ran my PyTorch deep learning model in Google Colab /usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in linear(input, weight, bias) 1370 ret = torch.addmm(bias, input, weight.t()) 1371 else: -> 1372 output = input.matmul(weight.t()) 1373 if bias is not None: 1374 output += bias RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)` I even reduced batch size from 128 to 64 i.e., reduced to half, but still, I got this error. Earlier, I ran the same code with a batch size of 128 but didn't get any error like this.
Solutionsource: stackoverflow \u2197
No, batch size does not matter in this case. The most likely reason is that there is an inconsistency between number of labels and number of output units. Try printing the size of the final output in the forward pass and check the size of the output print(model.fc1(x).size()) Here fc1 would be replaced by the name of your model's last linear layer before returning Make sure that label.size() is equal to prediction.size() before calculating the loss And even after fixing that problem, you'll have to restart the GPU runtime (I needed to do this in my case when using a Colab GPU) This GitHub issue comment might also be helpful.
API access
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/1ca449d9033480d710bd0bd9690fab2d3c1d887a4d83fb6d736c33da0b9f61e6hash \u00b7 1ca449d9033480d710bd0bd9690fab2d3c1d887a4d83fb6d736c33da0b9f61e6