class_docstr: Define how to apply SVD algorithm.
docstr: Model developer API for optimizing a model.
code: def compress_model(
      self, to_optimize: tf.keras.Model
  ) -> tf.keras.Model:
      """Model developer API for optimizing a model."""
      # pylint: disable=protected-access
      if (
          not isinstance(to_optimize, tf.keras.Sequential)
          and not to_optimize._is_graph_network
      ):
          raise ValueError(
              "`compress_model` can only either be a tf.keras Sequential or "
              "Functional model."
          )
      # pylint: enable=protected-access
  
      def _create_layer_for_training(layer):
          # Require layer to be built so that the SVD-factorized weights
          # can be initialized from the weights.
          if not layer.built:
              raise ValueError(
                  "Applying SVD currently requires passing in a built model"
              )
  
          return algorithm.create_layer_for_training(
              layer, algorithm=self
          )
  
      def _create_layer_for_inference(layer):
          return algorithm.create_layer_for_inference(
              layer, algorithm=self
          )
  
      intermediate_model = tf.keras.models.clone_model(
          to_optimize, clone_function=_create_layer_for_training
      )
  
      return tf.keras.models.clone_model(
          intermediate_model, clone_function=_create_layer_for_inference
      )
  
file_path: model-optimization/tensorflow_model_optimization/python/core/common/keras/compression/algorithms/different_training_and_inference.py
imports: from typing import List
  import tensorflow
  from tensorflow_model_optimization.python.core.common.keras.compression import algorithm
label_desc: Use image node_id 7 for calling the SVD obj's underlying member method code with example usage: obj.compress_model(to_optimize) and returns: tf, algorithm, algorithm