{"record":{"id":"76d903fc43ecc267","repo":"Lightning-AI/pytorch-lightning","slug":"max-depth-can-be-1-0-or-0-got-max-depth","errorCode":null,"errorMessage":"`max_depth` can be -1, 0 or > 0, got {max_depth}.","messagePattern":"`max_depth` can be -1, 0 or > 0, got (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/utilities/model_summary/model_summary.py","lineNumber":217,"sourceCode":"        0 | net   | Sequential  | 132 K  | train | 2.6 M | [10, 256] | [10, 512]\n        1 | net.0 | Linear      | 131 K  | train | 2.6 M | [10, 256] | [10, 512]\n        2 | net.1 | BatchNorm1d | 1.0 K  | train | 0     | [10, 512] | [10, 512]\n        ------------------------------------------------------------------------------\n        132 K     Trainable params\n        0         Non-trainable params\n        132 K     Total params\n        0.530     Total estimated model params size (MB)\n        3         Modules in train mode\n        0         Modules in eval mode\n        2.6 M     Total Flops\n\n    \"\"\"\n\n    def __init__(self, model: \"pl.LightningModule\", max_depth: int = 1) -> None:\n        self._model = model\n\n        if not isinstance(max_depth, int) or max_depth < -1:\n            raise ValueError(f\"`max_depth` can be -1, 0 or > 0, got {max_depth}.\")\n\n        # The max-depth needs to be plus one because the root module is already counted as depth 0.\n        self._flop_counter = FlopCounterMode(display=False, depth=max_depth + 1)\n\n        self._max_depth = max_depth\n        self._layer_summary = self.summarize()\n        # 1 byte -> 8 bits\n        # TODO: how do we compute precision_megabytes in case of mixed precision?\n        precision_to_bits = {\n            \"64\": 64,\n            \"32\": 32,\n            \"16\": 16,\n            \"bf16\": 16,\n            \"16-true\": 16,\n            \"bf16-true\": 16,\n            \"32-true\": 32,\n            \"64-true\": 64,\n        }","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/utilities/model_summary/model_summary.py#L199-L235","documentation":"ModelSummary validates its max_depth argument: it must be an int and >= -1 (-1 means unlimited depth). Passing a non-int (e.g. float or bool misuse) or a value < -1 raises this ValueError at construction.","triggerScenarios":"ModelSummary(model, max_depth=-2) or ModelSummary(model, max_depth=1.0); also Trainer(summary=...) misconfigured with a bad depth value.","commonSituations":"Computing max_depth dynamically (e.g. -len(layers) going below -1), passing a float from config files (YAML parses 1.0 as float).","solutions":["Pass an integer: use -1 for unlimited, 0 for none, or a positive int","Coerce config values: int(max_depth)","Validate depth >= -1 before constructing"],"exampleFix":"# before\nsummary = ModelSummary(model, max_depth=-2)\n# after\nsummary = ModelSummary(model, max_depth=-1)","handlingStrategy":"validation","validationCode":"def valid_depth(d):\n    return isinstance(d, int) and not isinstance(d, bool) and d >= -1\nassert valid_depth(max_depth), 'max_depth must be int >= -1'","typeGuard":"def is_valid_max_depth(d) -> bool:\n    return isinstance(d, int) and not isinstance(d, bool) and d >= -1","tryCatchPattern":null,"preventionTips":["Type-check config values parsed from YAML (int vs float)","Use -1 for unlimited depth instead of large negatives"],"tags":["model-summary","validation","lightning","valueerror"],"backgroundTag":"argument-validation-failed","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}