class_docstr: Tests KerasLayer in an all-Keras environment.
class_docstr_tok: ["Tests","KerasLayer","in","an","all-Keras","environment","."]
docstr: Tests importing a float32 model then saving it with mixed_float16.
docstr_tok: ["Tests","importing","a","float32","model","then","saving","it","with","mixed_float16","."]
code: def testResaveWithMixedPrecision(self, save_from_keras):
      """Tests importing a float32 model then saving it with mixed_float16."""
      major, minor, _ = tf.version.VERSION.split(".")
      if not tf.executing_eagerly() or (int(major), int(minor)) < (
          2,
          4,
      ):
          self.skipTest(
              "Test uses non-experimental mixed precision API, which is "
              "only available in TF 2.4 or above"
          )
      export_dir1 = os.path.join(self.get_temp_dir(), "mixed-precision")
      export_dir2 = os.path.join(
          self.get_temp_dir(), "mixed-precision2"
      )
      # TODO(b/193472950): Currently, KerasLayer only works with mixed precision
      # when the model takes non-floating point inputs, which is why an embedding
      # model is used in this test.
      _save_2d_text_embedding(
          export_dir1, save_from_keras=save_from_keras
      )
      try:
          tf_keras_v2.mixed_precision.set_global_policy("mixed_float16")
          inp = tf_keras_v2.layers.Input(shape=(1,), dtype=tf.string)
          imported = hub.KerasLayer(export_dir1, trainable=True)
          outp = imported(inp)
          model = tf_keras_v2.Model(inp, outp)
          model.compile(
              tf_keras_v2.optimizers.SGD(0.002, momentum=0.001),
              "mean_squared_error",
              run_eagerly=True,
          )
          x = [["a"], ["aa"], ["aaa"]]
          y = [len(xi) for xi in x]
          model.fit(x, y)
          tf.saved_model.save(model, export_dir2)
      finally:
          tf_keras_v2.mixed_precision.set_global_policy("float32")
  
imports: import json
  import os
  from absl.testing import parameterized
  import numpy
  import tensorflow
  import tensorflow_hub
label_desc: Use image node_id 10 for calling the KerasTest obj's underlying member method code with example usage: obj.testResaveWithMixedPrecision(save_from_keras) without return types