{"record":{"id":"a505e83fc7a495b4","repo":"Lightning-AI/pytorch-lightning","slug":"accumulation-factor-should-be-an-int-greater-than","errorCode":null,"errorMessage":"Accumulation factor should be an int greater than 0. Got {list(scheduling.values())}.","messagePattern":"Accumulation factor should be an int greater than 0\\. Got (.+?)\\.","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/gradient_accumulation_scheduler.py","lineNumber":79,"sourceCode":"        # because epoch (key) should be zero-indexed.\n        >>> accumulator = GradientAccumulationScheduler(scheduling={4: 2})\n        >>> trainer = Trainer(callbacks=[accumulator])\n\n    \"\"\"\n\n    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):","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/gradient_accumulation_scheduler.py#L61-L97","documentation":"All values of the `scheduling` dict must be ints >= 1 (accumulation factors). Zero, negative, float, or string values raise MisconfigurationException listing the offending values. Validated in `__init__` immediately after the key check.","triggerScenarios":"`GradientAccumulationScheduler({0: 0})`, `{0: 2.5}`, or `{'0': '8'}` — e.g. values loaded from YAML/JSON as strings or computed with float math.","commonSituations":"Config parsed from YAML without type coercion; wanting to 'disable' accumulation for an epoch by setting 0 (use 1 instead); fractional accumulation factors.","solutions":["Use integers >= 1; to disable accumulation for an epoch use 1, never 0","Cast values: `{k: int(v) for k, v in schedule.items()}`","Inspect the value list in the error message to locate bad entries"],"exampleFix":"# before\nGradientAccumulationScheduler({0: 0, 3: 4})\n# after\nGradientAccumulationScheduler({0: 1, 3: 4})","handlingStrategy":"validation","validationCode":"if any(not isinstance(v, int) or v < 1 for v in scheduling.values()):\n    scheduling = {k: int(v) for k, v in scheduling.items()}\nassert all(isinstance(v, int) and v >= 1 for v in scheduling.values())","typeGuard":"def valid_factors(s: dict) -> bool:\n    return all(type(v) is int and v >= 1 for v in s.values())","tryCatchPattern":null,"preventionTips":["Use 1 (not 0) to disable accumulation for an epoch","Coerce values from YAML/JSON to int at config load"],"tags":["lightning","gradient-accumulation","invalid-value","type-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}