Explain the function of static keyword and final keyword in Java in detail>>>
Python run error: runtimeerror: cudnn error: cudnn_ STATUS_ INTERNAL_ ERROR
Solution:
Add:
torch.cuda.set_device(0)
Nan solution for training RNN network loss
(1) The cause of gradient explosion can be solved by gradient ruling
GRAD_CLIP = 5 loss.backward() torch.nn.utils.clip_grad_norm_(model.parameters(), GRAD_CLIP) optimizer.step()
(2) Testmodel and evaluate
with torch.no_grad():
(3) Lower the learning rate
RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 ‘self’ in call to _ th_ addmm
There are three places in the code that need CUDA () conversion:
Whether the model is placed on CUDA model = model. To (device)
Whether the input data is put on CUDA data = data. To (device)
Whether the new tensor in the model is placed on CUDA P = torch. Tensor ([1]). To (device)
0
In the first article, model = model. To (device) is only instantiated in model__ init__() If instantiated in forward and used directly, the model will not be placed in CUDA
Here is an error code:
import torch
import torch.nn as nn
data = torch.rand(1, 10).cuda()
class TestMoule(nn.Module):
def __init__(self):
super(TestMoule, self).__init__()
# self.linear = torch.nn.Linear(10, 2)
def forward(self, x):
# return self.linear(x)
return torch.nn.Linear(10, 2)(x)
model = TestMoule()
model = model.cuda()
print(model(data))
RuntimeError: CUDA error: an illegal memory access was encountered
One of the above problems is that some functions under the NN module pass in GPU type data, with the following error code:
import torch
data = torch.randn(1, 10).cuda()
layernorm = torch.nn.LayerNorm(10)
# layernorm = torch.nn.LayerNorm(10).cuda()
re_data = layernorm(data)
print(re_data)
RuntimeError: CUDA error: device-side assert triggered
The category target of classification is not one-to-one corresponding to the softmax value of model output
Targets is a value of 1-3, but softmax calculates a value of 0-2, so the above error is prompted
df = pd.read_csv('data/reviews.csv')
def to_sentiment(score):
score = int(score)
if score <= 2:
return 0
elif score == 3:
return 1
else:
return 2
df['sentiment'] = df.score.apply(to_sentiment)
Similar Posts:
- Error in loading pre training weight in torch. Load() in pytorch
- [Solved] RuntimeError: Attempting to deserialize object on CUDA device 2 but torch.cuda.device_count() is 1
- Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same
- [Solved] RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
- PyTorch UserWarning: volatile was removed and now has no effect. Use `with torch.no_grad():` inst
- [Solved] torch.cuda.CudaError: CUDA driver version is insufficient for CUDA runtime version (35) [ WARN:0
- Runtimeerror: CUDA error: out of memory [How to Solve]
- [Solved] RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
- [Solved] pytorchImportError: numpy.core.multiarray failed to import
- RuntimeError: cuda runtime error (30) : unknown errorr