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

substitute defaults on deserialization #2012

Open
leshabirukov opened this issue Jan 16, 2025 · 3 comments
Open

substitute defaults on deserialization #2012

leshabirukov opened this issue Jan 16, 2025 · 3 comments
Labels
question Further information is requested topic: rewriter

Comments

@leshabirukov
Copy link

Problem: rewrite Conv nodes, but only with dilations==[1,1]. Issue - default value. To check dilation, I need include it in pattern, but this cause pattern match to fail on nodes with default dilations.

Probably related: #1627

Possible fix: substitute defaults on deserialization, I suspect, such a function already exists.

rewr_c.py.txt

@justinchuby
Copy link
Collaborator

Thanks. So a node with default and without default is store differently in graph. They are semantically the same but syntactically different. We need to decide what the behavior of the matcher should be.

@justinchuby justinchuby added question Further information is requested topic: rewriter labels Jan 16, 2025
@leshabirukov
Copy link
Author

Well, it can be outside of matcher, if one could force defaults for node.

But as I found, it may be not formalized at all!

from onnx import helper, reference

schema = reference.op_run.get_schema('Conv', 15)
if schema.attributes:
    for _, attr in sorted(schema.attributes.items()):
        default_value = helper.get_attribute_value(attr.default_value)
        print(f'{attr.name=:20}{default_value=}')

attr.name='auto_pad'
default_value=b'NOTSET'
attr.name='dilations'
default_value=None
attr.name='group'
default_value=1
attr.name='kernel_shape'
default_value=None
attr.name='pads'
default_value=None
attr.name='strides'
default_value=None
onnx.reference.op_run.get_schema('Conv', 11).attributes['dilations']

OpSchema.Attribute(name='dilations', type=<AttrType.INTS: 7>, description='dilation value along each spatial axis of the filter. If not present, the dilation defaults is 1 along each spatial axis.', default_value=, required=False)

I wonder, how it handled in onnxruntime, just hardcoded?

@leshabirukov
Copy link
Author

I would rather put defaults handler outside of matcher, with function like force_defaults(node) =>node, forced keys probably paired with strip_defaults

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested topic: rewriter
Projects
None yet
Development

No branches or pull requests

2 participants