Lightning-AI/pytorch-lightning · error · MisconfigurationException
Accumulation factor should be an int greater than 0. Got {li
Error message
Accumulation factor should be an int greater than 0. Got {list(scheduling.values())}. What it means
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.
Source
Thrown at src/lightning/pytorch/callbacks/gradient_accumulation_scheduler.py:79
# because epoch (key) should be zero-indexed.
>>> accumulator = GradientAccumulationScheduler(scheduling={4: 2})
>>> trainer = Trainer(callbacks=[accumulator])
"""
def __init__(self, scheduling: dict[int, int]):
super().__init__()
if not scheduling: # empty dict error
raise TypeError("Empty dict cannot be interpreted correct")
if any(not isinstance(key, int) or key < 0 for key in scheduling):
raise MisconfigurationException(
f"Epoch should be an int greater than or equal to 0. Got {list(scheduling.keys())}."
)
if any(not isinstance(value, int) or value < 1 for value in scheduling.values()):
raise MisconfigurationException(
f"Accumulation factor should be an int greater than 0. Got {list(scheduling.values())}."
)
minimal_epoch = min(scheduling.keys())
if minimal_epoch < 0:
raise IndexError(f"Epochs indexing from 1, epoch {minimal_epoch} cannot be interpreted correct")
if minimal_epoch != 0: # if user didn't define first epoch accumulation factor
scheduling.update({0: 1})
self.scheduling = scheduling
self.epochs = sorted(scheduling.keys())
def going_to_accumulate_grad_batches(self) -> bool:
return any(v > 1 for v in self.scheduling.values())
def get_accumulate_grad_batches(self, epoch: int) -> int:
accumulate_grad_batches = 1
for iter_epoch in reversed(self.epochs):View on GitHub (pinned to 9fed5c27d2)
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
Example fix
# before
GradientAccumulationScheduler({0: 0, 3: 4})
# after
GradientAccumulationScheduler({0: 1, 3: 4}) Defensive patterns
Strategy: validation
Validate before calling
if any(not isinstance(v, int) or v < 1 for v in scheduling.values()):
scheduling = {k: int(v) for k, v in scheduling.items()}
assert all(isinstance(v, int) and v >= 1 for v in scheduling.values()) Type guard
def valid_factors(s: dict) -> bool:
return all(type(v) is int and v >= 1 for v in s.values()) Prevention
- Use 1 (not 0) to disable accumulation for an epoch
- Coerce values from YAML/JSON to int at config load
When it happens
Trigger: `GradientAccumulationScheduler({0: 0})`, `{0: 2.5}`, or `{'0': '8'}` — e.g. values loaded from YAML/JSON as strings or computed with float math.
Common situations: Config parsed from YAML without type coercion; wanting to 'disable' accumulation for an epoch by setting 0 (use 1 instead); fractional accumulation factors.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Epoch should be an int greater than or equal to 0. Got {list
- Filter should be a dictionary, given {filter!r}
- Expected `fabric.save(filter=...)` for key {k!r} to be a cal
- Empty dict cannot be interpreted correct
- Epochs indexing from 1, epoch {minimal_epoch} cannot be inte
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/a505e83fc7a495b4.
Report an issue: GitHub.