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: Returns whether the layer is supported or not.
  
  Mimics XNNPACK's behaviour of compatibility function.
  
  Args:
    layer: Current layer in the model.
  
  Returns:
    True if the layer is supported, False otherwise.
  
  References:
    - https://github.com/google/XNNPACK/blob/master/src/subgraph.c#L130
docstr_tok: ["Returns","whether","the","layer","is","supported","or","not",".","Mimics","XNNPACK","'s","behaviour","of","compatibility","function",".","Args",":","layer",":","Current","layer","in","the","model",".","Returns",":","True","if","the","layer","is","supported",",","False","otherwise",".","References",":","-","https",":","\/\/github.com\/google\/XNNPACK\/blob\/master\/src\/subgraph.c","#","L130"]
code: def _check_layer_support(self, layer):
      """Returns whether the layer is supported or not.
  
      Mimics XNNPACK's behaviour of compatibility function.
  
      Args:
        layer: Current layer in the model.
  
      Returns:
        True if the layer is supported, False otherwise.
  
      References:
        - https://github.com/google/XNNPACK/blob/master/src/subgraph.c#L130
      """
      if isinstance(
          layer,
          (
              layers.Add,
              layers.Multiply,
              layers.ZeroPadding2D,
              layers.ReLU,
              layers.LeakyReLU,
              layers.ELU,
              layers.Dropout,
          ),
      ):
          return True
      elif isinstance(layer, layers.DepthwiseConv2D):
          # 3x3 convolution with `SAME` padding (no dilation, stride-1).
          # 3x3 convolution with `VALID` padding (no dilation, stride-1 or stride-2,
          #   preceding `ZeroPadding2D` layer with padding 1 on each side.
          # 5x5 convolution with `SAME` padding (no dilation, stride-1)
          # 5x5 convolution with `VALID` padding (no dilation, stride-1 or stride-2,
          #   preceding `ZeroPadding2D` layer with padding 2 on each side.
          padding = layer.padding.lower()
          producers = list(self._get_producers(layer))
          zero_padding = (
              producers[0]
              if len(producers) == 1
              and isinstance(producers[0], layers.ZeroPadding2D)
              else None
          )
  
          supported_case_1 = (
              layer.kernel_size == (3, 3)
              and layer.strides == (1, 1)
              and padding == "same"
          )
  
          supported_case_2 = (
              layer.kernel_size == (3, 3)
              and (layer.strides == (1, 1) or layer.strides == (2, 2))
              and padding == "valid"
              and zero_padding
              and zero_padding.padding == ((1, 1), (1, 1))
          )
  
          supported_case_3 = (
              layer.kernel_size == (5, 5)
              and layer.strides == (1, 1)
              and padding == "same"
          )
  
          supported_case_4 = (
              layer.kernel_size == (5, 5)
              and (layer.strides == (1, 1) or layer.strides == (2, 2))
              and padding == "valid"
              and zero_padding
              and zero_padding.padding == ((2, 2), (2, 2))
          )
  
          supported = (
              layer.depth_multiplier == 1
              and layer.dilation_rate == (1, 1)
              and (
                  supported_case_1
                  or supported_case_2
                  or supported_case_3
                  or supported_case_4
              )
          )
  
          return supported
      elif isinstance(layer, layers.Conv2D):
          # 1x1 convolution (no stride, no dilation, no padding, no groups).
          return (
              layer.groups == 1
              and layer.dilation_rate == (1, 1)
              and layer.kernel_size == (1, 1)
              and layer.strides == (1, 1)
          )
      elif isinstance(layer, layers.GlobalAveragePooling2D):
          return layer.keepdims
      elif isinstance(layer, layers.BatchNormalization):
          return list(layer.axis) == [3]
      elif isinstance(layer, layers.UpSampling2D):
          return layer.interpolation == "bilinear"
      elif isinstance(layer, layers.Activation):
          return quantize_utils.serialize_activation(
              layer.activation, use_legacy_format=True
          ) in ("relu", "relu6", "leaky_relu", "elu", "sigmoid")
      elif layer.__class__.__name__ == "TFOpLambda":
          return layer.function in (
              tf.identity,
              tf.__operators__.add,
              tf.math.add,
              tf.math.subtract,
              tf.math.multiply,
          )
      elif isinstance(layer, pruning_wrapper.PruneLowMagnitude):
          return self._check_layer_support(layer.layer)
      return False
  
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 7 for calling the PruneForLatencyOnXNNPack obj's underlying member method code with example usage: obj._check_layer_support(layer) and returns: False, True, supported, unknown, layer, unknown, unknown, unknown, unknown, self