{"record":{"id":"e44d08561a2d6295","repo":"Lightning-AI/pytorch-lightning","slug":"when-requesting-structured-pruning-the-pruning","errorCode":null,"errorMessage":"When requesting `structured` pruning, the `pruning_dim` should be provided.","messagePattern":"When requesting `structured` pruning, the `pruning_dim` should be provided\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/pruning.py","lineNumber":189,"sourceCode":"        self._pruning_method_name: Optional[str] = None\n\n        for name in self._parameter_names:\n            if name not in self.PARAMETER_NAMES:\n                raise MisconfigurationException(\n                    f\"The provided `parameter_names` name: {name} isn't in {self.PARAMETER_NAMES}\"\n                )\n\n        if isinstance(pruning_fn, str):\n            pruning_kwargs = {}\n            pruning_fn = pruning_fn.lower()\n            if pruning_fn not in _PYTORCH_PRUNING_FUNCTIONS:\n                raise MisconfigurationException(\n                    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())}\"","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/pruning.py#L171-L207","documentation":"Structured pruning methods (names ending in '_structured') need a dimension along which to remove entire channels/neurons. If pruning_fn is a structured method but pruning_dim is None, ModelPruning's __init__ raises MisconfigurationException demanding the dimension.","triggerScenarios":"ModelPruning(pruning_fn='ln_structured') or 'random_structured' without pruning_dim; specifying pruning_norm but forgetting dim, or vice versa.","commonSituations":"Switching from unstructured to structured pruning without updating parameters; unclear which axis to prune in conv layers (usually dim=0 for output channels).","solutions":["Add pruning_dim, e.g., pruning_fn='ln_structured', pruning_dim=0","For 'ln_structured' also supply pruning_norm (the n parameter)","Verify dim matches the tensor layout of the modules being pruned (dim=0 prunes output channels for Linear/Conv)"],"exampleFix":"# before\nModelPruning(pruning_fn='ln_structured', pruning_norm=2)\n# after\nModelPruning(pruning_fn='ln_structured', pruning_norm=2, pruning_dim=0)","handlingStrategy":"validation","validationCode":"if str(pruning_fn).endswith('_structured'):\n    assert pruning_dim is not None, 'structured pruning requires pruning_dim'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair structured methods with pruning_dim (usually 0 for output channels)","Remember ln_structured additionally needs pruning_norm"],"tags":["pytorch-lightning","pruning","structured-pruning","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}