Skip to content
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

Tensorflow: Performance bottleneck due to tf.function retracing #74

Closed
lazyoracle opened this issue Mar 18, 2021 · 0 comments · Fixed by #177
Closed

Tensorflow: Performance bottleneck due to tf.function retracing #74

lazyoracle opened this issue Mar 18, 2021 · 0 comments · Fixed by #177
Labels
bug Something isn't working tensorflow Tensorflow Performance and Implementation
Milestone

Comments

@lazyoracle
Copy link
Member

Describe the bug
Possible tensorflow performance bottleneck due to repeated tracing of tf.function decorated modules

To Reproduce
In Simulated_Calibration.ipynb:

C3:STATUS:Saving as: /tmp/tmpaz0djjuu/c3logs/ORBIT_cal/2021_03_16_T_16_57_04/calibration.log
(5_w,10)-aCMA-ES (mu_w=3.2,w_1=45%) in dimension 4 (seed=1004483, Tue Mar 16 16:57:04 2021)
C3:STATUS:Adding initial point to CMA sample.
WARNING:tensorflow:5 out of the last 14 calls to <function tf_matmul_left at 0x7f97602a8dd0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for  more details.

Suggested workarounds

Possible causes and solutions:

(1) creating @tf.function repeatedly in a loop, -- please define your @tf.function outside of the loop.
(2) passing tensors with different shapes, -- @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing.
(3) passing Python objects instead of tensors. -- please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.

@lazyoracle lazyoracle added bug Something isn't working tensorflow Tensorflow Performance and Implementation labels Mar 18, 2021
@lazyoracle lazyoracle moved this from To Do to Ongoing in Tensorflow performance Mar 1, 2022
@lazyoracle lazyoracle added this to the 1.5 milestone Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tensorflow Tensorflow Performance and Implementation
Projects
Development

Successfully merging a pull request may close this issue.

1 participant