tensorflow: Deadlock on recursive tf.function-decorated function

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 19.10
  • TensorFlow installed from (source or binary): binary, conda
  • TensorFlow version (use command below): unknown 2.0.0
  • Python version: 3.7

Describe the current behavior

Recursive calls with a tf.function decorated python function results in a deadlock. A minimal example is provided below.

Where it gets stuck: by recursively calling _maybe_define_function, which internally requires a lock (line 2118 in tensorflow_core/python/eager.function.py). This seems to deadlock when trying to create a graph function again invoking itself.

About use-cases: yes, there are. But yes, in principle, there are “workarounds”. But I assume this is not in general intended to produce a deadlock anyway, should it? If so, I would rather propose a loud failure.

Code to reproduce the issue

@tf.function(autograph=False)
def func1(depth=0):
    if depth > 1:
        return depth
    else:
        return func1(depth + 1)

func1(0)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 15 (10 by maintainers)

Most upvoted comments

I can confirm this is the case for me, too.