docstr: Runs CQAT end to end and model is quantized only for a single layer.
docstr_tok: ["Runs","CQAT","end","to","end","and","model","is","quantized","only","for","a","single","layer","."]
code: def testEndToEndClusterPreserveOneLayer(self):
      """Runs CQAT end to end and model is quantized only for a single layer."""
      original_model = tf.keras.Sequential(
          [
              layers.Dense(5, activation="relu", input_shape=(10,)),
              layers.Dense(
                  5, activation="softmax", input_shape=(10,), name="qat"
              ),
          ]
      )
      clustered_model = cluster.cluster_weights(
          original_model, **self.cluster_params
      )
      self.compile_and_fit(clustered_model)
      clustered_model = cluster.strip_clustering(clustered_model)
      num_of_unique_weights_clustering = (
          self._get_number_of_unique_weights(
              clustered_model, 1, "kernel"
          )
      )
  
      def apply_quantization_to_dense(layer):
          if isinstance(layer, tf.keras.layers.Dense):
              if layer.name == "qat":
                  return quantize.quantize_annotate_layer(layer)
          return layer
  
      quant_aware_annotate_model = tf.keras.models.clone_model(
          clustered_model,
          clone_function=apply_quantization_to_dense,
      )
  
      quant_aware_model = quantize.quantize_apply(
          quant_aware_annotate_model,
          scheme=default_8bit_cluster_preserve_quantize_scheme.Default8BitClusterPreserveQuantizeScheme(),
      )
  
      self.compile_and_fit(quant_aware_model)
  
      stripped_cqat_model = strip_clustering_cqat(quant_aware_model)
  
      # Check the unique weights of a certain layer of
      # clustered_model and pcqat_model
      num_of_unique_weights_cqat = self._get_number_of_unique_weights(
          stripped_cqat_model, 1, "kernel"
      )
      self.assertAllEqual(
          num_of_unique_weights_clustering, num_of_unique_weights_cqat
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.clustering.keras import cluster
  from tensorflow_model_optimization.python.core.clustering.keras import cluster_config
  from tensorflow_model_optimization.python.core.clustering.keras.experimental import cluster
  from tensorflow_model_optimization.python.core.quantization.keras import quantize
  from tensorflow_model_optimization.python.core.quantization.keras.collab_opts.cluster_preserve import default_8bit_cluster_preserve_quantize_scheme
  from tensorflow_model_optimization.python.core.quantization.keras.collab_opts.cluster_preserve.cluster_utils import strip_clustering_cqat
label_desc: Use image node_id 12 for calling the ClusterPreserveIntegrationTest obj's underlying member method code with example usage: obj.testEndToEndClusterPreserveOneLayer() and returns: layer, quantize