Fix BatchMatMul test and shape inference (#66733)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66733
Fix the test for BatchMatMul to compare glow/caffe2 outputs and fix its shape inference function since it made simplifying assumptions for broadcasting and failed on some of the shapes in the test. The previous inference was failing for any cases where the first n - 2 output dimensions of A x B was not simply that of whichever one of A or B had higher rank (ex. A: [2, 2, 2, 3, 4], B: [3, 1, 2, 2, 4, 5] we expect output dimensions [3, 2, 2, 2, 3, 5] rather than [3, 1, 2, 2, 3, 5].
Test Plan:
```
buck test glow/fb/test/numerics:test_operator_onnxifinnpi -- -r .*test_batch_matmul_manydims.* --env USE_INF_API=1
```
Reviewed By: khabinov
Differential Revision: D31701184
fbshipit-source-id: 31d0fb17409a399b90fb8042385e000ed81c3581