class_docstr: This wrapper augments a keras layer so the weight tensor may be pruned.
  
  This wrapper implements magnitude-based pruning of the weight tensors.
  Magnitude-based pruning achieves a target sparsity (s% of zeros) for a given
  weight tensor by monitoring the distribution of the absolute values of the
  weight tensor and determining the weight value (referred to as threshold)
  below which s% of elements lie. For every weight tensor being pruned, the
  wrapper maintains an identically shaped tensor (referred to as mask) which
  stores 0 if the weight value lies below the threshold.
  The mask and thresholds are computed during the training based on the
  evolution of the weight values.
  
  Block sparse patterns:
  For certain SIMD hardware architectures, it may be beneficial to induce
  spatially correlated sparsity. To train models in which the weight tensors
  have block sparse structure, the pruning wrapper can be configured with
  the block_height and block_width configuration parameters set to the desired
  block configuration (2x2, 4x4, 4x1, 1x8, etc). This is applicable to
  rank-2 weight tensor only and the tensor partitioned into non-overlapping
  blocks of size [block_height, block_dim]. Either the average or max absolute
  value in this block is taken as a proxy for the entire block
  (set by block_pooling_function configuration parameter)
  while computing the distribution of the weight values and
  the threshold for pruning.
  
  Custom keras layers:
  The pruning wrapper can also be applied to a user-defined keras layer.
  Such a layer may contain one or more weight tensors that may be pruned.
  To apply pruning wrapper to such layers, the layer should be a `PrunableLayer`
  instance or, more directly, user should define a `get_prunable_weights` method
  for the layer (Check the pruning_wrapper_test.CustomLayerPrunable for more
  details about how to define a user-defined prunable layer).
  
  Sparsity function:
  The target sparsity for the weight tensors are set through the
  pruning_schedule parameter of the pruning wrapper. The user must create a
  python callable that returns a scalar tensorflow tensor and pass this
  callable to the sparsity_function parameter. This scalar tensor contains the
  target sparsity value for the weight tensors in the layer.
  The wrapper provides the following pre-built sparsity functions:
  
  ConstantSparsity
  GradualSparsity
  
  Eg.
  params = PruningParams(frequency=10,pruning_schedule=ConstantSparsity(0.9))
  pruned_model = keras.model.Sequential()
  pruned_model.add(
      Prune(keras.layers.Dense(256), input_shape=(256,)))
  pruned_model.add(Prune(keras.layers.Dense(1024), params=params))
