{"record":{"id":"565354ade78a4e2c","repo":"Lightning-AI/pytorch-lightning","slug":"only-the-unstructured-pruning-type-is-supported","errorCode":null,"errorMessage":"Only the \"unstructured\" PRUNING_TYPE is supported with `use_global_unstructured=True`. Found method {pruning_fn} of type {pruning_fn.PRUNING_TYPE}. ","messagePattern":"Only the \"unstructured\" PRUNING_TYPE is supported with `use_global_unstructured=True`\\. Found method (.+?) of type (.+?)\\. ","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/pruning.py","lineNumber":214,"sourceCode":"                        )\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\n        self._make_pruning_permanent = make_pruning_permanent\n\n        if not (isinstance(amount, (int, float)) or callable(amount)):\n            raise MisconfigurationException(\n                \"`amount` should be provided and be either an int, a float or Callable function.\"\n            )\n\n        self.amount = amount\n\n        if verbose not in (0, 1, 2):\n            raise MisconfigurationException(\"`verbose` must be any of (0, 1, 2)\")\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/pruning.py#L196-L232","documentation":"ModelPruning applies global unstructured pruning via torch.nn.utils.prune.global_unstructured, which only accepts methods whose PRUNING_TYPE is 'unstructured'. If the resolved pruning_fn (builtin or custom class) has a different PRUNING_TYPE (e.g., 'structured'), __init__ raises MisconfigurationException naming the method and its type.","triggerScenarios":"Passing pruning_fn='ln_structured' (a structured method) while leaving use_global_unstructured=True (default); passing a custom BasePruningMethod subclass whose PRUNING_TYPE = 'structured'.","commonSituations":"Choosing a structured method for channel pruning without realizing the callback routes everything through global_unstructured by default; custom methods copied from PyTorch docs that declare structured types.","solutions":["Use an unstructured method such as pruning_fn='l1_unstructured' or 'random_unstructured' with global unstructured pruning","For structured pruning needs, pass use_global_unstructured=False with a supported setup, or apply torch structured pruning manually outside this callback","If writing a custom method, ensure PRUNING_TYPE = 'unstructured' in the class definition"],"exampleFix":"# before\nModelPruning(pruning_fn='ln_structured', pruning_dim=0, pruning_norm=1)  # default use_global_unstructured=True\n# after\nModelPruning(pruning_fn='l1_unstructured', amount=0.5)","handlingStrategy":"validation","validationCode":"if use_global_unstructured:\n    ptype = getattr(pruning_fn, 'PRUNING_TYPE', 'unstructured')\n    assert ptype == 'unstructured', f'global unstructured requires unstructured methods, got {ptype}'","typeGuard":"def is_unstructured_method(fn) -> bool:\n    return getattr(fn, 'PRUNING_TYPE', None) == 'unstructured'","tryCatchPattern":null,"preventionTips":["Default to unstructured methods (l1_unstructured) with global pruning","Set PRUNING_TYPE='unstructured' on custom methods"],"tags":["pytorch-lightning","pruning","global-unstructured","unsupported-operation"],"backgroundTag":"unsupported-api-combination","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}