Skip to content

Conversation

gramalingam
Copy link
Contributor

Description

  1. Adds support for node label in parser and printer
  2. Adds some status-checks that were missed in recent addition to support invalid identifiers.

Node labels are now supported with the following syntax:

   [a_node_label] y = MatMul (x, w)

However, we have a couple of options to choose from here:

(a) The ONNX spec says that the node label must be a valid identifier. So, we can allow for a valid identifier between the [...], relying on a quoted string inside if the user wants to use something that is not a valid identifier.

(b) Alternatively, since [ and ] act as end-markers, like quotes, we can allow any string in-between, that is taken to be the node label. (Users will need to use an escape backslash if they want ] in the label.)

Option (b) is better if users want to use non-identifier labels, eg., numbers, etc. I am inclined to go with (b), even though it is extra code. However, it won't be friendly to the use of white-space inside if users want to use identifier labels. Eg., [ mylabel ] will include the blank spaces in the label.

The implementation currently does only (a), which is simpler.

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
@gramalingam gramalingam requested a review from a team as a code owner September 6, 2024 23:15
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.23%. Comparing base (d191997) to head (4a98986).
Report is 351 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6349      +/-   ##
==========================================
- Coverage   57.23%   57.23%   -0.01%     
==========================================
  Files         507      507              
  Lines       31406    31406              
  Branches     4690     4690              
==========================================
- Hits        17976    17975       -1     
  Misses      12575    12575              
- Partials      855      856       +1     

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

@justinchuby
Copy link
Member

justinchuby commented Sep 6, 2024

  • Would quoting the label be too extra, as in [ "some node" ] (hopefully not)?
  • Would it be a bad idea to put the label to the end of the line, so that varying length labels will not make the lines look weird? For example
[ some_label ] y = Add (x, y)
[ some_extra_extra_long_label__some_scope_1__some_scope_2 ] z = some::SomeNodeNames(y)

Alternatively putting them at the back:

y = Add (x, y) [ some_label ]
z = some::SomeNodeNames(y) [ some_extra_extra_long_label__some_scope_1__some_scope_2 ]

Or does this syntax support line breaks, so

[ some_label ]
y = Add (x, y)
[ some_extra_extra_long_label__some_scope_1__some_scope_2 ]
z = some::SomeNodeNames(y)

is valid?

@gramalingam
Copy link
Contributor Author

  • Would quoting the label be too extra, as in [ "some node" ] (hopefully not)?

Yes ... that is precisely the choice/tradeoff discussed between (a) and (b). Option (b) avoids it, at the cost of including any extra blanks before or after the label as part of the label. (Though we could skip that, but seems a bit complicated).

Yes, line breaks can be used.

Putting the labels at the end: hmmm. It has the advantage you mention. But it seems less natural (convention typically puts labels before the statement; and, with if/while this would push the label to appear after the entire if/while body). I am inclined to leave it as is (visualization tools can always choose to present it differently, with alignment/omission etc. being supported as pretty-printing options).

@justinchuby
Copy link
Member

I see. "some node" is a valid identifier. I missed that part.

@gramalingam
Copy link
Contributor Author

I see. "some node" is a valid identifier. I missed that part.

I am unclear what your preference is. I am planning to extend the PR to allow [some node] as opposed to the current requirement of ["some node"]. Please let me know if you think that's not a good idea.

@justinchuby
Copy link
Member

justinchuby commented Sep 9, 2024

I think it would be more straightforward to just assume a valid identifier so that it is consistent across.

@justinchuby
Copy link
Member

justinchuby commented Sep 9, 2024

Sorry I see the trade off now: node names may not be a valid identifier…

edit: but still users can still write [ "6" ], which fits well with the fact that node names are strings. I personally feel that option (a) is clean and nice.

andife and others added 2 commits September 10, 2024 14:11
@gramalingam
Copy link
Contributor Author

Ok, I will leave this as is (using option 1).

@gramalingam gramalingam added this pull request to the merge queue Sep 10, 2024
Merged via the queue into onnx:main with commit 001550a Sep 10, 2024
39 checks passed
@gramalingam gramalingam deleted the pp-node-label branch September 10, 2024 20:15
linshokaku pushed a commit to linshokaku/onnx that referenced this pull request Oct 2, 2024
### Description

1) Adds support for node label in parser and printer
2) Adds some status-checks that were missed in recent addition to
support invalid identifiers.

Node labels are now supported with the following syntax:

```
   [a_node_label] y = MatMul (x, w)
```

However, we have a couple of options to choose from here:

(a) The ONNX spec says that the node label must be a valid identifier.
So, we can allow for a valid identifier between the `[...]`, relying on
a quoted string inside if the user wants to use something that is not a
valid identifier.

(b) Alternatively, since `[` and `]` act as end-markers, like quotes, we
can allow any string in-between, that is taken to be the node label.
(Users will need to use an escape backslash if they want `]` in the
label.)

Option (b) is better if users want to use non-identifier labels, eg.,
numbers, etc. I am inclined to go with (b), even though it is extra
code. However, it won't be friendly to the use of white-space inside if
users want to use identifier labels. Eg., `[ mylabel ]` will include the
blank spaces in the label.

The implementation currently does only (a), which is simpler.

---------

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
Co-authored-by: Andreas Fehlner <fehlner@arcor.de>
Signed-off-by: Linsho Kaku <linsho@preferred.jp>
@ramkrishna2910 ramkrishna2910 added the module: parser onnx parser label May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: parser onnx parser
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants