code: def prune_weights(
      mlmodel,
      mode="threshold_based",
      threshold=1e-3,
      target_sparsity=1.0,
      block_size=-1,
      n_m_ratio=(),
  ):
      if mode == "threshold_based":
          op_config = cto.coreml.OpThresholdPrunerConfig(
              threshold=threshold,
              minimum_sparsity_percentile=0.0,
          )
      elif mode == "percentile_based":
          op_config = cto.coreml.OpMagnitudePrunerConfig(
              target_sparsity=target_sparsity,
          )
      elif mode == "block_sparsity":
          op_config = cto.coreml.OpMagnitudePrunerConfig(
              target_sparsity=target_sparsity,
              block_size=block_size,
          )
      else:
          assert mode == "n_m_pruning"
          op_config = cto.coreml.OpMagnitudePrunerConfig(
              n_m_ratio=n_m_ratio,
          )
  
      config = cto.coreml.OptimizationConfig(global_config=op_config)
      return cto.coreml.prune_weights(mlmodel, config)
  
imports: import itertools
  import numpy
  import pytest
  import torch
  import coremltools
  import coremltools.optimize
  from coremltools._deps import _HAS_SKLEARN
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import types
  from coremltools.converters.mil.testing_utils import get_op_types_in_program
  from coremltools.optimize.coreml._post_training_quantization import CoreMLWeightMetaData
  from coremltools.test.ml_program.test_compression import get_test_model_and_data
label_desc: Use image node_id 3 for calling a global function with example usage: prune_weights(mlmodel, mode, threshold, target_sparsity, block_size, n_m_ratio) and returns: cto