code: def sparsify_weights(
      mlmodel,
      mode="threshold_based",
      threshold=1e-12,
      target_percentile=1.0,
      op_selector=None,
  ):
      """
      ``coremltools.compression_utils.sparsify_weights`` is deprecated and will be removed in the future.
      Please use :py:class:`coremltools.optimize.coreml.prune_weights`.
      """
      if op_selector is None:
          op_selector = _default_op_selector
  
      if mode.upper() == "THRESHOLD_BASED":
          op_config = _OpThresholdPrunerConfig(
              threshold=threshold,
              minimum_sparsity_percentile=0.0,
              weight_threshold=None,
          )
  
      elif mode.upper() == "PERCENTILE_BASED":
          op_config = _OpMagnitudePrunerConfig(
              target_sparsity=target_percentile,
              weight_threshold=None,
          )
  
      else:
          raise ValueError(
              'Only modes "THRESHOLD_BASED" and "PERCENTILE_BASED" are supported for weight sparsification.'
              f' Got mode: "{mode}".'
          )
  
      config = _OptimizationConfig(
          global_config=op_config,
          is_deprecated=True,
          op_selector=op_selector,
      )
      return _prune_weights(mlmodel, config)
  
file_path: coremltools/coremltools/models/ml_program/compression_utils.py
imports: import numpy
  from coremltools.converters.mil import Operation
  from coremltools.models._deprecation import deprecated
  from coremltools.optimize.coreml import OpLinearQuantizerConfig, OpMagnitudePrunerConfig, OpPalettizerConfig, OpThresholdPrunerConfig, OptimizationConfig
  from coremltools.optimize.coreml import linear_quantize_weights, decompress_weights, palettize_weights, prune_weights
label_desc: Use image node_id 4 for calling a global function with example usage: sparsify_weights(mlmodel, mode, threshold, target_percentile, op_selector) and returns: _prune_weights