-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add Document about the Graph Optimization in TensorFlow #511
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
Conversation
Thanks! |
site/en/guide/graphs.md
Outdated
Below optimizations are typical optimizations performed in TensorFlow. | ||
|
||
* **Constant Folding** evaluates the operations whose input tensors are all constant. | ||
* **Memory Optimizer** analyzes the TensorFlow graph to inspect the peak memory usage at each operations. To reduce a peak memory usage, Memory Optimizer inserts CPU-GPU memory copy operations for swapping GPU memory to CPU, or rewrites TensorFlow graph in order to the recomputation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing verb here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I fixed it.
site/en/guide/graphs.md
Outdated
* Enable Debug Stripper | ||
|
||
**Debug Stripper** which is disabled by default, strips the operations used for the debug purpose (Assert, CheckNumerics, Print). | ||
To enable Debug Stripper, you need to write codes as follows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To enable Debug Stripper, you need to write codes as follows. | |
To enable Debug Stripper, you need to write code as follows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for a suggestion. I fixed it.
site/en/guide/graphs.md
Outdated
**Debug Stripper** which is disabled by default, strips the operations used for the debug purpose (Assert, CheckNumerics, Print). | ||
To enable Debug Stripper, you need to write codes as follows. | ||
|
||
Only you need to do is changing `RewriteOptions::debug_stripper` enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only you need to do is changing `RewriteOptions::debug_stripper` enabled. | |
The only thing you need to do is enable `RewriteOptions::debug_stripper`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it.
site/en/guide/graphs.md
Outdated
To disable Constant Folding, you need to write code as follows. | ||
|
||
**Constant Folding** is performed more than two times on the graph optimization process in TensorFlow. | ||
You need to change not only `RewriteOptions::constant_folding`, but also `OptimizerOptions::opt_level`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to change not only `RewriteOptions::constant_folding`, but also `OptimizerOptions::opt_level`. | |
You need to change both`RewriteOptions::constant_folding`, and `OptimizerOptions::opt_level`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I fixed it.
site/en/guide/graphs.md
Outdated
To disable Constant Folding, you need to write code as follows. | ||
|
||
**Constant Folding** is performed more than two times on the graph optimization process in TensorFlow. | ||
You need to change not only `RewriteOptions::constant_folding`, but also `OptimizerOptions::opt_level`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a python doc, should we be referring to these by their python names?
like graph_options.rewrite_options.constant_folding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I replaced all parts like this issue in the document.
@suharshs, you know about graph optimizations. Can you validate this Docs PR, or suggest someone who can? Is anything here relevant to the tf2 docs? |
site/en/guide/graphs.md
Outdated
cfg.graph_options.optimizer_options.opt_level = config_pb2.OptimizerOptions.L0 | ||
|
||
# build the computation graph | ||
train_op = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best if code-examples are copy-paste runnable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added simple code-example.
site/en/guide/graphs.md
Outdated
cfg.graph_options.rewrite_options.debug_stripper = rewriter_config_pb2.RewriterConfig.ON | ||
|
||
# build the computation graph | ||
train_op = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put something here so the example is copy-paste runnable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added simple code-example too.
train_op = ... | ||
|
||
# execute the computation graph with Debug Stripper ON | ||
with tf.Session(config=cfg) as sess: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do something here to show that the optimization is really applied?
Maybe include an assert or check-numerics above, and then pass it bad data here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the instructions how to inspect the optimized graph as Inspect the Optimized Graph
section. Do these instructions match your intention?
train_op = ... | ||
|
||
# execute the computation graph with Debug Stripper ON | ||
with tf.Session(config=cfg) as sess: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can verify that this does what's expected? is there a way to inspect the optimized graph?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as "Constant Folding".
I think this is grappler specific, so @rmlarsen may be a better fit. |
We just released a slide deck about this used for a presentation given to the CS245 class at Stanford University on April 24, 2019. A recording of the talk should be available as well. |
Thanks for the review. This slide has lots of useful information. Thanks for sharing. At the beginning, I assumed that this document is for the beginner of the graph optimization. |
Hey @alextp, can you take a quick look at this pull request? |
@lamberta documenting the graph optimizations is a good idea. TF 2 has changed somewhat the syntax to control them, now it's in tf.config.optimizer: https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/config/optimizer I assume you'll proof-read for English mistakes and whatnot before merging, though. @ezhulenev @rmlarsen for FYI since you work on these parts of tf and might have strong opinions about the content in this document. |
Hi @nuka137, |
Hi, I'm so sorry for late reply. I'm going to resume this pull request. |
Thanks, @nuka137 I don't think we're going to have an separate Sound ok? |
Thanks! |
This pull request adds the document about the graph optimization performing internally in TensorFlow.
This document shows what optimizations are performed in TensorFlow, and how to enable/disable these optimizations from Python API.
I think most of TensorFlow beginners does not interests, but this document helps the advanced user who wants to control the graph optimizations manually.
P.S. I could not figure out where should I add this document, so I added to
site/en/guide/graphs.md
for temporary.