bugfix: RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across
Browse files报错原因:这是因为view()需要Tensor中的元素地址是连续的,但可能出现Tensor不连续的情况,所以先用 .contiguous()。将其在内存中变成连续分布即可。
解决方案:output = self.dense(out.transpose(1, 2).contiguous().view(B, L, -1))
visual.py
CHANGED
@@ -66,7 +66,7 @@ class Attention(nn.Module):
|
|
66 |
out = attention_fn_default(
|
67 |
q, k, v
|
68 |
)
|
69 |
-
output = self.dense(out.transpose(1, 2).view(B, L, -1))
|
70 |
output = self.output_dropout(output)
|
71 |
return output
|
72 |
|
|
|
66 |
out = attention_fn_default(
|
67 |
q, k, v
|
68 |
)
|
69 |
+
output = self.dense(out.transpose(1, 2).contiguous().view(B, L, -1))
|
70 |
output = self.output_dropout(output)
|
71 |
return output
|
72 |
|