-
Notifications
You must be signed in to change notification settings - Fork 526
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
enable TF remapper optimizer #1418
Conversation
TF supports a remapper optimizer which remaps subgraphs onto more efficient implementations by replacing commonly occuring subgraphs with optimized fused monolithic kernels. However, its support is limited: (1) MatMul + BiasAdd (not Add) + Activation; (2) Float32 (but not float64); (3) Activation is Tanh; (4) MKL is built and used. This commit replaces Add by BiasAdd in the NN. The speed of a single op can be improved by about 20% when TF is using MKL and precision is set to float32. One can find `_MklNativeFusedMatMul` op in the profiler. See also: - https://www.tensorflow.org/guide/graph_optimization - https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/grappler/optimizers/remapper.cc (cherry picked from commit 8f2dc44)
Codecov Report
@@ Coverage Diff @@
## devel #1418 +/- ##
==========================================
+ Coverage 74.55% 75.72% +1.17%
==========================================
Files 92 92
Lines 7623 7650 +27
==========================================
+ Hits 5683 5793 +110
+ Misses 1940 1857 -83
Continue to review full report at Codecov.
|
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 this change compatible to tf 1.x?
This PR only introduces The support for tanh + MKL is introduced in tensorflow/tensorflow#42173 (v2.4). I don't know why only FP32 is supported. |
I found that Intel OneDNN does not support fp64 at all... |
I have some other ideas: we can customize a remapper optimizer. TF has provided the interface. |
TF supports a remapper optimizer which remaps subgraphs onto more efficient implementations by replacing commonly occuring subgraphs with optimized fused monolithic kernels. However, its support is limited: (1)
MatMul
+BiasAdd
(notAdd
) + Activation; (2) Float32 (but not float64); (3) Activation is Tanh; (4) MKL is built and used.This commit replaces
Add
byBiasAdd
in the NN. The speed of a single op can be improved by about 20% when TF is using MKL and precision is set to float32. One can find_MklNativeFusedMatMul
op in the profiler.Original graph. Ops include MklMatMul, AddV2, and Tanh.
New graph.
_MklNativeFusedMatMul
is used here.See also:
(cherry picked from commit 8f2dc44)