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

informing about bad positional argument in node constructor #1984

Open
leshabirukov opened this issue Dec 26, 2024 · 2 comments
Open

informing about bad positional argument in node constructor #1984

leshabirukov opened this issue Dec 26, 2024 · 2 comments
Assignees
Labels
contribution welcome We welcome code contributions for this

Comments

@leshabirukov
Copy link

rewr.txt

When you mistakingly do

  def lr_pattern( op, x ):
      return op.LeakyRelu( x, 1.0)

instead of

  def lr_pattern_good( op, x ):
      return op.LeakyRelu( x, alpha=1.0)

You will get such error text:

AttributeError: 'float' object has no attribute '_add_usage'

Expected behavior: something like

TypeError: LeakyRelu() takes 2 positional arguments but 3 were given

Possible patch: missed_keyword.patch

@justinchuby justinchuby self-assigned this Dec 27, 2024
@justinchuby
Copy link
Collaborator

Thanks! Will fix

@justinchuby justinchuby added the contribution welcome We welcome code contributions for this label Dec 30, 2024
leshabirukov added a commit to leshabirukov/onnxscript that referenced this issue Dec 30, 2024
Patch for Big Brother issue!  
microsoft#1984
@leshabirukov
Copy link
Author

I have a question:

is opset??.Operation supposed to allow non-Value wrapped arguments? I see here

inputs = [_to_value_pattern(x) for x in args]

if isinstance(x, (int, float)):

OpPatternBuilder try to wrap float as Constant, returning Value(None). But it ends with this topic problem.

By the way, traceback:

Matched: Identity
Traceback (most recent call last):
  File "C:\Users\lesha\Documents\GitHub\onnxscript\.hypothesis\letsbegin.py", line 33, in <module>
    apply_to_file("with_id.onnx", [rule_to_lr, ])
  File "C:\Users\lesha\Documents\GitHub\onnxscript\.hypothesis\letsbegin.py", line 23, in apply_to_file
    rule[0].apply_to_model(ir_model)
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\rewriter\pattern.py", line 1348, in apply_to_model
    return RewriteRuleSet([self], commute=commute).apply_to_model(model, verbose=verbose)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\rewriter\pattern.py", line 1503, in apply_to_model
    count = self._apply_to_graph_or_function(model, model.graph, verbose=verbose)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\rewriter\pattern.py", line 1479, in _apply_to_graph_or_function
    delta = rule.try_rewrite(model, graph_or_function, node, verbose=verbose)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\rewriter\pattern.py", line 1329, in try_rewrite
    replacement_subgraph = self._replacement_pattern.get_replacement(match)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\rewriter\pattern.py", line 915, in get_replacement
    new_outputs = self._function(context, **match.bindings)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\.hypothesis\letsbegin.py", line 12, in lr_pattern
    return op.LeakyRelu(x, 1.0)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\ir\_tape.py", line 76, in <lambda>
    return lambda *args, **kwargs: self._make_node(op_type, args, kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\ir\_tape.py", line 90, in _make_node
    value = super().op(op_type, inputs=inputs, attributes=kwargs, domain=domain)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\ir\_tape.py", line 40, in op
    node = ir.Node(domain, op_type, inputs, attributes=attrs, num_outputs=1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lesha\Documents\GitHub\onnxscript\onnxscript\ir\_core.py", line 1157, in __init__
    input_value._add_usage(self, i)  # pylint: disable=protected-access
    ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'float' object has no attribute '_add_usage'

Process finished with exit code 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome We welcome code contributions for this
Projects
None yet
Development

No branches or pull requests

2 participants