title: How to execute TensorFlow 2 Keras Sequential model in eager mode when "compile"?
body: <p>I want to build a loss in a "pythonic" way using the eager execution of TF2, but even in eager mode, Keras is passing non-eager tensors.</p>
  
  <p>Code:</p>
  
  <pre class="lang-py prettyprint-override"><code>    def conditional_loss(self, y_true, y_pred):
          print(y_true)
          return 0
  
      def define_model(self):
          self.model = keras.Sequential([
              keras.layers.Dense(units=768),
              keras.layers.BatchNormalization(),
              keras.layers.ReLU(),
              keras.layers.Dropout(0.2),
              keras.layers.Dense(units=128),
              keras.layers.BatchNormalization(),
              keras.layers.ReLU(),
              keras.layers.Dropout(0.2),
              keras.layers.Dense(units=5, activation='softmax')
          ])
  
          self.model.compile(optimizer='adam',
                             loss=self.conditional_loss,
                             metrics=[self.conditional_loss, 
                                      keras.metrics.sparse_categorical_accuracy]
                             )
          self.model.fit(
              self.train_dataset,
              epochs=10,
              validation_data=self.test_dataset,
              callbacks=[tensorboard_callback, model_callback],
          )
  
  </code></pre>
  
  <p>If I print <code>y_true</code> in <code>conditional_loss</code> TF prints a non-eager tensor.</p>
  
  <pre class="lang-py prettyprint-override"><code>Tensor("metrics/conditional_loss/Cast:0", shape=(None, 1), dtype=float32)
  </code></pre>
  
  <p>If I build my own <code>keras.Model()</code> I can call it with the argument<code>dynamic=True</code> to enable eager execution. (<a href="https://github.com/tensorflow/tensorflow/issues/26268" rel="nofollow noreferrer">Reference</a>). Exists a way to do it in <code>keras.Sequential()</code> ?</p>