Questions tagged [eager-execution]

TensorFlow's eager execution is an imperative programming environment that evaluates operations immediately, without building graphs: operations return concrete values instead of constructing a computational graph to run later. This makes it easy to get started with TensorFlow and debug models, and it reduces boilerplate as well. To follow along with this guide, run the code samples below in an interactive python interpreter.

146 questions
0
votes
0 answers

tf.executing_eagerly() returns true even when in graph mode

Why tf.executing_eagerly() returns True after tf.config.run_functions_eagerly(False)? Python 3.9.13 TensorFlow version: 2.10.0 @tf.function def my_func(a): print("Python side effect") return a + a a_fn = tf.function(my_func)
mon
  • 18,789
  • 22
  • 112
  • 205
0
votes
0 answers

Tf.mirrored strategy enabling eager execution of code

I am using tensorflow2.6 and my code requires setting the below code at starting because I use symbolic keras tensor in partial loss in my model from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution() At the…
0
votes
0 answers

PyTorch vs Tensorflow Eager Execution - Slowdown with repeatedly calling prediction for RL

I'm trying to do some RL, this requires repeatedly calling model.predict or model.forward instead of calling either function on large batches. I noticed that this was going surprisingly slow. For example, the following code ran (on CPU) in around 6…
0
votes
0 answers

Tensorflow learning stucks at a random step and produces a lot of warnings

I set tf.config.experimental.set_device_policy('warn') and when I call fit() function the learning process might get stuck on a random step and epoch while producing these warnings each step: W tensorflow/core/common_runtime/eager/execute.cc:169]…
Delinester
  • 21
  • 3
0
votes
2 answers

Tensorflow 2 graph mode - For loop in a model train_step() function?

I am struggling to make a loop work in a model train_step() function in graph mode. =====> Please jump directly to UPDATE below The following snippet, which works in eager mode but not in graph mode, is not my train_step() code but if someone could…
u2gilles
  • 6,888
  • 7
  • 51
  • 75
0
votes
0 answers

tf.while_loop to specify a less-specific shape

I try to iterate inside a while loop but I get this error, I have several variables involved in the loop, the solution I think is to use the loop_vars, but I am not clear if for all the variables or only for the out, I am in my beginnings in…
milk
  • 1
  • 1
0
votes
0 answers

Why is eager execute required when using my custom loss function?

QUESTION: Why does my custom loss function require run_eagerly parameter to be set to True in the compile method in TensorFlow? BACKGROUND: I have built a CNN with TensorFlow 2.8.1 to classify CIFAR-100 images using a custom loss function. The…
0
votes
1 answer

How to re-write tensorflow code to make model training faster?

QUESTION: My training is super slow. How do I rewrite my code to make my deep learning model training faster? BACKGROUND: I have built a CNN with TensorFlow 2.8.1 to classify CIFAR-100 images using a custom loss function. The CIFAR dataset…
0
votes
1 answer

tf.train.Checkpoint and loading weights

I'm training a model for seq2Seq using tensorflow. correct me if I'm wrong. I understood that the tf.train.Checkpoint is used to save just the checkpoint files which are only useful when source code that will use the saved parameter values is…
Al Mi
  • 63
  • 5
0
votes
1 answer

segmentation fault in tensorflow eager execution?

I use the mirrored strategy in my Tensorflow2 code, as described in this tutorial: https://www.tensorflow.org/guide/distributed_training. I have almost the same exact code, and the setup is working well for about 1.5 years now. I regularly put the…
0
votes
1 answer

Converting KerasTensor to numpy array

I am trying to convert "KerasTensor" into numpy array. I have tried converting KerasTensor to tf.Tensor (with no luck). I have also tried using tensor.numpy(), tensor.eval() and keras.backend.eval(tensor) all of that have not worked. Trying…
user9447544
0
votes
2 answers

Can't input data to custom loss: Inputs to eager execution function cannot be Keras symbolic tensors

When I'm testing my tensorflow keras custom loss(using additional input data to calculate loss), which is as follow: @tf.function def build_walker_loss(labeled_output_t, unlabeled_output_t, label): similarity = tf.matmul(labeled_output_t,…
0
votes
1 answer

max value of a tensor in graph mode tensorflow

I have this tf code in graph mode (it has a training function wrapped by @tf.function) where I need to get the max value of a tensor x with type Tensor("x_3:0", shape=(100,), dtype=int64). Then I need…
user1571823
  • 394
  • 5
  • 20
0
votes
1 answer

Tensorflow2: How to print value of a tensor returned from tf.function when eager execution is disabled?

I've read that I can see contents of tf variables by using tf.print inside my tf.function definition. It doesn't work. My __tf.version__ is 2.5.0. I run the following function inside Jupyter…
0
votes
0 answers

Cannot avoid tensorflow function retracing

I implemented my custom layer to perform resizing of images with padding. I just want to resize my images (proportionally) that's why I implemented custom layer instead of using tf.image.resize(). And I want to do this using special preprocessing…
user12641640