Lightning-AI/pytorch-lightning · error · MisconfigurationException

`verbose` must be any of (0, 1, 2)

Error message

`verbose` must be any of (0, 1, 2)

What it means

ModelPruning's verbose parameter controls how much pruning information is printed and only accepts the integers 0, 1, or 2. Anything else (3, -1, True-as-1 works but '1' as a string, None) raises MisconfigurationException.

Source

Thrown at src/lightning/pytorch/callbacks/pruning.py:231

        if use_global_unstructured and pruning_fn.PRUNING_TYPE != "unstructured":  # type: ignore
            raise MisconfigurationException(
                'Only the "unstructured" PRUNING_TYPE is supported with `use_global_unstructured=True`.'
                f" Found method {pruning_fn} of type {pruning_fn.PRUNING_TYPE}. "  # type: ignore[union-attr]
            )

        self.pruning_fn = pruning_fn
        self._apply_pruning = apply_pruning
        self._make_pruning_permanent = make_pruning_permanent

        if not (isinstance(amount, (int, float)) or callable(amount)):
            raise MisconfigurationException(
                "`amount` should be provided and be either an int, a float or Callable function."
            )

        self.amount = amount

        if verbose not in (0, 1, 2):
            raise MisconfigurationException("`verbose` must be any of (0, 1, 2)")

        self._verbose = verbose

    def filter_parameters_to_prune(self, parameters_to_prune: _PARAM_LIST = ()) -> _PARAM_LIST:
        """This function can be overridden to control which module to prune."""
        return parameters_to_prune

    def _create_pruning_fn(self, pruning_fn: str, **kwargs: Any) -> Union[Callable, pytorch_prune.BasePruningMethod]:
        """This function takes `pruning_fn`, a function name.

        IF use_global_unstructured, pruning_fn will be resolved into its associated ``PyTorch BasePruningMethod`` ELSE,
        pruning_fn will be resolved into its function counterpart from `torch.nn.utils.prune`.

        """
        pruning_meth = (
            _PYTORCH_PRUNING_METHOD[pruning_fn]
            if self._use_global_unstructured
            else _PYTORCH_PRUNING_FUNCTIONS[pruning_fn]

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use 0 (silent), 1, or 2 (most verbose)
  2. Convert booleans to levels explicitly: verbose = 2 if debug else 0
  3. Coerce config strings with int() before passing

Example fix

# before
ModelPruning(pruning_fn='l1_unstructured', amount=0.5, verbose=True)
# after
ModelPruning(pruning_fn='l1_unstructured', amount=0.5, verbose=2)
Defensive patterns

Strategy: validation

Validate before calling

verbose = int(cfg.get('verbose', 0))
assert verbose in (0, 1, 2)

Type guard

def is_valid_verbose(v) -> bool:
    return v in (0, 1, 2)

Prevention

When it happens

Trigger: ModelPruning(verbose=3), verbose=-1, or verbose='1' from an un-coerced config string; passing verbose=True (bool) also fails since True is not in (0,1,2) by identity/value check in some Python/type-checker setups.

Common situations: Mapping a boolean 'debug' flag to verbose=True; config files delivering strings; assuming any non-negative int is fine.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/903103446070f8e8. Report an issue: GitHub.