-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
(torch) Use pure-python implementation of tree
when in dynamo context
#18614
Comments
Do we have a way to tell when we're in a Dynamo context? |
Should we start using Optree instead? |
If we add a |
+1 for optree. |
Hi @james77777778 , Seems Is my understanding correct? We may need this info for future work of supporting torch dynamo. |
Actually, I just picked the item from: #18442 (a few months ago) In the PR, I didn't achieve a significant speed-up by replacing It's a bit strange for me as well, considering that Refs:
Perhaps we need a completely pure python implementation for dynamo? |
Motivation
any_symbolic_tensors
is called on pretty much all ops and it internally usestree.flatten()
to check if any positional or keyword arguments to the op is aKerasTensor
(e.g. symbolic tensor). torchdynamo skips tracingtree
(presumably since it has C-bindings) therefore causing graph-breaks at each op. This results in poor jitted performance for the pytorch backend since the graph-breaks occur between each op and we lose opportunities for any significant compiler optimizations (e.g. operator fusion).See #18569 for more details.
Proposal
tree.flatten()
and use that instead oftree.flatten()
to prevent graph-breaks atany_symbolic_tensors()
.tree.*
then (as suggested by @fchollet in (re)enable torch.compile in the pytorch trainer for train, predict, and eval #18569) we need to create akeras.utils.tree
that uses pure-python implementations when in dynamo context and replace usages oftree.*
withkeras.utils.tree.*
.My suggestion is to first to 1), then see if 2) is needed as 2) is a bigger change that we may not actually need.
The text was updated successfully, but these errors were encountered: