Conversation
|
the input mutation is not a concern in jax which never does Inplace by default. Your test isn't strong enough because the compare py and numba (or other backend) run minimal rewrites you need to pass the fully fledged mode as an argument or even simpler test with an already inplace set subtensor (pass inplace=true to the test) and then call the function again |
|
After looking into this more I'm not sure your worry is founded:
I had the robot go at it every which way, it only mutated if the two guards noted above are disabled. I guess I could disable them, then try to make that work? Surely this isn't the only inplace elemwise operation? |
06f7677 to
2846433
Compare
|
|
||
| x = pt.zvector("x") | ||
| out = pt.real(x)[0].set(99.0) | ||
| f = function([In(x, mutable=True)], out, mode=pytorch_mode) |
There was a problem hiding this comment.
PyTensor would be allowed to destroy this x. The issue would be if it weren't she still destroyed it
There was a problem hiding this comment.
When I said inplace=True I meant the set subtensor op in your test could be inplace from the get go. That's how you know elemwise is not returning a view and the input is not destroyed accidentally
What worry is unfounded? You can't have an op return a view without stating so with view map. If it does you'll get wrong results eventually not just corrupted inputs. I didn't say you couldn't implement the behavior, you just have to check it doesn't return views?
That's how guards are supposed to work? I never said we HAD a bug, I just explained why np.real nfunc was commented out (so Elemwise perform doesn't try to use it directly) |
I think these are super rare. If there are more we need to forbid elemwise python mode from using it or force a copy after |
We have no coverage for this Op because it doesn't have an
nfunc_name. There was a concern that because numpy returns a view, we could end up with graph mutations that pytensor is not aware of. An example is:I added some checks for this specific case, it seems like everything works ok?