Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Op Support: torchvision.roi_align.default #143

Open
shivadbhavsar opened this issue Jul 2, 2024 · 4 comments
Open

Op Support: torchvision.roi_align.default #143

shivadbhavsar opened this issue Jul 2, 2024 · 4 comments
Assignees
Labels
Op Support TorchMIGraphX For internal tracking

Comments

@shivadbhavsar
Copy link
Collaborator

No description provided.

@shivadbhavsar shivadbhavsar added TorchMIGraphX For internal tracking Op Support labels Jul 2, 2024
@bpickrel bpickrel self-assigned this Jul 23, 2024
@shivadbhavsar
Copy link
Collaborator Author

Here is some sample test code to help with the acc_op implementation

import torch
from torchvision.ops import RoIAlign

roi_mod = RoIAlign(output_size=[2, 2], spatial_scale=1.0, sampling_ratio=-1, aligned=False)

inp = torch.randn(2, 3, 4, 4)
boxes = torch.tensor([[0, 0, 0, 0.5, 0.7]])

torch_out = roi_mod(inp, boxes)
print(torch_out)


import torch_migraphx.fx.tracer.acc_tracer.acc_tracer as acc_tracer
from torch_migraphx.fx.fx2mgx import MGXInterpreter
from torch_migraphx.fx.mgx_module import MGXModule
def convert_to_mgx(mod, inp):
    traced = acc_tracer.trace(mod.eval(), inp)
    traced.graph.print_tabular()
    interp = MGXInterpreter(traced, inp)
    interp.run()
    return MGXModule(interp.program, interp.get_input_names())

mgx_mod = convert_to_mgx(roi_mod, [inp, boxes])

mgx_out = mgx_mod(inp, boxes)
print(mgx_out)

Currently, this will fail with RuntimeError: Conversion of function torchvision.ops.roi_align.roi_align not supported.. Do one of the following:
a. Create a acc_op wrapper for torchvision.ops.roi_align.roi_align and implement a converter for it in acc_ops_converters.
b. Dont bother with acc wrapper, just create a torchvision_converters file and directly implement a converter for torchvision.ops.roi_align.roi_align

@bpickrel
Copy link
Contributor

Current status: Converter has been coded for this op, branch aten_roi_align but I learned that the MigraphX implementation of the ROIAlign op. doesn't give correct results. The op. has two coordinate transformation modes 'half_pixel' and 'output_half_pixel', and only the legacy mode 'output_half_pixel' gives correct results.

To debug the 'half_pixel' mode calculations, I'm comparing them in detail with the implementation found in Onnxruntime. This was used as the model for the MigraphX version but the code is just different enough to make checking a big job.

There isn't any PR for this task at this time.

@bpickrel
Copy link
Contributor

Confirmed that the MIGraphX ROIAlign op is buggy and created PR 3482 to fix it. This PR will be a prerequisite for the torch-migraphx code work.

The Migraphx implementation of ROIAlign did not have a test for half_pixel case at all, and contains bugs that weren't revealed by the existing test such as inverting X and Y coordinates in the input array. Thus, I keep finding more problems as I write more tests.

@bpickrel
Copy link
Contributor

PR 3482 is now coded and in review. The torch-migraphx changes, which depend on the MIGraphx PR, are still in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Op Support TorchMIGraphX For internal tracking
Projects
None yet
Development

No branches or pull requests

2 participants