文章目录
-
-
- 关于pytorch在训练模型时常见错误
-
- 问题1 Expected hidden[0] size (2, 32, 256), got [2, 14, 256]`
- 问题2 1D target tensor expected, multi-target not supported`
- 问题3 too many values to unpack (expected 2,3......)
- 问题4 np转int
- 问题5 unhashable type: 'numpy.ndarray
- 问题6 CUDA error: device-side assert triggered CUDA kernel errors
- 问题7 grad can be implicitly created only for scalar outputs
- 问题8 Trying to resize storage that is not resizable at ..\aten\src\TH\THStorageFunctions.cpp:76
- 问题9 view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
- 问题10 Caught KeyError in DataLoader worker process 0.Original Traceback (most recent call last):
- 问题11 can only concatenate str (not "list") to str
- 问题12 TextEncodeInput must be Union[TextInputSequence, Tuple[InputSequence, InputSequence]]
- 问题13 No module named 'sentencepiece'
- 问题14 ValueError: too many values to unpack (expected 2)
- 问题13 Found dtype Long but expected Float
- 问题14 one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [1024]] is at version 4; expected version 2 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!
-
关于pytorch在训练模型时常见错误
问题1 Expected hidden[0] size (2, 32, 256), got [2, 14, 256]`
【Pytorch】Expected hidden[0] size (2, 32, 256), got [2, 14, 256]
错误原因:
训练数据不能被批量大小整除造成的。
改正方法:
- 修改batchsize,让数据集大小能整除batchsize
- 如果使用Dataloader,设置一个参数drop_last=True,会自动舍弃最后不足batchsize的batch
问题2 1D target tensor expected, multi-target not supported`
1D target tensor expected, multi-target not supported
错误原因:
计算交叉熵时shape