torch-mlir/frontends/pytorch/test/node_import
Sean Silva 59a3f46795 Add support for prim.NumToTensor
With this, we can import BERT!
```
pt_util ~/tmp/bert.pt  --import --exported-name=forward \
| npcomp-opt -torch-globalize-object-graph -inline -symbol-dce
```
https://gist.github.com/silvasean/fe7735ff5d065cc9216f7b0346d0e977

The test case here is a bit unconventional -- it isn't actually valid
Python. To figure out how to generate it I had to go search the PyTorch
codebase for "NumToTensor" and work backward. In this case I found
this
[code](649760e5f1/torch/csrc/jit/frontend/ir_emitter.cpp (L464))
which via a wild guess I was able to turn into a test case.

In this case it didn't take me too long, but when doing this kind of
"add a bunch of trivial stuff to bring up a real model", I'm starting to
think that we might skimp on test cases when it's fairly trivial and not
obvious how to test with a small test.
2021-02-26 10:16:56 -08:00
..
README.md Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
add3.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
debug-info.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
elif.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
errors.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
if.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
list.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
prim.py Add support for prim.NumToTensor 2021-02-26 10:16:56 -08:00
tuple.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
types-bool.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00
types-none.py Rename tests to match the code they test 2021-02-25 13:31:33 -08:00

README.md

node_import

Most of the tests in this directory test the importing of TorchScript torch::jit::Graph's.

However, TorchScript graphs don't really correspond directly to anything on the MLIR side. They are a weird combination of a context, builder, and function and just holds a torch::jit::Block. It is torch::jit::Node and torch::jit::Block which form the recursive structure analogous to MLIR's operation/region/block.

  • torch::jit::Node == mlir::Operation,
  • torch::jit::Block == mlir::Region containing single mlir::Block

Hence the name of this directory and the corresponding code in node_importer.h/cpp.