{"record":{"id":"4236c4a042170594","repo":"Lightning-AI/pytorch-lightning","slug":"empty-dict-cannot-be-interpreted-correct","errorCode":null,"errorMessage":"Empty dict cannot be interpreted correct","messagePattern":"Empty dict cannot be interpreted correct","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/gradient_accumulation_scheduler.py","lineNumber":71,"sourceCode":"            If ``minimal_epoch`` is less than 0.\n\n    Example::\n\n        >>> from lightning.pytorch import Trainer\n        >>> from lightning.pytorch.callbacks import GradientAccumulationScheduler\n\n        # from epoch 5, it starts accumulating every 2 batches. Here we have 4 instead of 5\n        # 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","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/gradient_accumulation_scheduler.py#L53-L89","documentation":"GradientAccumulationScheduler requires a non-empty `scheduling` dict mapping epoch -> accumulation factor. Passing `{}` raises TypeError('Empty dict cannot be interpreted correct') in `__init__` because there is no default schedule to fall back on.","triggerScenarios":"Calling `GradientAccumulationScheduler({})`, commonly when the schedule dict is built programmatically (loop/filter/hyperparameter search) and ends up empty.","commonSituations":"Sweep configs where accumulation schedule is parameterized and collapses to empty; filtering a schedule dict conditionally; YAML config omission parsed to empty mapping.","solutions":["Provide at least one entry, e.g. `{0: 1}` (accumulate 1 from epoch 0)","If you want no accumulation, remove the callback entirely instead of passing an empty dict","Guard programmatically-built dicts: `scheduling or {0: 1}`"],"exampleFix":"# before\nGradientAccumulationScheduler({})\n# after\nGradientAccumulationScheduler({0: 1})","handlingStrategy":"validation","validationCode":"scheduling = scheduling or {0: 1}\nassert scheduling, 'scheduling must not be empty'","typeGuard":"def is_valid_schedule(scheduling: dict) -> bool:\n    return bool(scheduling) and all(isinstance(k, int) and k >= 0 for k in scheduling) and all(isinstance(v, int) and v >= 1 for v in scheduling.values())","tryCatchPattern":null,"preventionTips":["Never pass a possibly-empty programmatically built dict; provide a default","Validate the whole schedule once with the helper above before constructing the callback"],"tags":["lightning","gradient-accumulation","empty-argument","callback-config"],"backgroundTag":"empty-config-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}