Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@gramalingam
Copy link
Contributor

@gramalingam gramalingam commented Mar 17, 2023

A minimal and simple extension to the proto definitions to allow multiple (overloaded) functions in its model-local function list with same (domain, name).

Model-local functions in ONNX provide a default-implementation for certain ops used in the model (expressed in terms of other primitive ops). This extension will allow us to provide different default-implementations for different calls to the same op (which might differ in the types of input-arguments or in the values of attribute-parameters).

  • Update proto
  • Update helper.py constructors
  • Update parser
  • Update shape inference implementation
  • Update in-memory IR
  • Add test-case
  • Minimal extensions in inliner to support this

@gramalingam gramalingam requested a review from a team as a code owner March 17, 2023 22:47
@gramalingam gramalingam changed the title Add proto support for overloaded functions [Proposal: Don't Merge] Add proto support for overloaded functions Mar 18, 2023
@jbachurski
Copy link
Member

jbachurski commented Mar 21, 2023

Just wanted to say I think this is a really good idea. Functions are currently way too limited to be really useful for a runtime/tooling IMO. Adding overloads can be a good first step towards actually expressing a wider part of the standard with them. If I understand correctly, they would be parametrised by input types and attribute values which seems like exactly the way to go.

@BowenBao
Copy link
Contributor

BowenBao commented Feb 7, 2024

Thank you @gramalingam ! This will enable clean and unified function names for dynamo onnx exported specialized nn.Module functions, as well as potentially the currently inlined 'trace_only' functions in onnxscript torchlib.

One thing to point out though this does appear to vary slightly with traditional pl function overload concept, whereas here it is possible to have two function overloads with exact same input and attribute types. I think following the pl convention would restrict the usefulness in above mentioned use cases, but I'd love to learn about concerns if any.

@BowenBao
Copy link
Contributor

BowenBao commented Feb 7, 2024

cc @justinchuby, @pranavsharma

@gramalingam
Copy link
Contributor Author

Also: @yuslepukhin for comments/feedback if any

Signed-off-by: Ganesan Ramalingam <[email protected]>
@codecov
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (08a399b) 56.65% compared to head (878c8ec) 56.64%.

Files Patch % Lines
onnx/helper.py 0.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5011      +/-   ##
==========================================
- Coverage   56.65%   56.64%   -0.01%     
==========================================
  Files         506      506              
  Lines       30194    30201       +7     
  Branches     4556     4558       +2     
==========================================
+ Hits        17105    17108       +3     
- Misses      12266    12268       +2     
- Partials      823      825       +2     

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

Signed-off-by: Ganesan Ramalingam <[email protected]>
@xadupre
Copy link
Contributor

xadupre commented Feb 8, 2024

The new string would be consumed by a NodeProto to avoid any ambiguity or can it be left empty or is it just an extension of the function name? I assume this PR goes with #5903.

Signed-off-by: Ganesan Ramalingam <[email protected]>
Signed-off-by: Ganesan Ramalingam <[email protected]>
Signed-off-by: Ganesan Ramalingam <[email protected]>
@justinchuby justinchuby added this to the 1.16 milestone Feb 9, 2024
Signed-off-by: Ganesan Ramalingam <[email protected]>
@gramalingam gramalingam changed the title [Proposal: Don't Merge] Add proto support for overloaded functions Add proto support for overloaded functions Feb 9, 2024
Copy link
Contributor

@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.

Is onnx.printer.to_text updated to reflect this change?

@gramalingam
Copy link
Contributor Author

The new string would be consumed by a NodeProto to avoid any ambiguity or can it be left empty or is it just an extension of the function name? I assume this PR goes with #5903.

Both FunctionProto and NodeProto have this new field. But it is an optional string field. It can be left empty. As I understand Protobuf, older versions (IR version 9 and below), when read in (with new proto), it will have an empty string value.

When both FunctionProto and NodeProto have this empty, the behavior is same as before. However, if this is non-empty, then it is used to match the names from NodeProto to FunctionProto.

Signed-off-by: Ganesan Ramalingam <[email protected]>
@gramalingam
Copy link
Contributor Author

Is onnx.printer.to_text updated to reflect this change?

Good catch. I updated it, thanks.

@gramalingam
Copy link
Contributor Author

A question on the syntax (used in onnxtext format): I use "opname:overload" to indicate the overload. Please let me know if you have any suggestions: eg., if you think "opname::overload" would be better. A single colon seems sufficient and minimal. Double colon has the advantage of being aligned with C++ notation.

@gramalingam
Copy link
Contributor Author

@xadupre : one thing pending is updating the reference implementation. Do you know where it looks up a model-local function to execute a node?

@gramalingam gramalingam enabled auto-merge February 9, 2024 23:41
@gramalingam gramalingam added this pull request to the merge queue Feb 10, 2024
@justinchuby
Copy link
Member

A question on the syntax (used in onnxtext format): I use "opname:overload" to indicate the overload. Please let me know if you have any suggestions: eg., if you think "opname::overload" would be better. A single colon seems sufficient and minimal. Double colon has the advantage of being aligned with C++ notation.

Does . work like what PyTorch has?

@justinchuby
Copy link
Member

Hmm maybe not since domain can be dot separated already. : LGTM

Merged via the queue into onnx:main with commit a7eb8ac Feb 10, 2024
@gramalingam gramalingam deleted the func-overload-proto branch February 10, 2024 01:03
Abhishek-TyRnT pushed a commit to Abhishek-TyRnT/onnx that referenced this pull request Feb 14, 2024
A minimal and simple extension to the proto definitions to allow
multiple (overloaded) functions in its model-local function list with
same (domain, name).

Model-local functions in ONNX provide a default-implementation for
certain ops used in the model (expressed in terms of other primitive
ops). This extension will allow us to provide different
default-implementations for different calls to the same op (which might
differ in the types of input-arguments or in the values of
attribute-parameters).

* Update proto
* Update helper.py constructors
* Update parser
* Update shape inference implementation
* Update in-memory IR
* Add test-case
* Minimal extensions in inliner to support this

---------

Signed-off-by: Ganesan Ramalingam <[email protected]>
Signed-off-by: Abhishek-TyRnT <[email protected]>
@justinchuby
Copy link
Member

justinchuby commented Mar 11, 2024

Should op schemas be extended to support function overloads? @gramalingam

linshokaku pushed a commit to linshokaku/onnx that referenced this pull request Oct 2, 2024
A minimal and simple extension to the proto definitions to allow
multiple (overloaded) functions in its model-local function list with
same (domain, name).

Model-local functions in ONNX provide a default-implementation for
certain ops used in the model (expressed in terms of other primitive
ops). This extension will allow us to provide different
default-implementations for different calls to the same op (which might
differ in the types of input-arguments or in the values of
attribute-parameters).

* Update proto
* Update helper.py constructors
* Update parser
* Update shape inference implementation
* Update in-memory IR
* Add test-case
* Minimal extensions in inliner to support this

---------

Signed-off-by: Ganesan Ramalingam <[email protected]>
Signed-off-by: Linsho Kaku <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants