def is_pruner_prepared(optimizer):
    """
    Check if any layer to be compressed with `optimizer` has already
    been prepared for pruning by addition of pruning forward pre hooks
    """
    for name, submodule in optimizer._model.named_modules(remove_duplicate=True):
        config = optimizer._config.get_module_config(name, submodule)
        if config and hasattr(submodule, "pruning_method"):
            return True
    return False

    Check if any layer to be compressed with `optimizer` has already
    been prepared for pruning by addition of pruning forward pre hooks
    
coremltools/optimize/torch/_utils/joint_compression_utils.py