Better example code for the "Taking advantage of graphs" section#2424
Open
HsienChing wants to merge 1 commit intotensorflow:masterfrom
Open
Better example code for the "Taking advantage of graphs" section#2424HsienChing wants to merge 1 commit intotensorflow:masterfrom
HsienChing wants to merge 1 commit intotensorflow:masterfrom
Conversation
# Better example code for the "Taking advantage of graphs" section **Position:** "Taking advantage of graphs" section **Link:** https://www.tensorflow.org/guide/intro_to_graphs#taking_advantage_of_graphs **Condition:** The example code is OK, no bug. I am talking about a more detailed consideration about the tutorial. In the last line of the example code, the `assert` keyword is used to check the values between `a_regular_function()` and `tf.function(a_regular_function)`. ```Python assert(orig_value == tf_function_value) ``` However, when I run the code, nothing happens. As I learned the usage of `assert`, I understood that "noting happens" indicates "orig_value == tf_function_value". NOTE: In Python, the [`assert`](https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-assert_stmt) keyword is a debugging tool used to verify that a condition is true. If the condition evaluates to False, the program immediately raises an AssertionError and terminates, helping developers catch bugs during the development and testing phases. **Suggestion:** In my opinion, a tutorial should give readers an "explicit" guide instead of an "implicit" guide. Using `print` is a better choice than using `assert`. When using `print`, a `True` or `False` will be sent according to the conditional expression `orig_value == tf_function_value`, and readers will understand the result explicitly and immediately. ```Python print(orig_value == tf_function_value) ``` REF: https://github.com/HsienChing/ML_DL_project_State_Estimation_of_Li-ion_Batteries/blob/main/other/Issues_in_TensorFlow_official_doc_Introduction_to_graphs_and_tf.function.ipynb
PreviewPreview and run these notebook edits with Google Colab: Rendered notebook diffs available on ReviewNB.com.Format and styleUse the TensorFlow docs notebook tools to format for consistent source diffs and lint for style:$ python3 -m pip install -U --user git+https://github.com/tensorflow/docsIf commits are added to the pull request, synchronize your local branch: git pull origin patch-4
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Better example code for the "Taking advantage of graphs" section
Position:
"Taking advantage of graphs" section
Link:
https://www.tensorflow.org/guide/intro_to_graphs#taking_advantage_of_graphs
Condition:
The example code is OK, no bug. I am talking about a more detailed consideration about the tutorial.
In the last line of the example code, the
assertkeyword is used to check the values betweena_regular_function()andtf.function(a_regular_function).However, when I run the code, nothing happens. As I learned the usage of
assert, I understood that "noting happens" indicates "orig_value == tf_function_value".NOTE: In Python, the
assertkeyword is a debugging tool used to verify that a condition is true. If the condition evaluates to False, the program immediately raises an AssertionError and terminates, helping developers catch bugs during the development and testing phases.Suggestion:
In my opinion, a tutorial should give readers an "explicit" guide instead of an "implicit" guide. Using
printis a better choice than usingassert.When using
print, aTrueorFalsewill be sent according to the conditional expressionorig_value == tf_function_value, and readers will understand the result explicitly and immediately.REF: https://github.com/HsienChing/ML_DL_project_State_Estimation_of_Li-ion_Batteries/blob/main/other/Issues_in_TensorFlow_official_doc_Introduction_to_graphs_and_tf.function.ipynb