class_docstr: Specifies to prune only 1x1 Conv2D layers in the model.
  
  PruneForLatencyOnXNNPack checks that the model contains a subgraph that can
  leverage XNNPACK's sparse inference and applies pruning wrapper only to
  Conv2D with `kernel_size = (1, 1)`.
  
  Reference:
    - [Fast Sparse ConvNets](https://arxiv.org/abs/1911.09723)
    - [XNNPACK Sparse Inference](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/delegates/xnnpack/README.md#sparse-inference) # pylint: disable=line-too-long
class_docstr_tok: ["Specifies","to","prune","only","1x1","Conv2D","layers","in","the","model",".","PruneForLatencyOnXNNPack","checks","that","the","model","contains","a","subgraph","that","can","leverage","XNNPACK","'s","sparse","inference","and","applies","pruning","wrapper","only","to","Conv2D","with","`","kernel_size","=","(","1",",","1",")","`",".","Reference",":","-","[","Fast","Sparse","ConvNets","]","(","https",":","\/\/arxiv.org\/abs\/1911.09723",")","-","[","XNNPACK","Sparse","Inference","]","(","https",":","\/\/github.com\/tensorflow\/tensorflow\/blob\/master\/tensorflow\/lite\/delegates\/xnnpack\/README.md","#","sparse-inference",")","#","pylint",":","disable=line-too-long"]
docstr: Ensures that the model contains only supported layers.
docstr_tok: ["Ensures","that","the","model","contains","only","supported","layers","."]
code: def ensure_model_supports_pruning(self, model):
      """Ensures that the model contains only supported layers."""
  
      # Check whether the model is a subclass model.
      if not model._is_graph_network and not isinstance(
          model, tf.keras.models.Sequential
      ):
          raise ValueError(
              "Subclassed models are not supported currently."
          )
  
      if not model.built:
          raise ValueError(
              "Unbuilt models are not supported currently."
          )
  
      # Gather the layers that consume model's input tensors.
      input_layers = set(
          inp._keras_history.layer for inp in model.inputs
      )
  
      # Search for the start layer (Conv2D 3x3, `stride = (2, 2)`,
      # `filters = 3`, `padding = `VALID``) in every input branch (forward).
      start_layers = self._lookup_layers(
          input_layers,
          self._start_layer_stop_fn,
          self._get_consumers,
      )
      if not start_layers:
          raise ValueError(
              (
                  "Could not find `Conv2D 3x3` layer with stride 2x2, "
                  "`input filters == 3` and `VALID` padding and "
                  "preceding `ZeroPadding2D` with `padding == 1` in all "
                  "input branches of the model"
              )
          )
  
      # Search for the end layer (GlobalAveragePooling)
      # for every output branch (backward).
      output_layers = set(
          inp._keras_history.layer for inp in model.outputs
      )
      end_layers = self._lookup_layers(
          output_layers,
          self._end_layer_stop_fn,
          self._get_producers,
      )
      if not end_layers:
          raise ValueError(
              (
                  "Could not find a `GlobalAveragePooling2D` layer in "
                  "all output branches"
              )
          )
  
      # Ensure that all layers between the start and the end layers are supported
      # for pruning.
      def visit_fn(layer):
          if layer not in end_layers and not self._check_layer_support(
              layer
          ):
              raise ValueError(
                  (
                      "Layer {layer} is not supported for the {policy} "
                      "pruning policy".format(
                          layer=layer.__class__.__name__,
                          policy=self.__class__.__name__,
                      )
                  )
              )
          return layer in end_layers
  
      _ = self._lookup_layers(
          sum(
              [self._get_consumers(layer) for layer in start_layers], []
          ),
          visit_fn,
          self._get_consumers,
      )
  
file_path: model-optimization/tensorflow_model_optimization/python/core/sparsity/keras/pruning_policy.py
imports: import abc
  import tensorflow
  from tensorflow_model_optimization.python.core.quantization.keras import utils
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_wrapper
label_desc: Use image node_id 8 for calling the PruneForLatencyOnXNNPack obj's underlying member method code with example usage: obj.ensure_model_supports_pruning(model) and returns: unknown