Python Pytorch:嵌入层后,无法获取<;的repr;类别';火炬张量'&燃气轮机;

Python Pytorch:嵌入层后,无法获取<;的repr;类别';火炬张量'&燃气轮机;,python,pytorch,embedding,Python,Pytorch,Embedding,我是PyTorch的新手,正在尝试复制该项目: 但是,feedforward()中出现了错误,这几天来一直困扰着我,下面是部分代码(有关模型的完整代码,请参阅): 这给了我一个错误(我正在使用GPU): THCudaCheck失败文件=/pytorch/aten/src/THC/generic/THCTensorMath.cu line=196错误=710:设备端断言已触发 回溯(最近一次呼叫最后一次): 文件“main.py”,第147行,在 main() 文件“main.py”,第136行,

我是PyTorch的新手,正在尝试复制该项目:

但是,
feedforward()
中出现了错误,这几天来一直困扰着我,下面是部分代码(有关模型的完整代码,请参阅):

这给了我一个错误(我正在使用GPU):

THCudaCheck失败文件=/pytorch/aten/src/THC/generic/THCTensorMath.cu line=196错误=710:设备端断言已触发
回溯(最近一次呼叫最后一次):
文件“main.py”,第147行,在
main()
文件“main.py”,第136行,在main中
模型=运行元增量(配置、模型、训练批处理程序、测试批处理程序)
文件“/home/yonghui/yt/meta_incr_training.py”,第158行,在run_meta_增量中
g=运行内部(配置、模型、任务)
文件“/home/yonghui/yt/meta_incr_training.py”,第120行,运行内部
pred=模型向前(e1,rel)
文件“/home/yonghui/yt/models.py”,第136行,前进
堆叠输入=火炬。cat([e1_嵌入,rel_嵌入],2)
RuntimeError:cuda运行时错误(710):在/pytorch/aten/src/THC/generic/THCTensorMath.cu:196触发设备端断言
/pytorch/aten/src/THC/THCTensorIndex.cu:361:void indexSelectLargeIndex(TensorInfo,TensorInfo,TensorInfo,int,int,int,IndexType,IndexType,long)[T=float,IndexType=unsigned int,DstDim=2,SrcDim=2,IdxDim=-2,indexmajor=true]:块:[189,0,0,0]线程:[0,0]断言` srindex
我使用调试器试图找出哪里出错: 在嵌入
e1
rel
之前,它们都是
int64
中的张量,形状为
torch.Size([128,1])

e1
可以正常嵌入,转换为
torch.float32
torch.Size([128,1,10,20])
。但是,在
rel
通过
emb_rel
的嵌入层后,调试器将所有TENRO显示为
无法获取
的repr


发生什么事了?我怎样才能解决这个问题?谢谢你的帮助

错误在打印此错误消息之前的某个地方,可能是在整形过程中

调用视图不会更改基础数据,它只会更改基础数据的“视图”,而且是惰性的。如果不可能使用张量的不同视图(例如,因为张量未连续存储在内存中,参见),则在第一次使用张量内容时(在您想要调试打印张量的情况下)会失败


调试时,考虑使用<代码>改写(参见,).< /P> < P > >使用调试器和检查输入张量解决此问题。


在嵌入前检查张量后,我发现一些元素超出了范围,尤其是索引从0开始的情况。

谢谢您提供这样的信息:)但是在我将
视图更改为
重塑后,错误没有改变,那么我建议你试试你能打印的最后一个张量是什么。这应该是你的bug出现之前的时刻。谢谢你的建议,我也尝试过将它转换为CPU版本,调试器的信息更加直观,在嵌入层中索引超出了它的范围。再次感谢您的帮助。:)
def forward(self, e1, rel, batch_size=None, weights=None):
......
        e1_embedded = self.emb_e(e1).view(-1, 1, 10, 20)
        rel_embedded = self.emb_rel(rel).view(-1, 1, 10, 20)
        stacked_inputs = torch.cat([e1_embedded, rel_embedded], 2)  # out: (128L, 1L, 20L, 20L)
THCudaCheck FAIL file=/pytorch/aten/src/THC/generic/THCTensorMath.cu line=196 error=710 : device-side assert triggered
Traceback (most recent call last):
  File "main.py", line 147, in <module>
    main()
  File "main.py", line 136, in main
    model = run_meta_incremental(config, model, train_batcher, test_rank_batcher)
  File "/home/yonghui/yt/meta_incr_training.py", line 158, in run_meta_incremental
    g = run_inner(config, model, task)
  File "/home/yonghui/yt/meta_incr_training.py", line 120, in run_inner
    pred = model.forward(e1, rel)
  File "/home/yonghui/yt/models.py", line 136, in forward
    stacked_inputs = torch.cat([e1_embedded, rel_embedded], 2)
RuntimeError: cuda runtime error (710) : device-side assert triggered at /pytorch/aten/src/THC/generic/THCTensorMath.cu:196
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [0,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [1,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [2,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [3,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [4,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [5,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [6,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
/pytorch/aten/src/THC/THCTensorIndex.cu:361: void indexSelectLargeIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2, IndexIsMajor = true]: block: [189,0,0], thread: [7,0,0] Assertion `srcIndex < srcSelectDimSize` failed.