[Codemod][AddExplicitStrictExportArg] caffe2/torch (#146439)

Differential Revision: D69068432

Pull Request resolved: https://github.com/pytorch/pytorch/pull/146439
Approved by: https://github.com/avikchaudhuri
This commit is contained in:
Yanan Cao (PyTorch) 2025-02-05 22:56:54 +00:00 committed by PyTorch MergeBot
parent 97b64f2e5c
commit 8af31e30d7
4 changed files with 846 additions and 564 deletions

View file

@ -4591,7 +4591,7 @@ class ExportTestsDevice(torch._dynamo.test_case.TestCase):
random_inputs = (torch.rand([32, 3, 32, 32]).to(device),)
dim_x = torch.export.Dim("dim_x", min=1, max=32)
exp_program = torch.export.export(
model, random_inputs, dynamic_shapes={"x": {0: dim_x}}
model, random_inputs, dynamic_shapes={"x": {0: dim_x}}, strict=True
)
output_buffer = io.BytesIO()
# Tests if we can restore saved nn.Parameters when we load them again
@ -4621,7 +4621,9 @@ class ExportTestsDevice(torch._dynamo.test_case.TestCase):
batchsize = torch.export.Dim("dim0", min=3, max=1024)
dynamic_shape_spec = {"a": [batchsize, None, None], "b": [None, None]}
torch.export.export(model, (a, b), dynamic_shapes=dynamic_shape_spec)
torch.export.export(
model, (a, b), dynamic_shapes=dynamic_shape_spec, strict=True
)
def test_export_fast_binary_broadcast_check_unbacked(self, device):
class MyModel(torch.nn.Module):
@ -4634,7 +4636,7 @@ class ExportTestsDevice(torch._dynamo.test_case.TestCase):
model = MyModel().eval().to(device)
numel = torch.tensor(10)
scalar = torch.randn(1)
torch.export.export(model, (numel, scalar))
torch.export.export(model, (numel, scalar), strict=True)
common_utils.instantiate_parametrized_tests(ExportTests)

View file

@ -144,7 +144,7 @@ class TestGraphTransformObserver(TestCase):
return torch.neg(x)
model = SimpleLinearModel()
gm = torch.export.export(model, (torch.rand(10),)).module()
gm = torch.export.export(model, (torch.rand(10),), strict=True).module()
with GraphTransformObserver(gm, "test"):
add_node = gm.graph.call_function(torch.ops.aten.add.default, (1, 1))
@ -171,7 +171,7 @@ class TestGraphTransformObserver(TestCase):
return torch.neg(x)
model = SimpleLinearModel()
gm = torch.export.export(model, (torch.rand(10),)).module()
gm = torch.export.export(model, (torch.rand(10),), strict=True).module()
with GraphTransformObserver(gm, "test"):
gm2 = copy.deepcopy(gm)

View file

@ -2213,7 +2213,7 @@ class AOTInductorTestsTemplate:
example_inputs = (torch.randn(10, 10, device=self.device),)
optimized = torch._inductor.aoti_load_package(
torch._inductor.aoti_compile_and_package(
torch.export.export(Model(), example_inputs)
torch.export.export(Model(), example_inputs, strict=True)
)
)
try:

File diff suppressed because it is too large Load diff