{"record":{"id":"02a9da0c654fa3c1","repo":"Lightning-AI/pytorch-lightning","slug":"the-provided-parameters-to-prune-should-either-b","errorCode":null,"errorMessage":"The provided `parameters_to_prune` should either be list of tuple with 2 elements: (nn.Module, parameter_name_to_prune) or None","messagePattern":"The provided `parameters_to_prune` should either be list of tuple with 2 elements: \\(nn\\.Module, parameter_name_to_prune\\) or None","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/pruning.py","lineNumber":487,"sourceCode":"            and len(parameters_to_prune) > 0\n            and all(len(p) == 2 for p in parameters_to_prune)\n            and all(isinstance(a, nn.Module) and isinstance(b, str) for a, b in parameters_to_prune)\n        ):\n            missing_modules, missing_parameters = [], []\n            for module, name in parameters_to_prune:\n                if module not in current_modules:\n                    missing_modules.append(module)\n                    continue\n                if not hasattr(module, name):\n                    missing_parameters.append(name)\n\n            if missing_modules or missing_parameters:\n                raise MisconfigurationException(\n                    \"Some provided `parameters_to_prune` don't exist in the model.\"\n                    f\" Found missing modules: {missing_modules} and missing parameters: {missing_parameters}\"\n                )\n        else:\n            raise MisconfigurationException(\n                \"The provided `parameters_to_prune` should either be list of tuple\"\n                \" with 2 elements: (nn.Module, parameter_name_to_prune) or None\"\n            )\n\n        return parameters_to_prune\n\n    @staticmethod\n    def _is_pruning_method(method: Any) -> bool:\n        if not inspect.isclass(method):\n            return False\n        return issubclass(method, pytorch_prune.BasePruningMethod)\n","sourceCodeStart":469,"sourceCodeEnd":499,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/pruning.py#L469-L499","documentation":"parameters_to_prune must be a list of 2-element tuples (nn.Module instance, parameter_name string) or empty/None. If the value is not such a list (a list of 3-tuples, strings, or a non-list), sanitize_parameters_to_prune raises MisconfigurationException stating the expected shape.","triggerScenarios":"Passing parameters_to_prune=['model.layer1.weight'] (dotted name strings instead of module objects); a list of (module, name, extra) 3-tuples; a dict or generator instead of a list.","commonSituations":"Assuming string module paths like torch.nn.utils.prune examples that use named_modules lookups; generating tuples with a comprehension bug that yields wrong shapes; passing a generator that the isinstance(list) check rejects.","solutions":["Pass module objects with names: parameters_to_prune=[(model.fc1, 'weight'), (model.fc2, 'weight')]","Or leave it None/[] and override filter_parameters_to_prune in a subclass to select modules dynamically","Wrap generators with list() and ensure each item is a 2-tuple"],"exampleFix":"# before\nModelPruning(pruning_fn='l1_unstructured', amount=0.5, parameters_to_prune=['fc1.weight'])\n# after\nModelPruning(pruning_fn='l1_unstructured', amount=0.5, parameters_to_prune=[(model.fc1, 'weight')])","handlingStrategy":"type-guard","validationCode":"def is_valid_prune_list(p) -> bool:\n    return p is None or (isinstance(p, list) and all(\n        isinstance(t, tuple) and len(t) == 2 and isinstance(t[1], str) for t in p\n    ))\nassert is_valid_prune_list(parameters_to_prune)","typeGuard":"def is_valid_prune_list(p) -> bool:\n    return p is None or (isinstance(p, list) and all(\n        isinstance(t, tuple) and len(t) == 2 for t in p\n    ))","tryCatchPattern":null,"preventionTips":["Use (module_object, 'param_name') tuples, never dotted strings","Wrap generators in list() before passing"],"tags":["pytorch-lightning","pruning","parameters-to-prune","argument-validation"],"backgroundTag":"wrong-argument-type","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}