Skip to content

Add torchvision.ops.deform_conv2d and opset19-specific tests#2923

Open
f-fuchs wants to merge 6 commits into
microsoft:mainfrom
f-fuchs:torchvision_deform_conv2d
Open

Add torchvision.ops.deform_conv2d and opset19-specific tests#2923
f-fuchs wants to merge 6 commits into
microsoft:mainfrom
f-fuchs:torchvision_deform_conv2d

Conversation

@f-fuchs
Copy link
Copy Markdown

@f-fuchs f-fuchs commented May 28, 2026

Summary

Add mapping for torchvision.ops.deform_conv2d to ONNX DeformConv and add OpInfo-based test coverage.

Changes

  • add torchvision.ops.deform_conv2d support in onnxscript/function_libs/torch_lib/ops/vision.py
  • map PyTorch padding to ONNX pads
  • infer and set group and offset_group
  • support optional bias and mask

Tests

Added OpInfo coverage for:

  • basic case
  • bias
  • mask
  • nonzero padding
  • grouped convolution
  • multiple offset groups

Files:

  • tests/function_libs/torch_lib/extra_opinfo.py
  • tests/function_libs/torch_lib/ops_test_data.py

Opset handling

DeformConv requires ONNX opset 19+, while the existing torch-lib full-graph suite uses opset 18.

To keep the existing suite unchanged:

  • keep the global torch-lib test baseline at opset 18
  • add a dedicated deform-conv full-graph test path at opset 19
  • exclude deform-conv from the generic opset-18 full-graph suite

Files:

  • tests/function_libs/torch_lib/ops_test.py
  • tests/function_libs/torch_lib/ops_test_common.py

Validation

python -m pytest tests/function_libs/torch_lib/ops_test.py -k deform_conv2d

Passed:

  • 1 passed
  • 1 skipped (expected for trace_only=True)

@f-fuchs
Copy link
Copy Markdown
Author

f-fuchs commented May 28, 2026

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Collaborator

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! For testing, I think you can instead add tests to the e2e file. This may be the simplest with regards to the opset situation

Comment thread tests/function_libs/torch_lib/ops_test.py Outdated
@f-fuchs
Copy link
Copy Markdown
Author

f-fuchs commented Jun 1, 2026

I reverted my test changes and added two tests to tests/function_libs/torch_lib/e2e_ops_tests.py.
These then showed that my prior mapping was not correct so I fixed it. Let me know if I should add additional tests

@titaiwangms titaiwangms self-requested a review June 1, 2026 15:49
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 72.64%. Comparing base (8fdb1e0) to head (a45eaca).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
onnxscript/function_libs/torch_lib/ops/vision.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2923   +/-   ##
=======================================
  Coverage   72.64%   72.64%           
=======================================
  Files         259      259           
  Lines       31652    31657    +5     
  Branches     2980     2980           
=======================================
+ Hits        22994    22998    +4     
- Misses       7649     7650    +1     
  Partials     1009     1009           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Collaborator

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@github-project-automation github-project-automation Bot moved this from Todo to Done in ONNX Script Review Board Jun 1, 2026
@justinchuby justinchuby requested a review from Copilot June 1, 2026 16:04
@justinchuby justinchuby added the module: torchlib Related to the torch/aten function lib in development label Jun 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds ONNX export support for torchvision.ops.deform_conv2d by registering a torch-lib mapping to the ONNX DeformConv operator (opset 19) and adds end-to-end export tests exercising the new path.

Changes:

  • Register torchvision::deform_conv2d in torch-lib and lower it to opset19.DeformConv with stride/dilation/pad/group handling.
  • Add e2e torch.onnx.export(..., opset_version=19, dynamo=True) tests for deform-conv (basic + mask/padding/group coverage).
  • Update test module imports to include torchvision for the new test cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
tests/function_libs/torch_lib/e2e_ops_tests.py Adds opset-19 e2e export tests for torchvision.ops.deform_conv2d.
onnxscript/function_libs/torch_lib/ops/vision.py Registers torchvision::deform_conv2d and maps it to ONNX DeformConv (opset 19).

Comment thread onnxscript/function_libs/torch_lib/ops/vision.py Outdated
Comment on lines +100 to +104
input: TFloat,
weight: TFloat,
offset: TFloat,
mask: TFloat,
bias: TFloat,
@@ -11,7 +11,9 @@
from typing import Sequence
@justinchuby
Copy link
Copy Markdown
Collaborator

@f-fuchs could you follow the copilot review comments?

f-fuchs and others added 2 commits June 2, 2026 08:22
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@f-fuchs f-fuchs force-pushed the torchvision_deform_conv2d branch from 117c463 to dcc75b0 Compare June 2, 2026 06:47
@f-fuchs
Copy link
Copy Markdown
Author

f-fuchs commented Jun 2, 2026

@f-fuchs could you follow the copilot review comments?

done

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

Labels

module: torchlib Related to the torch/aten function lib in development

Projects

Development

Successfully merging this pull request may close these issues.

3 participants