Tensorflow2.0 @tensorflow.function的角色

Tensorflow2.0 @tensorflow.function的角色,tensorflow2.0,Tensorflow2.0,我以两种方式在colab中运行此代码。一次使用@tf.function,一次不使用它。但结果是一样的。@tf.function的作用是什么 import tensorflow as tf @tf.function def f(x, y): return x ** 2 + y x = tf.constant([2, 3]) y = tf.constant([3, -2]) f(x, y)

我以两种方式在colab中运行此代码。一次使用@tf.function,一次不使用它。但结果是一样的。@tf.function的作用是什么

import tensorflow as tf
@tf.function
def f(x, y):
  return x ** 2 + y
x = tf.constant([2, 3])
y = tf.constant([3, -2])
f(x, y)