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)

    ``coremltools.compression_utils.sparsify_weights`` is deprecated and will be removed in the future.
    Please use :py:class:`coremltools.optimize.coreml.prune_weights`.
    
coremltools/models/ml_program/compression_utils.py