ponder-lab / Hybridize-Functions-Refactoring

Refactorings for optimizing imperative TensorFlow clients for greater efficiency.
Eclipse Public License 2.0
0 stars 0 forks source link

Add test case for multiple tf.function decorators on a single function, one with call and the other without #55

Open khatchad opened 2 years ago

khatchad commented 2 years ago

What happens when there's multiple tf.function decorators for the same function?

tatianacv commented 2 years ago

I just did some test with this in my local computer. The last tf.function is the only one that is taken into account.

For example:

import tensorflow as tf

@tf.function(experimental_follow_type_hints=True)
@tf.function(autograph=False)
def f(x: tf.Tensor):
  if x == 0: 
    tf.print('x is zero')
  print("Tracing")
  return x

f(1)

We would get the following error: OperatorNotAllowedInGraphError: Using a symbolic `tf.Tensor` as a Python `bool` is not allowed: AutoGraph is disabled in this function. Try decorating it directly with @tf.function.

But if we changed the order of the decorators:

import tensorflow as tf

@tf.function(autograph=False)
@tf.function(experimental_follow_type_hints=True)
def f(x: tf.Tensor):
  if x == 0: 
    tf.print('x is zero')
  print("Tracing")
  return x

f(1)

We wouldn't get the error, which means that it is not taking the autograph=False into account only tf.function(experimental_follow_type_hints=True). Also, we see that tf.function(experimental_follow_type_hints=True) is working as intended.

khatchad commented 1 year ago

It takes the last one.

khatchad commented 1 year ago

Our code should take the last one.

tatianacv commented 1 year ago

@khatchad I believe we have already done this in #37

khatchad commented 1 year ago

37 is a PR. Usually you would mark an issue as a duplicate of another issue.

tatianacv commented 1 year ago

This is a specific case of #30, which we closed. Therefore, I believe we can close this issue.

khatchad commented 1 year ago

30 is only about parameters. This issue sounds much more general.

khatchad commented 1 year ago

In fact, the issue description doesn't mention parameters at all.

khatchad commented 1 year ago

I see a test for multiple decorators but not multiple tf.function decorators.

khatchad commented 1 year ago

Actually, I see it in testComputeParameters12.

khatchad commented 1 year ago

And, that is the only one.

khatchad commented 1 year ago

And, the code for that case doesn't check that the function is hybrid.

khatchad commented 1 year ago

And, it's only the call case.

khatchad commented 1 year ago

@tatianacv Please add two test cases for this; one for the call and one for the non-call case.