{"record":{"id":"f3213a353856e0ad","repo":"Lightning-AI/pytorch-lightning","slug":"pytorch-basepruningmethod-is-currently-only-supp","errorCode":null,"errorMessage":"PyTorch `BasePruningMethod` is currently only supported with `use_global_unstructured=True`.","messagePattern":"PyTorch `BasePruningMethod` is currently only supported with `use_global_unstructured=True`\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/pruning.py","lineNumber":202,"sourceCode":"                    f\"The provided `pruning_fn` {pruning_fn} isn't available in PyTorch's\"\n                    f\" built-in functions: {list(_PYTORCH_PRUNING_FUNCTIONS.keys())} \"\n                )\n            if pruning_fn.endswith(\"_structured\"):\n                if pruning_dim is None:\n                    raise MisconfigurationException(\n                        \"When requesting `structured` pruning, the `pruning_dim` should be provided.\"\n                    )\n                if pruning_fn == \"ln_structured\":\n                    if pruning_norm is None:\n                        raise MisconfigurationException(\n                            \"When requesting `ln_structured` pruning, the `pruning_norm` should be provided.\"\n                        )\n                    pruning_kwargs[\"n\"] = pruning_norm\n                pruning_kwargs[\"dim\"] = pruning_dim\n            pruning_fn = self._create_pruning_fn(pruning_fn, **pruning_kwargs)\n        elif self._is_pruning_method(pruning_fn):\n            if not use_global_unstructured:\n                raise MisconfigurationException(\n                    \"PyTorch `BasePruningMethod` is currently only supported with `use_global_unstructured=True`.\"\n                )\n        else:\n            raise MisconfigurationException(\n                f\"`pruning_fn` is expected to be a str in {list(_PYTORCH_PRUNING_FUNCTIONS.keys())}\"\n                f\" or a PyTorch `BasePruningMethod`. Found: {pruning_fn}.\"\n                \" HINT: if passing a `BasePruningMethod`, pass the class, not an instance\"\n            )\n\n        # need to ignore typing here since pytorch base class does not define the PRUNING_TYPE attribute\n        if use_global_unstructured and pruning_fn.PRUNING_TYPE != \"unstructured\":  # type: ignore\n            raise MisconfigurationException(\n                'Only the \"unstructured\" PRUNING_TYPE is supported with `use_global_unstructured=True`.'\n                f\" Found method {pruning_fn} of type {pruning_fn.PRUNING_TYPE}. \"  # type: ignore[union-attr]\n            )\n\n        self.pruning_fn = pruning_fn\n        self._apply_pruning = apply_pruning","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/pruning.py#L184-L220","documentation":"If pruning_fn is passed as a custom torch.nn.utils.prune.BasePruningMethod subclass, ModelPruning only supports applying it through the global-unstructured machinery, which requires use_global_unstructured=True (the default). Passing a BasePruningMethod with use_global_unstructured=False raises MisconfigurationException.","triggerScenarios":"ModelPruning(pruning_fn=MyPruningMethod, use_global_unstructured=False); explicitly disabling global unstructured pruning while still passing a custom method class.","commonSituations":"Setting use_global_unstructured=False for per-layer/local pruning with a string fn, then later swapping in a custom method without reverting the flag; copying example code that disables the flag.","solutions":["Remove use_global_unstructured=False (or set it True) when using a BasePruningMethod","If you truly need non-global pruning, use a supported built-in string fn (e.g., 'l1_unstructured') with the flag off","Consider implementing custom global-unstructured logic by subclassing BasePruningMethod with PRUNING_TYPE='unstructured'"],"exampleFix":"# before\nModelPruning(pruning_fn=MyPruningMethod, use_global_unstructured=False)\n# after\nModelPruning(pruning_fn=MyPruningMethod, use_global_unstructured=True)","handlingStrategy":"validation","validationCode":"import torch.nn.utils.prune as prune\nis_method = isinstance(pruning_fn, type) and issubclass(pruning_fn, prune.BasePruningMethod)\nif is_method:\n    assert use_global_unstructured is not False","typeGuard":"def is_base_pruning_method_cls(fn) -> bool:\n    import torch.nn.utils.prune as prune\n    return isinstance(fn, type) and issubclass(fn, prune.BasePruningMethod)","tryCatchPattern":null,"preventionTips":["Keep use_global_unstructured=True (default) when passing custom method classes","Only disable the flag with string builtins"],"tags":["pytorch-lightning","pruning","base-pruning-method","unsupported-operation"],"backgroundTag":"unsupported-api-combination","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}