{"record":{"id":"c498bc4eb04c22eb","repo":"Lightning-AI/pytorch-lightning","slug":"the-provided-pruning-fn-pruning-fn-isn-t-avail","errorCode":null,"errorMessage":"The provided `pruning_fn` {pruning_fn} isn't available in PyTorch's built-in functions: {list(_PYTORCH_PRUNING_FUNCTIONS.keys())} ","messagePattern":"The provided `pruning_fn` (.+?) isn't available in PyTorch's built-in functions: (.+?) ","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/pruning.py","lineNumber":183,"sourceCode":"        self._use_lottery_ticket_hypothesis = use_lottery_ticket_hypothesis\n        self._resample_parameters = resample_parameters\n        self._prune_on_train_epoch_end = prune_on_train_epoch_end\n        self._parameter_names = parameter_names or self.PARAMETER_NAMES\n        self._global_kwargs: dict[str, Any] = {}\n        self._original_layers: Optional[dict[int, _LayerRef]] = None\n        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:","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/pruning.py#L165-L201","documentation":"When pruning_fn is given as a string, ModelPruning resolves it against PyTorch's built-in pruning functions (e.g., 'l1_unstructured', 'random_unstructured', 'ln_structured', 'random_structured', indexed in _PYTORCH_PRUNING_FUNCTIONS). An unknown string (note: it is lowercased before lookup) raises MisconfigurationException listing the valid keys.","triggerScenarios":"Passing pruning_fn='l1' or 'L1Unstructured' (case is handled by .lower(), but the key must still match a builtin name like 'l1_unstructured'); passing 'magnitude_pruning' or another non-builtin name.","commonSituations":"Assuming short names like 'l1' work; configs copied from tutorials using custom callables; version differences in which builtins Lightning maps.","solutions":["Use a key from the message's list, e.g., pruning_fn='l1_unstructured'","Or pass a torch.nn.utils.prune.BasePruningMethod subclass instead of a string","Print/inspect _PYTORCH_PRUNING_FUNCTIONS keys for your installed version before writing the config"],"exampleFix":"# before\nModelPruning(pruning_fn='l1')\n# after\nModelPruning(pruning_fn='l1_unstructured')","handlingStrategy":"validation","validationCode":"fn = cfg['pruning_fn'].lower()\n# valid keys: l1_unstructured, random_unstructured, ln_structured, random_structured\nassert fn in {'l1_unstructured', 'random_unstructured', 'ln_structured', 'random_structured'}, fn","typeGuard":"def is_builtin_pruning_fn(name: str) -> bool:\n    return name.lower() in {'l1_unstructured', 'random_unstructured', 'ln_structured', 'random_structured'}","tryCatchPattern":null,"preventionTips":["Use the exact keys from _PYTORCH_PRUNING_FUNCTIONS","Pass a BasePruningMethod class for custom logic"],"tags":["pytorch-lightning","pruning","pruning-fn","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}