Lightning-AI/pytorch-lightning · error · MisconfigurationException
The provided `parameters_to_prune` should either be list of
Error message
The provided `parameters_to_prune` should either be list of tuple with 2 elements: (nn.Module, parameter_name_to_prune) or None
What it means
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.
Source
Thrown at src/lightning/pytorch/callbacks/pruning.py:487
and len(parameters_to_prune) > 0
and all(len(p) == 2 for p in parameters_to_prune)
and all(isinstance(a, nn.Module) and isinstance(b, str) for a, b in parameters_to_prune)
):
missing_modules, missing_parameters = [], []
for module, name in parameters_to_prune:
if module not in current_modules:
missing_modules.append(module)
continue
if not hasattr(module, name):
missing_parameters.append(name)
if missing_modules or missing_parameters:
raise MisconfigurationException(
"Some provided `parameters_to_prune` don't exist in the model."
f" Found missing modules: {missing_modules} and missing parameters: {missing_parameters}"
)
else:
raise MisconfigurationException(
"The provided `parameters_to_prune` should either be list of tuple"
" with 2 elements: (nn.Module, parameter_name_to_prune) or None"
)
return parameters_to_prune
@staticmethod
def _is_pruning_method(method: Any) -> bool:
if not inspect.isclass(method):
return False
return issubclass(method, pytorch_prune.BasePruningMethod)
View on GitHub (pinned to 9fed5c27d2)
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
Example fix
# before ModelPruning(pruning_fn='l1_unstructured', amount=0.5, parameters_to_prune=['fc1.weight']) # after ModelPruning(pruning_fn='l1_unstructured', amount=0.5, parameters_to_prune=[(model.fc1, 'weight')])
Defensive patterns
Strategy: type-guard
Validate before calling
def is_valid_prune_list(p) -> bool:
return p is None or (isinstance(p, list) and all(
isinstance(t, tuple) and len(t) == 2 and isinstance(t[1], str) for t in p
))
assert is_valid_prune_list(parameters_to_prune) Type guard
def is_valid_prune_list(p) -> bool:
return p is None or (isinstance(p, list) and all(
isinstance(t, tuple) and len(t) == 2 for t in p
)) Prevention
- Use (module_object, 'param_name') tuples, never dotted strings
- Wrap generators in list() before passing
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Wrong argument type", "must be a string", "expected Array or Prism::Scope": TypeError and ArgumentError when a library receives a value of the wrong type — this error's family across 28 libraries.
Related errors
- The provided `parameter_names` name: {name} isn't in {self.P
- The provided `pruning_fn` {pruning_fn} isn't available in Py
- `verbose` must be any of (0, 1, 2)
- Some provided `parameters_to_prune` don't exist in the model
- Invalid value for every_n_train_steps={self._every_n_train_s
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/02a9da0c654fa3c1.
Report an issue: GitHub.