code: def prune_weights(mlmodel: _MLModel, config: _OptimizationConfig):
      """
      Utility function to convert a float precision MLModel of type ``mlprogram`` to a
      compressed MLModel using sparse representation. The ``const`` ops storing weight
      values are replaced by ``constexpr_sparse_to_dense`` ops.
  
      This function is useful if the model is trained with pruning techniques so that
      a lot of weights have zero values. If a large percentage of weight values are zero,
      a sparse representation is more efficient than a dense one (the default).
  
      The sparsified weights are stored in a bit mask. If the weight values are
      ``{0, 0, 0, 0, 0, 0, 0, 56.3}``, its sparse representation contains a bit mask with
      ones on locations where the value is non-zero: ``00000001b``. This is accompanied by
      non-zero data, which is a size-1 vector of value ``{56.3}``.
  
      For example, given the following:
  
          * ``weight = [0.3, 0, 0, 0.5, 0, 0]``
          * ``non_zero_data, bit_mask = sparsify(weight)``
  
      The indices of the non-zero elements are:
  
          * ``non_zero_data = [0.3, 0.5]``
          * ``bit_mask = "100100"``
  
      Parameters
      ----------
      mlmodel: MLModel
          Model to be sparsified. This MLModel should be of type ``mlprogram``.
  
      config: OptimizationConfig
          An :py:class:`OptimizationConfig` object that specifies the parameters for weight pruning.
  
      Returns
      -------
      model: MLModel
          The sparse MLModel instance.
  
      Examples
      --------
      .. sourcecode:: python
  
          import coremltools as ct
          import coremltools.optimize as cto
  
          model = ct.models.MLModel("my_model.mlpackage")
          config = cto.coreml.OptimizationConfig(
              global_config=cto.coreml.OpThresholdPrunerConfig(threshold=1e-12)
          )
          compressed_model = cto.coreml.prune_weights(model, config)
  
      """
  
      weight_pruner = _prune_weights(config, fake_compression=False)
      return _apply_graph_pass(mlmodel, weight_pruner)
  
imports: from collections import OrderedDict
  from typing import Callable, Dict, List, Optional
  import numpy
  from attrs import define, field, validators
  from tqdm import tqdm
  from coremltools import _SPECIFICATION_VERSION_IOS_16
  from coremltools.converters.mil.converter import mil_convert
  from coremltools.converters.mil.frontend.milproto import load
  from coremltools.converters.mil.mil.passes.defs.quantization import AbstractQuantizationPass
  from coremltools.models import MLModel
  from coremltools.optimize.coreml import OptimizationConfig
  from coremltools.optimize.coreml._config import _MetaDataDict
  from ._quantization_passes import WeightDecompressor
  from ._quantization_passes import linear_quantize_weights
  from ._quantization_passes import palettize_weights
  from ._quantization_passes import prune_weights
label_desc: Use image node_id 6 for calling a global function with example usage: prune_weights(mlmodel, config) and returns: _apply_graph_pass