-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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
fix precision error in constraint solver #101307
Conversation
When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values. However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints: `sympy.nsimplify` does the job. As an alternative approach, we considered using `sympy.evalf` to compare with reduced precision. But we did not pursue it because * the choice of what is a good reduced precision feels arbitrary (`sympy` uses `1e15` by default); * more importantly, there is no guarantee that we will not encounter the same problem when solving downstream. Differential Revision: [D45826951](https://our.internmc.facebook.com/intern/diff/D45826951/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/101307
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 5fe132c: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This fixes #101093. |
When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values. However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints: `sympy.nsimplify` does the job. As an alternative approach, we considered using `sympy.evalf` to compare with reduced precision. But we did not pursue it because * the choice of what is a good reduced precision feels arbitrary (`sympy` uses `1e15` by default); * more importantly, there is no guarantee that we will not encounter the same problem when solving downstream. Differential Revision: [D45826951](https://our.internmc.facebook.com/intern/diff/D45826951/) [ghstack-poisoned]
When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values. However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints: `sympy.nsimplify` does the job. As an alternative approach, we considered using `sympy.evalf` to compare with reduced precision. But we did not pursue it because * the choice of what is a good reduced precision feels arbitrary (`sympy` uses `1e15` by default); * more importantly, there is no guarantee that we will not encounter the same problem when solving downstream. Differential Revision: [D45826951](https://our.internmc.facebook.com/intern/diff/D45826951/) [ghstack-poisoned]
Pull Request resolved: #101307 When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values. However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints: `sympy.nsimplify` does the job. As an alternative approach, we considered using `sympy.evalf` to compare with reduced precision. But we did not pursue it because * the choice of what is a good reduced precision feels arbitrary (`sympy` uses `1e15` by default); * more importantly, there is no guarantee that we will not encounter the same problem when solving downstream. ghstack-source-id: 189013892 Differential Revision: [D45826951](https://our.internmc.facebook.com/intern/diff/D45826951/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this should work, but using nsimplify seems like a really big hammer here
When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values. However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints: `sympy.nsimplify` does the job. As an alternative approach, we considered using `sympy.evalf` to compare with reduced precision. But we did not pursue it because * the choice of what is a good reduced precision feels arbitrary (`sympy` uses `1e15` by default); * more importantly, there is no guarantee that we will not encounter the same problem when solving downstream. Differential Revision: [D45826951](https://our.internmc.facebook.com/intern/diff/D45826951/) [ghstack-poisoned]
Pull Request resolved: #101307 When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values. However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints: `sympy.nsimplify` does the job. As an alternative approach, we considered using `sympy.evalf` to compare with reduced precision. But we did not pursue it because * the choice of what is a good reduced precision feels arbitrary (`sympy` uses `1e15` by default); * more importantly, there is no guarantee that we will not encounter the same problem when solving downstream. ghstack-source-id: 189095998 Differential Revision: [D45826951](https://our.internmc.facebook.com/intern/diff/D45826951/)
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
In #101307 we tried to fix #101093 using `nsimplify` to convert floats into rationals, but the fix is not reliable: it is possible for `nsimplify` to pick constants that don't work. Currently, constraint solving is only used by `export`, but constraints are added in all modes. This means that we can hit this issue even in non-`export` modes. This diff works around this issue for such modes by delaying raising such failures until constraint solving. Differential Revision: [D45922797](https://our.internmc.facebook.com/intern/diff/D45922797/) [ghstack-poisoned]
In #101307 we tried to fix #101093 using `nsimplify` to convert floats into rationals, but the fix is not reliable: it is possible for `nsimplify` to pick constants that don't work. Currently, constraint solving is only used by `export`, but constraints are added in all modes. This means that we can hit this issue even in non-`export` modes. This diff works around this issue for such modes by delaying raising such failures until constraint solving. Differential Revision: [D45922797](https://our.internmc.facebook.com/intern/diff/D45922797/) ghstack-source-id: 189321831 Pull Request resolved: #101607
In #101307 we tried to fix #101093 using `nsimplify` to convert floats into rationals, but the fix is not reliable: it is possible for `nsimplify` to pick constants that don't work. Currently, constraint solving is only used by `export`, but constraints are added in all modes. This means that we can hit this issue even in non-`export` modes. This diff works around this issue for such modes by delaying raising such failures until constraint solving. Differential Revision: [D45922797](https://our.internmc.facebook.com/intern/diff/D45922797/) Pull Request resolved: #101607 Approved by: https://github.com/ezyang
When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values. However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints: `sympy.nsimplify` does the job. As an alternative approach, we considered using `sympy.evalf` to compare with reduced precision. But we did not pursue it because * the choice of what is a good reduced precision feels arbitrary (`sympy` uses `1e15` by default); * more importantly, there is no guarantee that we will not encounter the same problem when solving downstream. Differential Revision: [D45826951](https://our.internmc.facebook.com/intern/diff/D45826951/) Pull Request resolved: #101307 Approved by: https://github.com/ezyang
In #101307 we tried to fix #101093 using `nsimplify` to convert floats into rationals, but the fix is not reliable: it is possible for `nsimplify` to pick constants that don't work. Currently, constraint solving is only used by `export`, but constraints are added in all modes. This means that we can hit this issue even in non-`export` modes. This diff works around this issue for such modes by delaying raising such failures until constraint solving. Differential Revision: [D45922797](https://our.internmc.facebook.com/intern/diff/D45922797/) Pull Request resolved: #101607 Approved by: https://github.com/ezyang
Stack from ghstack (oldest at bottom):
When adding guards to the constraint solver, we check that they are consistent, i.e., they do not simplify to false when their free symbols are substituted with the corresponding concrete values.
However this check may "spuriously" fail because it doesn't take into account precision errors when comparing floats. Since the symbols involved are all positive integers, we try to approximate floats in the guards with rationals, providing concrete values as hints:
sympy.nsimplify
does the job.As an alternative approach, we considered using
sympy.evalf
to compare with reduced precision. But we did not pursue it becausesympy
uses1e15
by default);Differential Revision: D45826951