Skip to content

[torchlib] Migrate torchvision implementations#2569

Merged
justinchuby merged 7 commits into
mainfrom
justinchu/vision
Jan 6, 2026
Merged

[torchlib] Migrate torchvision implementations#2569
justinchuby merged 7 commits into
mainfrom
justinchu/vision

Conversation

@justinchuby
Copy link
Copy Markdown
Collaborator

@justinchuby justinchuby commented Sep 23, 2025

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby added the module: torchlib Related to the torch/aten function lib in development label Sep 23, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.18%. Comparing base (6e91205) to head (30450fa).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2569      +/-   ##
==========================================
+ Coverage   70.11%   70.18%   +0.07%     
==========================================
  Files         228      228              
  Lines       27396    27421      +25     
  Branches     2785     2786       +1     
==========================================
+ Hits        19208    19245      +37     
+ Misses       7228     7217      -11     
+ Partials      960      959       -1     

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

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
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 migrates torchvision implementations by adding support for roi_align and roi_pool operations to the torch_lib vision module. The changes enable ONNX export compatibility for these computer vision operations commonly used in object detection models.

  • Adds torchvision::roi_align implementation with proper coordinate transformation and sampling ratio handling
  • Adds torchvision::roi_pool implementation using ONNX MaxRoiPool operator
  • Updates existing torchvision::nms operation to be trace-only

Comment thread onnxscript/function_libs/torch_lib/ops/vision.py
Comment thread onnxscript/function_libs/torch_lib/ops/vision.py Outdated
@justinchuby justinchuby added this to the 0.5.4 milestone Oct 7, 2025
@justinchuby
Copy link
Copy Markdown
Collaborator Author

@titaiwangms

@justinchuby justinchuby modified the milestones: 0.5.4, 0.5.5 Oct 16, 2025
@titaiwangms
Copy link
Copy Markdown
Contributor

Where do we migrate this from? Was there a test we can move to here as well?

@justinchuby
Copy link
Copy Markdown
Collaborator Author

Adapted from https://github.com/pytorch/vision/blob/main/torchvision/ops/_register_onnx_ops.py. There are some tests we can move over too

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Comment thread tests/function_libs/torch_lib/extra_opinfo.py Fixed
Comment thread tests/function_libs/torch_lib/extra_opinfo.py Fixed
Comment thread tests/function_libs/torch_lib/extra_opinfo.py Fixed
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby enabled auto-merge (squash) January 6, 2026 17:57
@justinchuby justinchuby merged commit e80ebe8 into main Jan 6, 2026
32 of 33 checks passed
@justinchuby justinchuby deleted the justinchu/vision branch January 6, 2026 22:22
@github-project-automation github-project-automation Bot moved this from Todo to Done in ONNX Script Review Board Jan 6, 2026
@ruro
Copy link
Copy Markdown
Contributor

ruro commented Mar 19, 2026

FYI, as far as I can tell, this PR causes the following spurious warnings as long as torchvision is imported anywhere (even if the model that is being exported by the user does not contain any torchvision ops). For example:

import torch
import torchvision
torch.onnx.export(
    torch.nn.Linear(1, 1),
    torch.zeros(1, 1),
    "/tmp/linear.onnx",
)

currently leads to

W0319 05:22:31.474000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'input' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0, sampling_ratio: 'int' = -1, aligned: 'bool' = False). Treating as an Input.
W0319 05:22:31.475000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'boxes' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0, sampling_ratio: 'int' = -1, aligned: 'bool' = False). Treating as an Input.
W0319 05:22:31.475000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'input' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0). Treating as an Input.
W0319 05:22:31.475000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'boxes' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0). Treating as an Input.

@justinchuby
Copy link
Copy Markdown
Collaborator Author

FYI, as far as I can tell, this PR causes the following spurious warnings as long as torchvision is imported anywhere (even if the model that is being exported by the user does not contain any torchvision ops). For example:

import torch
import torchvision
torch.onnx.export(
    torch.nn.Linear(1, 1),
    torch.zeros(1, 1),
    "/tmp/linear.onnx",
)

currently leads to

W0319 05:22:31.474000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'input' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0, sampling_ratio: 'int' = -1, aligned: 'bool' = False). Treating as an Input.
W0319 05:22:31.475000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'boxes' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0, sampling_ratio: 'int' = -1, aligned: 'bool' = False). Treating as an Input.
W0319 05:22:31.475000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'input' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0). Treating as an Input.
W0319 05:22:31.475000 1 site-packages/torch/onnx/_internal/exporter/_schemas.py:455] Missing annotation for parameter 'boxes' from (input, boxes, output_size: 'Sequence[int]', spatial_scale: 'float' = 1.0). Treating as an Input.

Thanks - will find a way to hide this warning

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.

7 participants