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

py_function is slower in TF2.7 (and 2.6) compared to TF2.5 #53620

Open
anth2o opened this issue Jan 3, 2022 · 2 comments
Open

py_function is slower in TF2.7 (and 2.6) compared to TF2.5 #53620

anth2o opened this issue Jan 3, 2022 · 2 comments
Assignees
Labels
comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.9 Issues found in the TF 2.9 release (or RCs) type:performance Performance Issue

Comments

@anth2o
Copy link

anth2o commented Jan 3, 2022

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
  • TensorFlow installed from (source or binary): docker
  • TensorFlow version (use command below): 2.7
  • Python version: 3.8.10

Describe the current behavior

In my training code I'm using tf.data.Dataset.map with a tf.py_function within it. I know that using tf.py_function is slower than regular tensorflow, but there's a part of my dataset processing that requires the usage of plain Python code.

However, when I tried to upgrade TF from 2.5 to 2.6, I noticed that my trainings were slower in 2.6 compared to 2.5. I postponed the upgrade at the moment. When 2.7 came out I tried again but the slower data processing was still present.

Describe the expected behavior

I would have expected this kind of code to be as efficient as it was in 2.5

Standalone code to reproduce the issue

You can find a reproducible example in this colab.

To reproduce my issue, I wrapped the opening of the image on disk within a tf.py_function and opened it using Pillow and numpy. I know that this can be done in a more efficient way as I explained directly in the colab.

Here are the results I got when executing the %%timeit cell with 2 different versions of TF:

  • tf.version = "2.7.0" -> 3 loops, best of 7: 1.81 s per loop (would have been the same in TF2.6)
  • tf.version = "2.5.2" -> 3 loops, best of 7: 1.44 s per loop
@anth2o anth2o added the type:performance Performance Issue label Jan 3, 2022
@anth2o anth2o changed the title tf.py_function is slower in TF2.7 compared to TF2.5 py_function is slower in TF2.7 (and 2.6) compared to TF2.5 Jan 3, 2022
@mohantym mohantym added TF 2.7 Issues related to TF 2.7.0 comp:ops OPs related issues labels Jan 4, 2022
@mohantym
Copy link
Contributor

mohantym commented Jan 4, 2022

Hi @chunduriv ! Could you please look at this issue? Attaching Gist in 2.7 and 2.6 for reference .Thank you!

Updated
Was able to replicate the issue with Tf-nightly-2.11.0.dev20220822 .Please find the gist here. Thank you!

@mohantym mohantym assigned chunduriv and unassigned mohantym Jan 4, 2022
@sushreebarsa sushreebarsa assigned Saduf2019 and unassigned chunduriv Jan 6, 2022
@Saduf2019 Saduf2019 assigned sachinprasadhs and unassigned Saduf2019 Jan 6, 2022
@sachinprasadhs sachinprasadhs added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jan 12, 2022
@bgdax
Copy link

bgdax commented Jan 13, 2022

Thanks for raising this issue. We are looking into it.

@gadagashwini gadagashwini added TF 2.9 Issues found in the TF 2.9 release (or RCs) and removed TF 2.7 Issues related to TF 2.7.0 labels Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.9 Issues found in the TF 2.9 release (or RCs) type:performance Performance Issue
Projects
None yet
Development

No branches or pull requests

7 participants