pytorch/torch/export
Pian Pawakapan c20bc18d59 [export] allow static constraints in dynamic_shapes (#121860)
This PR allows users to specify int values for dimensions in dynamic_shapes as well as None, for example:

```
class Foo(torch.nn.Module):
    def forward(self, x, y, z):
        ...

    foo = Foo()
    inputs = (torch.randn(4, 6), torch.randn(5, 4), torch.randn(3, 3))

for dynamic_shapes in [
    None
    ((4, 6), (5, 4), (3, 3)),
    ((None, 6), None, {0: 3, 1: 3})
]:
    _ = export(foo, inputs, dynamic_shapes=dynamic_shapes)
```

All of the above should produce the same ExportedProgram.

This is done by temporarily creating a static dim constraint during analysis, where vr.lower == vr.upper. These constraints are then deleted during _process_constraints(), and do not show up in the final ExportedProgram's range_constraints.

Additionally, export() will also fail if the shapes are mis-specified, for example:
```
_ = export(foo, inputs, dynamic_shapes=((5, None), None, None))
```
leads to `torch._dynamo.exc.UserError: Static shape constraint of 5 does not match input size of 4, for L['x'].size()[0]`
Pull Request resolved: https://github.com/pytorch/pytorch/pull/121860
Approved by: https://github.com/avikchaudhuri
2024-03-21 16:59:59 +00:00
..
__init__.py [export] Remove WrapperModule. (#121042) 2024-03-05 18:10:22 +00:00
_remove_auto_functionalized_pass.py [export] add pass to remove auto functionalized hop (#122246) 2024-03-20 19:31:52 +00:00
_remove_effect_tokens_pass.py [export] Add serialization support for tokens (#121552) 2024-03-15 16:15:11 +00:00
_safeguard.py [export] Update error message for set_grad (#121666) 2024-03-12 16:41:45 +00:00
_trace.py [export] Log module hierarchy. (#121970) 2024-03-20 18:59:42 +00:00
_tree_utils.py [export] do not use tree_flatten_spec (#118608) 2024-01-30 19:14:04 +00:00
_unlift.py [export] Add effect token to export (#121424) 2024-03-09 02:43:26 +00:00
custom_obj.py [Export] Introduce class_fqn into CustomObjArgument (#118158) 2024-01-25 18:44:25 +00:00
dynamic_shapes.py [export] allow static constraints in dynamic_shapes (#121860) 2024-03-21 16:59:59 +00:00
exported_program.py [export] Improve consistency for nn_module_stack metadata, add checks to _trace.py (#120661) 2024-03-16 21:44:52 +00:00
graph_signature.py [export] Add serialization support for tokens (#121552) 2024-03-15 16:15:11 +00:00
unflatten.py [torch.export] Support is_compiling() flag for non-strict mode (#119602) 2024-02-29 05:52:51 +00:00