Skip to content

register_initializer should create an unique name to resolve name collisions #246

@titaiwangms

Description

@titaiwangms

The feature was initially proposed here: microsoft/onnxscript#2680 (comment), where we saw a silent name collision leading to problematic optimized model.

We should firstly refactor rewrite rules to use the official initializer registration API to avoid silent errors:
https://github.com/microsoft/onnxscript/blob/478acf741471a4764d507d52a4ca6b544a63fc86/onnxscript/rewriter/_rewrite_rule.py#L685-L691

Also, instead of throwing errors, register_initializer can solve this automatically:

ir-py/src/onnx_ir/_core.py

Lines 2727 to 2743 in 926397c

def register_initializer(self, value: Value) -> None:
"""Register an initializer to the graph.
This is a convenience method to register an initializer to the graph with
checks.
Args:
value: The :class:`Value` to register as an initializer of the graph.
It must have its ``.const_value`` set.
Raises:
ValueError: If a value of the same name that is not this value
is already registered.
ValueError: If the value does not have a name.
ValueError: If the initializer is produced by a node.
ValueError: If the value does not have its ``.const_value`` set.
"""

cc @justinchuby @xadupre @gramalingam more thoughts

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions