{"record":{"id":"903103446070f8e8","repo":"Lightning-AI/pytorch-lightning","slug":"verbose-must-be-any-of-0-1-2","errorCode":null,"errorMessage":"`verbose` must be any of (0, 1, 2)","messagePattern":"`verbose` must be any of \\(0, 1, 2\\)","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/pruning.py","lineNumber":231,"sourceCode":"        if use_global_unstructured and pruning_fn.PRUNING_TYPE != \"unstructured\":  # type: ignore\n            raise MisconfigurationException(\n                'Only the \"unstructured\" PRUNING_TYPE is supported with `use_global_unstructured=True`.'\n                f\" Found method {pruning_fn} of type {pruning_fn.PRUNING_TYPE}. \"  # type: ignore[union-attr]\n            )\n\n        self.pruning_fn = pruning_fn\n        self._apply_pruning = apply_pruning\n        self._make_pruning_permanent = make_pruning_permanent\n\n        if not (isinstance(amount, (int, float)) or callable(amount)):\n            raise MisconfigurationException(\n                \"`amount` should be provided and be either an int, a float or Callable function.\"\n            )\n\n        self.amount = amount\n\n        if verbose not in (0, 1, 2):\n            raise MisconfigurationException(\"`verbose` must be any of (0, 1, 2)\")\n\n        self._verbose = verbose\n\n    def filter_parameters_to_prune(self, parameters_to_prune: _PARAM_LIST = ()) -> _PARAM_LIST:\n        \"\"\"This function can be overridden to control which module to prune.\"\"\"\n        return parameters_to_prune\n\n    def _create_pruning_fn(self, pruning_fn: str, **kwargs: Any) -> Union[Callable, pytorch_prune.BasePruningMethod]:\n        \"\"\"This function takes `pruning_fn`, a function name.\n\n        IF use_global_unstructured, pruning_fn will be resolved into its associated ``PyTorch BasePruningMethod`` ELSE,\n        pruning_fn will be resolved into its function counterpart from `torch.nn.utils.prune`.\n\n        \"\"\"\n        pruning_meth = (\n            _PYTORCH_PRUNING_METHOD[pruning_fn]\n            if self._use_global_unstructured\n            else _PYTORCH_PRUNING_FUNCTIONS[pruning_fn]","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/pruning.py#L213-L249","documentation":"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.","triggerScenarios":"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.","commonSituations":"Mapping a boolean 'debug' flag to verbose=True; config files delivering strings; assuming any non-negative int is fine.","solutions":["Use 0 (silent), 1, or 2 (most verbose)","Convert booleans to levels explicitly: verbose = 2 if debug else 0","Coerce config strings with int() before passing"],"exampleFix":"# before\nModelPruning(pruning_fn='l1_unstructured', amount=0.5, verbose=True)\n# after\nModelPruning(pruning_fn='l1_unstructured', amount=0.5, verbose=2)","handlingStrategy":"validation","validationCode":"verbose = int(cfg.get('verbose', 0))\nassert verbose in (0, 1, 2)","typeGuard":"def is_valid_verbose(v) -> bool:\n    return v in (0, 1, 2)","tryCatchPattern":null,"preventionTips":["Map debug booleans to 2/0 explicitly","Only accept 0, 1, 2 in config schemas"],"tags":["pytorch-lightning","pruning","verbose","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}