torch-mlir/frontends/pytorch/e2e_testing/torchscript
Sean Silva 79928cd2dd Generalize support for elementwise ops.
We plumb through e2e a fair number of interesting cases:
- unary, binary, ternary elementwise ops
- ops like `torch.aten.add.Tensor` that also take a scalar parameter
- static size-1 broadcasting

We allow the static size-1 broadcasting case, but emit a runtime error
in the case of dynamic size-1 broadcasting. This seems like a sweet spot
subset of things that can be lowered directly to linalg, while not being
overly constraining to users. This is consistent with what IREE is doing
for CHLO->Linalg lowering as well
([code](50bf7a87e4/iree/compiler/InputConversion/MHLO/BroadcastingToLinalgPatterns.cpp (L1))).

To test the static size-1 case, we added support for the
`torch.aten.unsqueeze` op and lowering for it through
`linalg.tensor_expand_shape`. This involved a generalization of
`MaximizeValueSemantics` able to handle it (the solution there also
works for `torch.aten.flatten.using_ints` which we need for ResNet
anyway)

Also, a few minor additional changes:
- Add `VerifyInvariantsBeforeBackendLowering` pass, which catches a
  large class of errors before we get to backend lowering (now that we
  are doing dialect conversion, the errors are way nicer if we just emit
  them up front rather than in the guts of a random pattern).
- Minor change to RefBackend to allow `linalg.tensor_expand_shape`.

Recommended review order:
- e2e tests in elementwise.py
- `ConvertElementwiseOp` in TorchToLinalg.cpp + elementwise.mlir test
- `ConvertAtenUnsqueezeOp` in TorchToLinalg.cpp + unsqueeze.mlir test
- RefineTypes.cpp + tests
- MaximizeValueSemantics changes + test
- VerifyInvariantsBeforeBackendLowering pass + test
2021-06-28 13:28:38 -07:00
..
basic.py Generalize support for elementwise ops. 2021-06-28 13:28:38 -07:00
batchnorm.py Add torch.aten.batch_norm Linalg lowering support 2021-06-22 16:45:21 -07:00
elementwise.py Generalize support for elementwise ops. 2021-06-28 13:28:38 -07:00
main.py Generalize support for elementwise ops. 2021-06-28 13:28:38 -07:00
mlp.py Introduce `!torch.tensor` / `!torch.vtensor` types. 2021-06-10 10:56:48 -07:00
quantized_models.py Introduce `!torch.tensor` / `!torch.vtensor` types. 2021-06-10 10:56:48 -07:00
vision_models.py Introduce `!torch.tensor` / `!torch.vtensor` types. 2021-06-10 10:56:48 -07:00