class_docstr_tok: ["This","wrapper","augments","a","keras","layer","so","the","weight","tensor","may","be","pruned",".","This","wrapper","implements","magnitude-based","pruning","of","the","weight","tensors",".","Magnitude-based","pruning","achieves","a","target","sparsity","(","s","%","of","zeros",")","for","a","given","weight","tensor","by","monitoring","the","distribution","of","the","absolute","values","of","the","weight","tensor","and","determining","the","weight","value","(","referred","to","as","threshold",")","below","which","s","%","of","elements","lie",".","For","every","weight","tensor","being","pruned",",","the","wrapper","maintains","an","identically","shaped","tensor","(","referred","to","as","mask",")","which","stores","0","if","the","weight","value","lies","below","the","threshold",".","The","mask","and","thresholds","are","computed","during","the","training","based","on","the","evolution","of","the","weight","values",".","Block","sparse","patterns",":","For","certain","SIMD","hardware","architectures",",","it","may","be","beneficial","to","induce","spatially","correlated","sparsity",".","To","train","models","in","which","the","weight","tensors","have","block","sparse","structure",",","the","pruning","wrapper","can","be","configured","with","the","block_height","and","block_width","configuration","parameters","set","to","the","desired","block","configuration","(","2x2",",","4x4",",","4x1",",","1x8",",","etc",")",".","This","is","applicable","to","rank-2","weight","tensor","only","and","the","tensor","partitioned","into","non-overlapping","blocks","of","size","[","block_height",",","block_dim","]",".","Either","the","average","or","max","absolute","value","in","this","block","is","taken","as","a","proxy","for","the","entire","block","(","set","by","block_pooling_function","configuration","parameter",")","while","computing","the","distribution","of","the","weight","values","and","the","threshold","for","pruning",".","Custom","keras","layers",":","The","pruning","wrapper","can","also","be","applied","to","a","user-defined","keras","layer",".","Such","a","layer","may","contain","one","or","more","weight","tensors","that","may","be","pruned",".","To","apply","pruning","wrapper","to","such","layers",",","the","layer","should","be","a","`","PrunableLayer","`","instance","or",",","more","directly",",","user","should","define","a","`","get_prunable_weights","`","method","for","the","layer","(","Check","the","pruning_wrapper_test.CustomLayerPrunable","for","more","details","about","how","to","define","a","user-defined","prunable","layer",")",".","Sparsity","function",":","The","target","sparsity","for","the","weight","tensors","are","set","through","the","pruning_schedule","parameter","of","the","pruning","wrapper",".","The","user","must","create","a","python","callable","that","returns","a","scalar","tensorflow","tensor","and","pass","this","callable","to","the","sparsity_function","parameter",".","This","scalar","tensor","contains","the","target","sparsity","value","for","the","weight","tensors","in","the","layer",".","The","wrapper","provides","the","following","pre-built","sparsity","functions",":","ConstantSparsity","GradualSparsity","Eg",".","params","=","PruningParams","(","frequency=10",",","pruning_schedule=ConstantSparsity","(","0.9",")",")","pruned_model","=","keras.model.Sequential","(",")","pruned_model.add","(","Prune","(","keras.layers.Dense","(","256",")",",","input_shape=","(","256",",",")",")",")","pruned_model.add","(","Prune","(","keras.layers.Dense","(","1024",")",",","params=params",")",")"]
code: def call(self, inputs, training=None, **kwargs):
      if training is None:
          training = K.learning_phase()
  
      def increment_step():
          with tf.control_dependencies(
              [
                  tf_compat.assign(
                      self.pruning_step, self.pruning_step + 1
                  )
              ]
          ):
              return tf.no_op("update")
  
      def add_update():
          with tf.control_dependencies(
              [
                  tf.debugging.assert_greater_equal(
                      self.pruning_step,
                      np.int64(1),
                      message=self._PRUNE_CALLBACK_ERROR_MSG,
                  )
              ]
          ):
              with tf.control_dependencies(
                  [self.pruning_obj.conditional_mask_update()]
              ):
                  return tf.no_op("update")
  
      def no_op():
          return tf.no_op("no_update")
  
      # Increment the 'pruning_step' after each step.
      update_pruning_step = utils.smart_cond(
          training, increment_step, no_op
      )
      self.add_update(update_pruning_step)
  
      # Update mask tensor after each 'pruning_frequency' steps.
      update_mask = utils.smart_cond(training, add_update, no_op)
      self.add_update(update_mask)
  
      # Always execute the op that performs weights = weights * mask
      # Relies on UpdatePruningStep callback to ensure the weights
      # are sparse after the final backpropagation.
      #
      # self.add_update does nothing during eager execution.
      self.add_update(self.pruning_obj.weight_mask_op())
      # TODO(evcu) remove this check after dropping py2 support. In py3 getargspec
      # is deprecated.
      if hasattr(inspect, "getfullargspec"):
          args = inspect.getfullargspec(self.layer.call).args
      else:
          args = inspect.getargspec(self.layer.call).args
      # Propagate the training bool to the underlying layer if it accepts
      # training as an arg.
      if "training" in args:
          return self.layer.call(inputs, training=training, **kwargs)
  
      return self.layer.call(inputs, **kwargs)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import inspect
  import re
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.keras import compat
  from tensorflow_model_optimization.python.core.keras import metrics
  from tensorflow_model_optimization.python.core.keras import utils
  from tensorflow_model_optimization.python.core.sparsity.keras import prunable_layer
  from tensorflow_model_optimization.python.core.sparsity.keras import prune_registry
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_impl
  from tensorflow_model_optimization.python.core.sparsity.keras import pruning_schedule
  from tensorflow_model_optimization.python.core.sparsity.keras.pruning_utils import convert_to_tuple_of_two_int
label_desc: Use image node_id 3 for calling the PruneLowMagnitude obj's underlying member method code with example usage: obj.call(inputs, training) and returns: self, tf, self, tf, tf