Skip to content

Fix use of ONNX optimizer by Caffe2 backend#75718

Closed
thiagocrepaldi wants to merge 1 commit intopytorch:masterfrom
thiagocrepaldi:thiagofc/fix-caffe2-onnx-optimizer
Closed

Fix use of ONNX optimizer by Caffe2 backend#75718
thiagocrepaldi wants to merge 1 commit intopytorch:masterfrom
thiagocrepaldi:thiagofc/fix-caffe2-onnx-optimizer

Conversation

@thiagocrepaldi
Copy link
Copy Markdown
Collaborator

@thiagocrepaldi thiagocrepaldi commented Apr 13, 2022

Fixes #69674

The fix is Back Compatible with any Caffe2 build. It simply tries to use onnxptimizer module when onnx.optimizer is not available.

onnx.optimizer does not exist since ONNX 1.9 (April 2021) as the code was moved to a different repo

If both onnx<1.9 and onnxoptimizer are not found, the current fallback behavior is maintained (no ONNX optimization happens). Otherwise, the ONNX optimization pass will run from whatever module it is found.

This PR does not require or enforce a direct package dependency to work

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Apr 13, 2022

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 83f6441 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@thiagocrepaldi thiagocrepaldi added release notes: onnx torch.onnx related changes that should show up in the release notes topic: bug fixes topic category and removed open source cla signed labels Apr 13, 2022
@thiagocrepaldi thiagocrepaldi force-pushed the thiagofc/fix-caffe2-onnx-optimizer branch from c1d6c54 to 83f6441 Compare April 13, 2022 13:17
@thiagocrepaldi thiagocrepaldi added module: onnx Related to torch.onnx onnx-needs-import This PR is related to ONNX, but touches files outside of merge rule patterns, and hence needs import caffe2 labels Apr 13, 2022
@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 13, 2022
Copy link
Copy Markdown
Collaborator

@BowenBao BowenBao left a comment

Choose a reason for hiding this comment

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

LGTM

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@msaroufim has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@msaroufim msaroufim self-requested a review April 14, 2022 21:41
@malfet
Copy link
Copy Markdown
Contributor

malfet commented Apr 14, 2022

@pytorchbot merge this

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@msaroufim has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot pushed a commit that referenced this pull request Apr 16, 2022
Summary:
Fixes #69674

The fix is Back Compatible with any Caffe2 build. It simply tries to use `onnxptimizer` module when `onnx.optimizer` is not available.

`onnx.optimizer` does not exist since ONNX 1.9 (April 2021) as the code was moved to a different [repo](https://github.com/onnx/onnxoptimizer)

If both `onnx<1.9` and `onnxoptimizer` are not found, the current fallback behavior is maintained (no ONNX optimization happens). Otherwise, the ONNX optimization pass will run from whatever module it is found.

This PR does not require or enforce a direct package dependency to work

Pull Request resolved: #75718
Approved by: https://github.com/BowenBao, https://github.com/malfet

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/950dc1b45738e0cf0b341e0594cf517668b406a0

Reviewed By: mehtanirav

Differential Revision: D35658271

fbshipit-source-id: e10d7b55f39783b661f998d800e83482bb978824
thiagocrepaldi pushed a commit to thiagocrepaldi/detectron2 that referenced this pull request May 27, 2022
This commit fixes Caffe2Tracer.export_caffe2 API for the latest pytorch repo

Before this change, all tests at tests/test_export_caffe2.py fail because
the latest onnx releases does not have onnx.optimizer namespace anymore
and detectron2 code tried to use fuse_bn_into_conv from it.

However, fuse_bn_into_conv optimization previously present in onnx.optimizer
is already performed by torch.onnx.export. Therefore it wwas removed
from detectron2 code.

Depends on pytorch/pytorch#75718
Fixes facebookresearch#3488
Fixes pytorch/pytorch#69674 (PyTorch repo)
thiagocrepaldi pushed a commit to thiagocrepaldi/detectron2 that referenced this pull request May 27, 2022
This commit fixes Caffe2Tracer.export_caffe2 API for the latest pytorch repo

Before this change, all tests at tests/test_export_caffe2.py fail because
the latest onnx releases does not have onnx.optimizer namespace anymore
and detectron2 code tried to use fuse_bn_into_conv from it.

However, fuse_bn_into_conv optimization previously present in onnx.optimizer
is already performed by torch.onnx.export. Therefore it wwas removed
from detectron2 code.

Depends on pytorch/pytorch#75718
Fixes facebookresearch#3488
Fixes pytorch/pytorch#69674 (PyTorch repo)
thiagocrepaldi pushed a commit to thiagocrepaldi/detectron2 that referenced this pull request Jun 1, 2022
Before this change, all tests at tests/test_export_caffe2.py fail because
the latest onnx releases does not have onnx.optimizer namespace anymore
and detectron2 code tried to use fuse_bn_into_conv from it.

However, fuse_bn_into_conv optimization previously present in onnx.optimizer
is already performed by torch.onnx.export. Therefore it wwas removed
from detectron2 code.

Caffe2 export tests only run if onnx is installed

Depends on pytorch/pytorch#75718
Fixes facebookresearch#3488
Fixes pytorch/pytorch#69674 (PyTorch repo)
facebook-github-bot pushed a commit to facebookresearch/detectron2 that referenced this pull request Jul 15, 2022
Summary:
Currently all Caffe2 export tests (under `tests/test_export_caffe2.py`) fail because the latest `onnx` releases do not have `onnx.optimizer` submodule anymore (instead, a new module `onnxoptimizer` was created from it)

However, `fuse_bn_into_conv` optimization previously implemented within `onnx.optimizer` is already performed by `torch.onnx.export` too ruing ONNX export. Therefore `onnx.optimizer` dependency can be safely removed from detectron2 code.

Depends on pytorch/pytorch#75718
Fixes #3488
Fixes pytorch/pytorch#69674 (PyTorch repo)

ps: Although `Caffe2` support is/will be deprecated, this PR relies on the fact that [contributions are welcome as stated at docs/tutorials/deployment.md](https://github.com/facebookresearch/detectron2/blob/main/docs/tutorials/deployment.md)

Pull Request resolved: #4295

Reviewed By: wat3rBro

Differential Revision: D37152773

Pulled By: mcimpoi

fbshipit-source-id: 56ff8cda67814890d800834977fe4582f1a19761
@thiagocrepaldi thiagocrepaldi deleted the thiagofc/fix-caffe2-onnx-optimizer branch May 4, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

caffe2 cla signed module: onnx Related to torch.onnx onnx-needs-import This PR is related to ONNX, but touches files outside of merge rule patterns, and hence needs import open source release notes: onnx torch.onnx related changes that should show up in the release notes topic: bug fixes topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to export PointRend model (from detectron2) to ONNX

6 participants