{"record":{"id":"fd3833afdfb018b7","repo":"Lightning-AI/pytorch-lightning","slug":"some-provided-parameters-to-prune-don-t-exist-in","errorCode":null,"errorMessage":"Some provided `parameters_to_prune` don't exist in the model. Found missing modules: {missing_modules} and missing parameters: {missing_parameters}","messagePattern":"Some provided `parameters_to_prune` don't exist in the model\\. Found missing modules: (.+?) and missing parameters: (.+?)","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/pruning.py","lineNumber":482,"sourceCode":"                for m in current_modules\n                if getattr(m, p, None) is not None and isinstance(getattr(m, p, None), nn.Parameter)\n            ]\n        elif (\n            isinstance(parameters_to_prune, (list, tuple))\n            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":464,"sourceCodeEnd":499,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/pruning.py#L464-L499","documentation":"ModelPruning.sanitize_parameters_to_prune (invoked from the setup hook) verifies each (module, parameter_name) pair against the actual model. If a listed module object isn't among the model's modules, or a module lacks the named parameter, it raises MisconfigurationException listing the missing modules and missing parameters.","triggerScenarios":"Passing parameters_to_prune=[(some_other_module, 'weight')] where some_other_module is not part of the LightningModule; listing parameter name 'bias' for a module that has bias=False; pruning a layer that was replaced/removed before setup runs.","commonSituations":"Building parameters_to_prune from a different model instance (e.g., the raw nn.Module before wrapping, or after re-instantiating the model); Conv/Linear layers created with bias=False; refactors that rename layers after the pruning list was written.","solutions":["Build parameters_to_prune from the actual model instance that will be trained, e.g., [(m, 'weight') for m in model.modules() if isinstance(m, nn.Linear)]","Check hasattr(module, param_name) for every entry before constructing the callback","Only use parameter names that exist on the target modules ('weight' always; 'bias' only if the layer was created with bias=True)"],"exampleFix":"# before\nparameters_to_prune = [(model.features[0], 'bias')]  # layer created with bias=False\n# after\nparameters_to_prune = [(m, 'weight') for m in model.modules() if isinstance(m, nn.Linear)]","handlingStrategy":"validation","validationCode":"model_modules = {id(m) for m in model.modules()}\nfor mod, name in parameters_to_prune:\n    assert id(mod) in model_modules and hasattr(mod, name), f'{mod} lacks {name}'","typeGuard":"def params_exist_in_model(params, model) -> bool:\n    mods = list(model.modules())\n    return all(p[0] in mods and len(p) == 2 and hasattr(p[0], p[1]) for p in params)","tryCatchPattern":"try:\n    pruner.sanitize_parameters_to_prune(parameters_to_prune)\nexcept Exception as e:\n    parameters_to_prune = [(m, 'weight') for m in model.modules() if isinstance(m, nn.Linear)]","preventionTips":["Build parameters_to_prune from the same model instance passed to Trainer","Check hasattr(module, 'bias') before including it","Rebuild the list after model refactors"],"tags":["pytorch-lightning","pruning","parameters-to-prune","model-mismatch"],"backgroundTag":"model-layer-not-found","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}