Skip to content

[Rewriter] Create a way to create an initializer in the rewrite pattern (and core onnxscript) #2016

Description

Allow this usage in the rewrite pattern

def replacement(x):
    tensor = ir.tensor(..., name="new_name")
    return op.Add(op.Initializer(tensor), x)

def replacement_when_y_is_const_node(x):
    # Q: How do I get that const node?
    ...

def replacement_transpose_initializer(x):
    tensor = x.const_value
    transposed = ir.tensor(tensor.numpy().T)
    return op.Initializer(transposed)
def Initializer(tensor: ir.TensorProtocol, name: str | None = None) -> ir.Value:
    # When name is None, the value name will be taken from the tensor
    # Otherwise the name is specified in name
    # Optionally we can also generate a name if nothing is specified, but I am not sure if that's error-prone
    ...

cc G. Ramalingam (@gramalingam) kunal-vaishnavi

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions