-
Notifications
You must be signed in to change notification settings - Fork 74k
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
AutoGraph cannot handle python 3.10's structural pattern matching #57166
Comments
Hi @burnpanck, When I executed given code, it worked as expected. Tested with
|
Hey @gadagashwini, thanks for looking into this. Please note that in my case, the code does execute as well. The traceback I posted under "relevant log output" is really a logged message (right after the warning that I mention), not from an exception that reaches my code. Your code logs the same warning - although the reason it gives is different: Either way, do not expect the code to throw an exception. The issue that I'm reporting here is the warning message both our runs are logging, and the implications: The example code is not being handled by AutoGraph, even though it still can execute. |
Any updates here? Still present in TF 2.15.0. Structural pattern matching is part of standard Python and by now several years and python releases old. If AutoGraph cannot handle structural pattern matching, it basically means it is unable to read the python syntax. This is a pity, because pattern matching is very useful, even if it does not involve any tensors. That is, supporting the syntax is important even if the syntax does not unlock any tensor operations. As the feature becomes more well-known, this will only grow in importance. |
@burnpanck I think TensorFlow's AutoGraph may not yet have implemented support for converting this syntax into graph operations.Did u try another approach ? |
@Datamagician10 You think right. AutoGraph does not support structural pattern matching, despite this being a standard python feature since almost three years now (python 3.10 was released in 2021) - that is what I am reporting here. @mdanatg @gowthamkpr @sushreebarsa @gadagashwini Each of you were assigned to this at some point, but it seems the issue has now fallen between the cracks. Implementing this shouldn't be too difficult. Judging from previous release schedules, the next TF release may well drop support for python 3.9, at which point basically doesn't support any version of python correctly at all anymore! |
I do see that AutoGraph in fact offers to convert some python control statements into TF graphs. To support that use-case, AutoGraph needs to "read and understand" the python AST at some point before running the TF graph (i.e. during the first phase that includes tracing). For example, the documentation states that |
Click to expand!
Issue Type
Bug
Source
binary
Tensorflow Version
2.9.2
Custom Code
No
OS Platform and Distribution
macOS 12.5
Mobile device
none
Python version
3.10
Bazel version
No response
GCC/Compiler version
No response
CUDA/cuDNN version
none
GPU model and memory
Apple's METAL (though unlikely to be relevant here)
Current Behaviour?
Trying to AutoGraph a function containing a PEP 634/635/636 structural pattern matching statement from python 3.10 (i.e.
match/case
) results in theWARNING:tensorflow:AutoGraph could not transform <function test at 0x2c4c99120> and will run it as-is.
Standalone code to reproduce the issue
Relevant log output
The text was updated successfully, but these errors were encountered: