Summary:
Before this pr, rsub did not convert two elements into the same dtype, therefore "1 - x" may export to an onnx model that two elements of rsub having different dtype.
By adding this symbolic patch this bug should be fixed.
Related test cases also created.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15707
Differential Revision:
D13583042
Pulled By: zrphercule
fbshipit-source-id:
3a2de47a1a8d1ded1a0adfb911adbe6ac729cdef
attribute {
name: "value"
t {
- data_type: 7
- raw_data: "\001\000\000\000\000\000\000\000"
+ data_type: 11
+ raw_data: "\000\000\000\000\000\000\360?"
}
type: TENSOR
}
model = nn.GroupNorm(3, 6)
self.run_model_test(model, train=True, input=c, batch_size=BATCH_SIZE)
+ def test_rsub(self):
+ class RsubModel(torch.nn.Module):
+ def forward(self, x):
+ return 1 - x
+
+ x = torch.randn(1, 2)
+ self.run_model_test(RsubModel(), train=False, input=(x,),
+ batch_size=BATCH_SIZE, use_gpu=False)
# a bit of metaprogramming to set up all the rnn tests
def rsub(g, self, other, alpha=None):
+ other = _maybe_get_scalar(other)
+ other = _if_scalar_type_as(g, other, self)
return sub(g, other, self, alpha=alpha)