Tensorflow 2 eager vs graph mode
You could always write two functions (one with the decorator and one without) and call whichever suits you... 

For example 

@tf.function()
def graph_function()
    # This function will operate in graph mode
    ...

def eager_function()
    # This function will operate in eager mode
   ...

if tf.executing_eagerly()
    my_function = eager_function
else:
    my_function = graph_function

# You proceed to my_function from now on


I don't know if there is a better way but I've seen this a lot being used in the tensorflow official repository on github.