Skip to content

[torchlib] Add aten::_grouped_mm ONNX lowering - #3017

Open
TANGBUDU wants to merge 1 commit into
microsoft:mainfrom
TANGBUDU:fix/grouped-mm-onnx-export-2795
Open

[torchlib] Add aten::_grouped_mm ONNX lowering#3017
TANGBUDU wants to merge 1 commit into
microsoft:mainfrom
TANGBUDU:fix/grouped-mm-onnx-export-2795

Conversation

@TANGBUDU

Copy link
Copy Markdown

Summary

Adds a torchlib lowering for aten::_grouped_mm, addressing #2795.

  • lowers 3D x 3D grouped matmul directly to ONNX MatMul
  • supports the offset-based 2D x 3D, 3D x 2D, and 2D x 2D layouts by unrolling groups when the group count is statically known
  • preserves dynamic shapes for the regular 3D x 3D case
  • keeps the existing PyTorch constraints around offsets, bias, and output dtype
  • guards the new OpInfo/e2e tests so stable PyTorch releases that do not yet expose _grouped_mm remain unaffected

For an offset tensor whose number of groups is itself dynamic, this PR intentionally does not build a generic loop. A future follow-up could lower that case with Scan/Loop; the static-group unrolling here follows the direction discussed in #2795.

Tests

  • pytest tests/function_libs/torch_lib/ops_test.py -k grouped_mm -q
    • 4 offset/layout subtests pass
  • pytest tests/function_libs/torch_lib/e2e_ops_tests.py -k grouped_mm -q
    • 2 passed
  • lintrunner -a
    • no lint issues
  • git diff --check
    • clean
  • stable PyTorch 2.7.1 compatibility check
    • _grouped_mm tests are correctly excluded/skipped

I also ran the full torch-lib e2e file on the current PyTorch nightly. It has 5 unrelated failures (STFT graph API, dynamic unbind shape constraints, and SDPA numerical mismatch); all 5 reproduce unchanged on a clean upstream/main checkout with this patch stashed.

@TANGBUDU

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant