Minor additions to the guide about access to source code of functions.

PiperOrigin-RevId: 349276476
Change-Id: I2b93bf77e0942134f4c651e802ce29ff55b44dc5
This commit is contained in:
Dan Moldovan 2020-12-28 06:25:50 -08:00 committed by TensorFlower Gardener
parent a7d64fb21c
commit ec43d70760
2 changed files with 31 additions and 3 deletions

View File

@ -10,6 +10,11 @@ This warning is output when AutoGraph could not convert a function, for an
unexpected reason. The error message contains the reason why the function could
not be converted, as well as guidance on how to proceed next.
The exact error message may vary from version to version but in general, the
cause of the failure appears somewhere in the text, for example as
"Cause: could not get source code" or "Original error: could not get source
code".
Note: AutoGraph does not always output a warning. For example, constructors
are silently called without conversion.
@ -24,6 +29,16 @@ Note: the warning is output to the [abseil](https://github.com/abseil/abseil-py)
logger, with `WARNING` severity. To direct these warnings to `stdout`, use
`tf.autograph.set_verbosity(0, True)`.
### "Unable to locate the source code" or "Source not found" errors
Newer versions of AutoGraph raise a `ConversionError`. Older versions print a
warning. In both cases, a similar message about finding the source code is
included.
These errors are raised when AutoGraph is unable to find the source code of
functions it needs to transform. See [Limitations](limitations.md) for more
details.
### "WARNING: Large unrolled loop detected"
This warning is output when AutoGraph detects a `for` or `while` loop that

View File

@ -693,12 +693,25 @@ exceptions exist:
* functions created dynamically, using `exec` or `eval`
Use
[inspect.getsource](https://docs.python.org/3/library/inspect.html#inspect.getsource)
[inspect.findsource](https://docs.python.org/3/library/inspect.html#inspect.findsource)
to quickly diagnose whether the source code is available for a function.
For example:
```
import inspect
def simple_function():
return 1
# If this raises an error, then AutoGraph prints a warning.
# If it returns source code, then AutoGraph should work as well.
inspect.findsource(simple_function)
```
#### Source code of lambda functions
##### Changes in TF 2.4
##### TF 2.4 and newer
Key Point: When nesting lambda functions, use distinguishing argument names
to avoid parse errors.
@ -726,7 +739,7 @@ use distinct argument names:
l = lambda outer_x: lambda inner_x: inner_x + 1
```
##### TF 2.3 and older
##### Before TF 2.3 and older
In older versions of TensorFlow, the loading code for lambda functions is not
robust. Follow the guidance below to avoid errors.