Skip to content

Comments

Use type-directed translation of attribute values#923

Merged
gramalingam merged 19 commits intomainfrom
rama/attr_type
Jul 26, 2023
Merged

Use type-directed translation of attribute values#923
gramalingam merged 19 commits intomainfrom
rama/attr_type

Conversation

@gramalingam
Copy link
Collaborator

Use the attribute-type from opschema, when available, to handle attribute-values during translation, as well as in eager-mode.

This enables constructs like Constant(value_ints=[]), Constant(value=0), Constant(value=[1,-1]).

See #860 and #786

@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Merging #923 (f9a4962) into main (0b1a0e3) will increase coverage by 0.04%.
The diff coverage is 88.37%.

@@            Coverage Diff             @@
##             main     #923      +/-   ##
==========================================
+ Coverage   76.80%   76.84%   +0.04%     
==========================================
  Files         112      112              
  Lines       13552    13619      +67     
  Branches     1378     1386       +8     
==========================================
+ Hits        10408    10466      +58     
- Misses       2801     2805       +4     
- Partials      343      348       +5     
Files Changed Coverage Δ
onnxscript/_internal/autocast.py 83.48% <63.63%> (ø)
onnxscript/converter.py 80.97% <77.77%> (-0.45%) ⬇️
onnxscript/converter_test.py 84.15% <100.00%> (+1.32%) ⬆️
onnxscript/evaluator.py 88.93% <100.00%> (+0.22%) ⬆️
onnxscript/irbuilder.py 77.27% <100.00%> (+0.34%) ⬆️
onnxscript/tensor.py 86.66% <100.00%> (+0.09%) ⬆️

@gramalingam
Copy link
Collaborator Author

The doc-generation CI is failing. When I try to repro locally, sphinx fails (even earlier than the CI) for me with

loading intersphinx inventory from https://onnxruntime.ai/docs/api/python/objects.inv...

Extension error (sphinx.ext.intersphinx):
Handler <function load_mappings at 0x00000248C38FDB80> for event 'builder-inited' threw an exception
(exception: '<' not supported between instances of 'dict' and 'dict')

Any ideas?

@justinchuby
Copy link
Collaborator

It started failing earlier this week. Looks like a dependency just updated and broke it

# The caller is responsible for omitting such attribute-values from the list of attributes
# in a NodeProto.
if val is None:
if attr_meta and attr_meta.required:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we test the error cases too?

Comment on lines +435 to +436
# Utility to convert kwarg to ONNX AttributeProto:
def make_attr(key: str, value: Any) -> onnx.AttributeProto:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Utility to convert kwarg to ONNX AttributeProto:
def make_attr(key: str, value: Any) -> onnx.AttributeProto:
def make_attr(key: str, value: Any) -> onnx.AttributeProto:
"""Utility to convert kwarg to ONNX AttributeProto."""

implicit_args = {k: _os_to_ort_value(v) for k, v in implicit_args.items()}

# Utility to convert kwarg to ONNX AttributeProto:
def make_attr(key: str, value: Any) -> onnx.AttributeProto:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also lift the function to module and mark private to reduce nested functions?


node = onnx.helper.make_node(schema.name, inputs, outputs, domain=schema.domain, **kwargs)
node = onnx.helper.make_node(schema.name, inputs, outputs, domain=schema.domain)
node.attribute.extend(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we need to do the same for the torch_lib graph tracing evaluator.

@gramalingam gramalingam merged commit 7402a96 into main Jul 26, 2023
@gramalingam gramalingam deleted the rama/attr_type branch July 26, 2023 17:08
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.

2 participants