Don't replace unused variables with None - #2396
Conversation
|
Some grad tests are failing in a non-trivial way. In the case of |
|
Could you please check whether the error goes away if |
|
I would not expect clone (which is not what PyTorch does, it really does identity.) Maybe what is missing is something in |
|
You are right, @t-vi , that still fails with "Encountered exception ValueError: Variable t1 is being overwritten this is not allowed while tracing Model()", though this failure is unrelated to removing this helper function. Using |
|
Btw, which |
|
Couldn't we del _ instead when it is assigned? |
The underscore doesn't appear until the printing process and is otherwise represented as |
|
I think the del_last_used could check if the return is a tuple and if it is it can just iterate over that instead of using flat proxy outs. This would allow you to detect none properly. |
|
@t-vi I'm not understanding your last comment, or at least the motivation behind it. Correct me if I'm wrong, but it seems like you are suggesting that unused TensorProxies should continue to be replaced with None in the dce pass and that del_last_used should then tidy things up. What is the advantage of replacing an unused TensorProxy with None in a bsym's outs? |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
t-vi
left a comment
There was a problem hiding this comment.
Thank you @beverlylytle @IvanYashchuk @crcrpar
Created, but unused variables in a Thunder jitted program are replaced by a placeholder
None, which, then in the executable is replaced by_, as is conventional in Python. More concretely,would be represented by a trace with a bound symbol for the var_mean op with output consisting of a TensorProxy and None, which then would be executed as something like
y, _ = torch.var_mean(x). Not only is it confusing to seeNoneseemingly being assigned a value, this variable_takes up memory and is never deleted. This PR leaves the unused variable as a TensorProxy so that it can be removed withdel_last_used.