打印tensor数据出现如下错误:
print(output)
File "/home/qin/anaconda3/envs/Center/lib/python3.6/site-packages/torch/tensor.py", line 179, in __repr__
return torch._tensor_str._str(self)
File "/home/qin/anaconda3/envs/Center/lib/python3.6/site-packages/torch/_tensor_str.py", line 372, in _str
return _str_intern(self)
File "/home/qin/anaconda3/envs/Center/lib/python3.6/site-packages/torch/_tensor_str.py", line 352, in _str_intern
tensor_str = _tensor_str(self, indent)
File "/home/qin/anaconda3/envs/Center/lib/python3.6/site-packages/torch/_tensor_str.py", line 241, in _tensor_str
formatter = _Formatter(get_summarized_data(self) if summarize else self)
File "/home/qin/anaconda3/envs/Center/lib/python3.6/site-packages/torch/_tensor_str.py", line 89, in __init__
nonzero_finite_vals = torch.masked_select(tensor_view, torch.isfinite(tensor_view) & tensor_view.ne(0))
RuntimeError: CUDA error: an illegal memory access was encountered
terminate called after throwing an instance of 'c10::Error'
代码如下:
for layer in self.layers:
output = layer(output, pos, reference_points, spatial_shapes, padding_mask)
六层encoder,第五层的output打印出错
原因:
output第五层变成了0
https://discuss.pytorch.org/t/runtimeerror-cuda-error-an-illegal-memory-access-was-encountered-autograd/85282/9