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

Strage Behavior of FoldConstants Transformation #104

Open
iksnagreb opened this issue Feb 29, 2024 · 1 comment · May be fixed by #107
Open

Strage Behavior of FoldConstants Transformation #104

iksnagreb opened this issue Feb 29, 2024 · 1 comment · May be fixed by #107
Labels
bug Something isn't working

Comments

@iksnagreb
Copy link
Contributor

Occasionally, I had the FoldConstants transformation produce wrong shape constants when applied to Reshape nodes where the shape input is produced by a bunch of Shape-Gather-Unsqueeze-Concat operators (this seems to be common export behavior of PyTorch to produce these, but it should be easily constant-fold-able when all shapes are known at export time). By "wrong" I mean at least one axis is zero and the resulting graph is broken beyond repair from that point on (all following shapes make no sense at all). I have not really an idea what exactly is going on and giving a minimal example is difficult as it seems to occur only for more complex operator patterns deeper inside the model (e.g., the same pattern is folded fine in the first layer but then it breaks in the second), but a fix seems to be trivial: Insert a break here, leaving the loop to remove the node and re-do the shape annotations after each folded constant instead of just once at the end.

Not sure whether this is the proper way to solve this and I will try to follow up on this, hopefully with a reproducible example later, but before I forget I wanted to document this issue and maybe someone else already encountered this or something similar and knows what is going on.

@iksnagreb iksnagreb added the bug Something isn't working label Feb 29, 2024
@maltanar
Copy link
Collaborator

maltanar commented Mar 5, 2024

This may be related to on-the-fly modifications of the model.graph.node container, I've previously observed some weird behavior too when nodes are being added/removed to the container as some transformation iterates over it. This can give rise to some very confusing bugs, and the easiest way out is actually to stop iterating over the node container once a node is is added/removed and let the transformation run once again. Adding break at that location in FoldConstants, as you suggest above, should be taking care of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants