docstr: Runs PCQAT end to end when we quantize the whole model.
docstr_tok: ["Runs","PCQAT","end","to","end","when","we","quantize","the","whole","model","."]
code: def testEndToEndPruneClusterPreserveQAT(self):
      """Runs PCQAT end to end when we quantize the whole model."""
      preserve_sparsity = True
      clustered_model = self._get_clustered_model(preserve_sparsity)
      # Save the kernel weights
      first_layer_weights = clustered_model.layers[0].weights[1]
      stripped_model_before_tuning = cluster.strip_clustering(
          clustered_model
      )
      nr_of_unique_weights_before = self._get_number_of_unique_weights(
          stripped_model_before_tuning, 0, "kernel"
      )
  
      self.compile_and_fit(clustered_model)
  
      stripped_model_clustered = cluster.strip_clustering(
          clustered_model
      )
      weights_after_tuning = stripped_model_clustered.layers[0].kernel
      nr_of_unique_weights_after = self._get_number_of_unique_weights(
          stripped_model_clustered, 0, "kernel"
      )
  
      # Check after sparsity-aware clustering, despite zero centroid can drift,
      # the final number of unique weights remains the same
      self.assertEqual(
          nr_of_unique_weights_before, nr_of_unique_weights_after
      )
  
      # Check that the zero weights stayed the same before and after tuning.
      # There might be new weights that become zeros but sparsity-aware
      # clustering preserves the original zero weights in the original positions
      # of the weight array
      self.assertTrue(
          np.array_equal(
              first_layer_weights[:][0:2], weights_after_tuning[:][0:2]
          )
      )
  
      # Check sparsity before the input of PCQAT
      sparsity_pruning = self._get_sparsity(stripped_model_clustered)
  
      # PCQAT: when the preserve_sparsity flag is True, the PCQAT should work
      quant_aware_annotate_model = quantize.quantize_annotate_model(
          stripped_model_clustered
      )
  
      # When preserve_sparsity is True in PCQAT, the final sparsity of
      # the layer stays the same or larger than that of the input layer
      preserve_sparsity = True
      sparsity_pcqat, unique_weights_pcqat = self._pcqat_training(
          preserve_sparsity, quant_aware_annotate_model
      )
      self.assertAllGreaterEqual(
          np.array(sparsity_pcqat), sparsity_pruning[0]
      )
      self.assertAllEqual(
          nr_of_unique_weights_after, unique_weights_pcqat
      )
  
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 13 for calling the ClusterPreserveIntegrationTest obj's underlying member method code with example usage: obj.testEndToEndPruneClusterPreserveQAT() without return types