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

Export TIMM image models to onnx #2564

Merged
merged 1 commit into from
Jan 4, 2023
Merged

Conversation

liangfu
Copy link
Collaborator

@liangfu liangfu commented Dec 13, 2022

Issue #, if available:

Description of changes:

  1. This PR exports the TIMM image models to onnx, and it's been tested on onnxruntime for checking correctness.
  2. Downgrades onnx to 1.12.x (since Upgrade onnx version to 1.13.x #2567), due to conflict version range of protobuf against tensorboardx:
    a. onnx 1.13.x requires protobuf >=3.12.2,<=3.20.1, (onnx 1.12.x requires protobuf >=3.12.2,<=3.20.1)
    b. tensorboardx 2.5.1 requires protobuf >=3.8.0,<=3.20.1

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@liangfu liangfu force-pushed the swin-onnx-1 branch 7 times, most recently from 0de339b to eaba988 Compare December 15, 2022 21:48
@liangfu liangfu changed the title Export Swin image cls model to onnx Export TIMM image models to onnx Dec 15, 2022
@liangfu liangfu force-pushed the swin-onnx-1 branch 3 times, most recently from 764c5ba to ce2bd08 Compare December 19, 2022 17:34
@github-actions
Copy link

Job PR-2564-ce2bd08 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/ce2bd08/index.html

@liangfu
Copy link
Collaborator Author

liangfu commented Dec 19, 2022

tabular/setup.py Outdated Show resolved Hide resolved
multimodal/src/autogluon/multimodal/models/utils.py Outdated Show resolved Hide resolved
@github-actions
Copy link

Job PR-2564-5b7e30d is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/5b7e30d/index.html

torch.onnx.export(
self._model.eval(),
batch,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we still use the dict format as model input? It seems that @FANGAreNotGnu made it work when export hf_text models.

Copy link
Collaborator Author

@liangfu liangfu Dec 20, 2022

Choose a reason for hiding this comment

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

The reason we are moving away from dict input comes with two folds: 1) there are limitations in exporting onnx, 2) there are lots of benefits if we keep model inputs / outputs clear, see huggingface/transformers#16059

Copy link
Contributor

Choose a reason for hiding this comment

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

The dict input design is to flexibly support various modalities, backbones, and fusions in the AutoMM. I think changing the design may cause issues for some cases. For example, it seems difficult to list arguments of a fusion model since it may fuse any combinations of image, text, and tabular backbones.

Copy link
Contributor

Choose a reason for hiding this comment

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

For most functions in AutoMM, we have used the type hints. The dict design can make each model more modular. A batch may contain inputs for several backbones and a model only needs to extract its necessary information from the batch. This is especially useful in various fusion settings.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the dict does not work, does it make sense for us to switch to dataclasses or namedtuple @liangfu @zhiqiangdon ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We can try namedtuple, but not sure whether it is compatible with onnx.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

namedtuple is now experimentally working as inputs for tracing, but not yet ready to be part of collate function. will try integrate it into collate function in a follow-up PR.

@github-actions
Copy link

Job PR-2564-be11941 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/be11941/index.html

@github-actions
Copy link

Job PR-2564-03670f4 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/03670f4/index.html

@github-actions
Copy link

Job PR-2564-b732b91 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/b732b91/index.html

@github-actions
Copy link

Job PR-2564-aac3c98 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/aac3c98/index.html

@github-actions
Copy link

github-actions bot commented Jan 4, 2023

Job PR-2564-16430e3 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/16430e3/index.html

Copy link
Contributor

@zhiqiangdon zhiqiangdon left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing onnx export! Remember resolving the conflicts with the master branch.

@github-actions
Copy link

github-actions bot commented Jan 4, 2023

Job PR-2564-7411c95 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-2564/7411c95/index.html

@liangfu liangfu merged commit 0b0947e into autogluon:master Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants