-
Notifications
You must be signed in to change notification settings - Fork 149
Passing check_parameters through minimize and tg.grad raises TypeError #1744
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
base: main
Are you sure you want to change the base?
Passing check_parameters through minimize and tg.grad raises TypeError #1744
Conversation
ricardoV94
left a comment
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.
Sorry this is actually masking an error. A ScalarFromTensor should have a scalar gradient, and therefore tensor_from_scalar is correct
Sorry I'm not quite following - do you mean that there is a deeper bug unrelated to this code, and fixing that bug means that this PR is unecessary? |
|
There's a deeper bug, your fix is making it.
Point 2. is the crux. Some Op gradient is returning a scalar when it should return a tensor, or some invalid graph manipulation was done. Need to find what variable is creating that tensor output gradient. Can you check if the variable has a traceback in |
|
Do you have a MWE that reproduces the bug? |
|
Sorry only just got back to this now!
I believe the example I give in the issue should be appropriate, or would you prefer smth more minimal? (it was as minimal as I could make it from the original bug).
I'll try to investigate when I get back to my PC around Monday next week. |
|
It's the minimize L_op fault, it return a tensor gradient for a scalar input. Here is a slightly more MWE with only PyTensor constructs: import pytensor.tensor as pt
from pytensor.raise_op import assert_op
theta = pt.scalar("theta")
x = pt.scalar("x")
obj = assert_op(x, theta > 0)
x0, _ = pt.optimize.minimize(objective=obj, x=x)
pt.grad(x0, theta) |
|
Should be patched by #1784 |
Addresses #1743