8000 [ONNX] Enable test_fill script test by shubhambhokare1 · Pull Request #79555 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[ONNX] Enable test_fill script test #79555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion test/onnx/test_pytorch_onnx_onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11393,7 +11393,6 @@ def forward(self, x, y):
self.run_test(M_ToDeviceDtype(), (x, y))

@skipIfUnsupportedMinOpsetVersion(9)
@skipScriptTest()
def test_fill(self):
class FillModule(torch.nn.Module):
def forward(self, x, filled_value: int):
Expand All @@ -11403,6 +11402,14 @@ def forward(self, x, filled_value: int):
filled_value = 7
self.run_test(FillModule(), (x, filled_value))

class FillFloatModule(torch.nn.Module):
def forward(self, x, filled_value: float):
return x.fill_(filled_value)

x = torch.randn((4, 5, 6))
filled_value = 7.5
self.run_test(FillFloatModule(), (x, filled_value))

class FillScalarModule(torch.nn.Module):
def forward(self, x):
res = x + 2
Expand Down
15 changes: 15 additions & 0 deletions torch/csrc/jit/passes/onnx/remove_inplace_ops_for_onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ Node* addDummyClone(
orig_data->type()->kind() == TypeKind::BoolType) {
auto* noneNode = graph->create(prim::Constant);
noneNode->output()->setType(NoneType::get());
// For scripting mode, aten::clone requires input to be a TensorType
// Hence if we encounter an IntType, FloatType, or BoolType,
// we set the input to the appropriate TensorType
if (orig_data->type()->kind() == TypeKind::IntType &&
insertBefore == false) {
orig_data->setType(TensorType::fromNumberType(*IntType::get()));
} else if (
orig_data->type()->kind() == TypeKind::FloatType &&
insertBefore == false) {
orig_data->setType(TensorType::fromNumberType(*FloatType::get()));
} else if (
orig_data->type()->kind() == TypeKind::BoolType &&
insertBefore == false) {
orig_data->setType(TensorType::fromBoolType());
}
newNode = graph->create(aten::clone, /*num_outputs =*/1);
newNode->addInput(orig_data);
newNode->addInput(noneNode->output());
Expand Down
0