question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unreserve_name function does not respect already declared variables

See original GitHub issue

I believe there is a bug in the Scope.unreserve_name function: It removes the name from the Scope.onnx_variable_names even if it is already declared in Scope.variables.

https://github.com/onnx/sklearn-onnx/blob/314cd07c19a78597c15c2ea10862b4e5d4318aa5/skl2onnx/common/_topology.py#L650-L658

If that happens then variables in Scope.variables could get overwritten. That is because the unique variable name is not taken anymore but a name-variable pair is already set in Scope.variables.

https://github.com/onnx/sklearn-onnx/blob/314cd07c19a78597c15c2ea10862b4e5d4318aa5/skl2onnx/common/_topology.py#L624-L628

This happened to me and was quite difficult to debug.


My suggested solution is to only unreserve an ONNX name, if the name is not already used in Scope.variables. If it is, then it should raise a warning instead of throwing an error. You could also make it throw an error, but then you’d have to fix it in parse_sklearn (which is I believe the only time the unreserve_name function is actually called):

https://github.com/onnx/sklearn-onnx/blob/314cd07c19a78597c15c2ea10862b4e5d4318aa5/skl2onnx/_parse.py#L566-L568

Another approach would be to get rid of unreserve_name altogether, since it’s only called once and doesn’t seem particularly useful. But maybe I’m mistaken here. 🙂

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
xaduprecommented, Aug 31, 2021

I think the current design is over complicated. PR #726 simplifies it. It removes reserved_names. I’ll see if it is not too complicated to ix all unit tests it will probably break. parser and shape_calculator could be removed.

0reactions
xaduprecommented, Sep 1, 2021

Thanks, #726 is ready to be reviewed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid declaration of already declared variables in Visual C++
One way is to write small functions and refactor your function once it reaches say 80 lines. Such problems are more prominent in...
Read more >
Crash when trying to declare an already declared variable ...
The parser does not detect a previously declared variable when declaring a new one, while using an experimental pragma .
Read more >
Variable declarations (Dynare Reference Manual)
First, variables and parameters must not have the same name as Dynare commands or built-in functions. In this respect, Dynare is not case-sensitive....
Read more >
Variables/FB Instances: Declaring in Variables Worksheets
Local variable: open the local variables worksheet either by clicking the 'Toggle WS' icon on the toolbar while the related code worksheet is...
Read more >
Class variables, method variables and scope
The concept of scope was introduced in section 3, but now it has to be extended to include methods and classes. Similarly x...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found