Pytorch use error
Cause analysis and solution of error content
Error content
RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor
Cause analysis
Because I use a higher version of torch 1.7.1, this error is caused by the upgrade of torch 1.5 or above bilstm.
Solution
- go to the CPU to run the code and no error will be reported! Convert the error location parameter
lengths
to CPU
type: OL>
lengths.to("cpu")
It can be solved!
Reference: link
Read More:
- Python learning notes (5) — cross entropy error runtimeerror: 1D target tensor expected, multi target not supported
- RuntimeError: log_vml_cpu not implemented for ‘Long’
- [Solved] RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 ‘mat1‘
- Solve the runtimeerror in RNN: expected scalar type long but found float error
- RuntimeError:cuda runtime error (11) : invalid argument at /pytorch/aten/src/THC/generic
- Problem: attributeerror: ‘tensor’ object has no attribute ‘creator’
- RuntimeError: NCCL error in: /pytorch/torch/lib/c10d/ProcessGroupNCCL.cpp:784 torch
- Create a D3D11 application process
- RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- The solution of push D command execution error (/ bin / sh: 1: push D: not found) on Ubuntu
- TypeError: __array__() takes 1 positional argument but 2 were given
- [solved] error: valueerror: expected 2D array, got scalar array instead
- RuntimeError: “unfolded2d_copy“ not implemented for ‘Half‘
- AttributeError: ‘Tensor‘ object has no attribute ‘_numpy‘
- FCOS No CUDA runtime is found, using CUDA_HOME=’/usr/local/cuda-10.0′
- ValueError: num_samples should be a positive integer value, but got num_samp=0
- [Solved] emulator: glteximage2d: got err pre 🙁 0x502 internal 0x1908 format 0x1908 type 0x1401
- Tensorflow ValueError: Failed to convert a NumPy array to a Tensor
- (29)RuntimeError: cuda runtime error (999)
- RuntimeError: cuda runtime error (801) : operation not supported at ..