RuntimeError: CUDA त्रुटि: डिवाइस साइड मुखर ट्रिगर

Runtimeerror Cuda Error



मॉडल को प्रशिक्षित किया गया था और अचानक एक त्रुटि की सूचना दी। मुझे समस्या नहीं मिली। मैंने बस त्रुटि को पुन: पेश किया। इंटरनेट पर यह कहा जाता है कि torch.nn.functional.F के क्रॉस_एंट्रॉपी के इनपुट और लक्ष्य के साथ एक समस्या है। लक्ष्य सूचकांक गलत है। 1,2], निम्नानुसार है: लक्ष्य है [1,2,3] और [2,3,0] ठीक हैं, [1,2,100] और [99,100,101] सही नहीं हैं, यह अभी तक पता नहीं लगा है, पहले याद रखें ।

[१] https://blog.csdn.net/littlehaes/article/details/102806323

[दो] https://blog.csdn.net/qq_27292549/article/details/81084782



[३] बहु-वर्ग क्रॉस एन्ट्रापी की गणना: https://www.cnblogs.com/jclian91/p/9376117.html



[४] लक्ष्य लेबल में एक अवैध मूल्य दिखाई देता है: https://www.cnblogs.com/geoffreyone/p/10653619.html

>>> import torch >>> import torch.nn.functional.F as F >>> input = torch.randn(3, 5, requires_grad=True) >>> target = torch.randint(5, (3,), dtype=torch.int64) >>> input tensor([[-1.5579, 0.5080, 0.1069, 0.7945, 0.4689], [-2.9727, 0.3491, -1.2172, -0.0223, 1.2733], [-0.2269, -1.1830, -0.8604, 1.2835, 1.2629]], requires_grad=True) >>> target tensor([2, 3, 0]) >>> loss = F.cross_entropy(input, target) >>> loss tensor(2.0206, grad_fn=) >>> input2 = torch.randn(4, 5, requires_grad=True) >>> lossloss = F.cross_entropy(input, target) >>> loss=F.cross_entropy(input2, target) Traceback (most recent call last): File '', line 1, in File '/home/cmz/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py', line 2056, in cross_entropy return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction) File '/home/cmz/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py', line 1869, in nll_loss .format(input.size(0), target.size(0))) ValueError: Expected input batch_size (4) to match target batch_size (3). >>> import numpy as np >>> target tensor([2, 3, 0]) >>> t=np.array([99,100,101]) >>> tt=torch.from_numpy(t) >>> tt tensor([ 99, 100, 101]) >>> loss = F.cross_entropy(input, tt) Traceback (most recent call last): File '', line 1, in File '/home/cmz/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py', line 2056, in cross_entropy return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction) File '/home/cmz/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py', line 1871, in nll_loss ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index) RuntimeError: Assertion `cur_target >= 0 && cur_target >> t=np.array([1,2,3]) >>> ttt=torch.from_numpy(t) >>> ttt tensor([1, 2, 3]) >>> loss = F.cross_entropy(input, ttt) >>> t=np.array([1,2,100]) >>> ttt=torch.from_numpy(t) >>> loss = F.cross_entropy(input, ttt) Traceback (most recent call last): File '', line 1, in File '/home/cmz/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py', line 2056, in cross_entropy return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction) File '/home/cmz/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py', line 1871, in nll_loss ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index) RuntimeError: Assertion `cur_target >= 0 && cur_target