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

Grappler ImplementationSelector fails to use CUDNN (for GRU & LSTM) when using tf.data.experimental.scan #50325

Open
OmriSteiner opened this issue Jun 17, 2021 · 1 comment
Assignees
Labels
comp:data tf.data related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.5 Issues related to TF 2.5 type:bug Bug

Comments

@OmriSteiner
Copy link
Contributor

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): binary (latest-gpu docker)
  • TensorFlow version (use command below): v2.5.0-rc3-213-ga4dfb8d1a71 2.5.0 (but this also reproduces in earlier versions).
  • Python version: 3.6.9
  • CUDA/cuDNN version: 11.2 / 8.1.0
  • GPU model and memory: NVIDIA Quadro P1000

Describe the current behavior
As you can see in the code here, the way CUDNN LSTM & GRU are implemented, is by adding two functions with the same name to the graph. Grappler's ImplementationSelector optimizer runs later and selects the correct implementation. However, when using tf.data.experimental.scan, from what I've previously seen (I don't quite remember well), the function gets renamed - which causes the implementation selector to fail.
What actually happens is the non-CUDNN version is the default implementation - so it falls back to that one.

Describe the expected behavior
The layers should run using CUDNN, when possible.

Contributing

  • Do you want to contribute a PR? (yes/no): This might be a bit over my head, but if the solution is simple, I could implement it.
  • Briefly describe your candidate solution(if contributing):

Standalone code to reproduce the issue
Unfortunately I couldn't think of a way to display this issue without Tensorboard, but here it is:

import tensorflow as tf

model = tf.keras.models.Sequential([
    tf.keras.layers.GRU(4),
])

@tf.function
def foo(dataset):
    a = 1.
    # Autograph converts this to tf.data.experimental.scan
    for i in dataset:
        a = model(i)
    return a # return the value to avoid pruning

inp_tensor = tf.random.normal([32, 10, 8])
dataset = tf.data.Dataset.from_tensor_slices([inp_tensor])

tf.profiler.experimental.start("/tmp/tensorboard")

# This successfully uses CUDNN
model.predict(inp_tensor)

# This doesn't use CUDNN
foo(dataset)

tf.profiler.experimental.stop()

Here you can see model.predict uses CUDNN:
image

And here you can see foo(dataset) does not use CUDNN:
image

@OmriSteiner OmriSteiner added the type:bug Bug label Jun 17, 2021
@tilakrayal tilakrayal added TF 2.5 Issues related to TF 2.5 comp:grappler Grappler related issues comp:data tf.data related issues labels Jun 17, 2021
@tilakrayal
Copy link
Contributor

I was able to reproduce the code in tf v2.4 and v2.5.Please find the gist of it here.

@tilakrayal tilakrayal assigned rmothukuru and unassigned tilakrayal Jun 18, 2021
@rmothukuru rmothukuru assigned ymodak and unassigned rmothukuru Jun 18, 2021
@ymodak ymodak added stat:awaiting tensorflower Status - Awaiting response from tensorflower and removed comp:grappler Grappler related issues labels Jun 18, 2021
@ymodak ymodak assigned aaudiber and unassigned ymodak Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:data tf.data related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.5 Issues related to TF 2.5 type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants