{"record":{"id":"031e3e0f655d1617","repo":"Lightning-AI/pytorch-lightning","slug":"epochs-indexing-from-1-epoch-minimal-epoch-cann","errorCode":null,"errorMessage":"Epochs indexing from 1, epoch {minimal_epoch} cannot be interpreted correct","messagePattern":"Epochs indexing from 1, epoch (.+?) cannot be interpreted correct","errorType":"validation","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/gradient_accumulation_scheduler.py","lineNumber":85,"sourceCode":"    def __init__(self, scheduling: dict[int, int]):\n        super().__init__()\n\n        if not scheduling:  # empty dict error\n            raise TypeError(\"Empty dict cannot be interpreted correct\")\n\n        if any(not isinstance(key, int) or key < 0 for key in scheduling):\n            raise MisconfigurationException(\n                f\"Epoch should be an int greater than or equal to 0. Got {list(scheduling.keys())}.\"\n            )\n\n        if any(not isinstance(value, int) or value < 1 for value in scheduling.values()):\n            raise MisconfigurationException(\n                f\"Accumulation factor should be an int greater than 0. Got {list(scheduling.values())}.\"\n            )\n\n        minimal_epoch = min(scheduling.keys())\n        if minimal_epoch < 0:\n            raise IndexError(f\"Epochs indexing from 1, epoch {minimal_epoch} cannot be interpreted correct\")\n        if minimal_epoch != 0:  # if user didn't define first epoch accumulation factor\n            scheduling.update({0: 1})\n\n        self.scheduling = scheduling\n        self.epochs = sorted(scheduling.keys())\n\n    def going_to_accumulate_grad_batches(self) -> bool:\n        return any(v > 1 for v in self.scheduling.values())\n\n    def get_accumulate_grad_batches(self, epoch: int) -> int:\n        accumulate_grad_batches = 1\n        for iter_epoch in reversed(self.epochs):\n            if epoch >= iter_epoch:\n                accumulate_grad_batches = self.scheduling[iter_epoch]\n                break\n        return accumulate_grad_batches\n\n    @override","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/gradient_accumulation_scheduler.py#L67-L103","documentation":"After the earlier per-key check rejects negative keys, this `min(keys) < 0` IndexError is effectively unreachable defensive code. It exists to reject schedules whose first epoch is negative, with a legacy message implying epochs index from 1. In practice you will always hit the MisconfigurationException at line 74 instead.","triggerScenarios":"Practically none in current versions — negative keys are caught by the preceding check. Only reachable via integer-like objects that pass `isinstance(key, int)` yet compare oddly (e.g. bools, which are ints but never negative).","commonSituations":"Legacy documentation referencing 'epochs indexing from 1'; users on very old Lightning versions where the check order differed.","solutions":["Fix any negative epoch keys to be >= 0 — you'll normally get the clearer MisconfigurationException","Upgrade Lightning to get the well-ordered validation","If you truly see this error, report it as a bug since the guard is defensive"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert all(k >= 0 for k in scheduling), 'epoch keys must be >= 0'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["This branch is defensive/unreachable — fix negative keys via the earlier validation","Keep Lightning updated to benefit from the well-ordered checks"],"tags":["lightning","gradient-accumulation","unreachable","defensive-code"],"backgroundTag":"invalid-config-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}