{"record":{"id":"cec338fe08a24ab3","repo":"Lightning-AI/pytorch-lightning","slug":"write-interval-should-be-one-of-i-value-for-i","errorCode":null,"errorMessage":"`write_interval` should be one of {[i.value for i in WriteInterval]}.","messagePattern":"`write_interval` should be one of (.+?)\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/prediction_writer.py","lineNumber":112,"sourceCode":"                torch.save(predictions, os.path.join(self.output_dir, f\"predictions_{trainer.global_rank}.pt\"))\n\n                # optionally, you can also save `batch_indices` to get the information about the data index\n                # from your prediction data\n                torch.save(batch_indices, os.path.join(self.output_dir, f\"batch_indices_{trainer.global_rank}.pt\"))\n\n\n        # or you can set `write_interval=\"batch\"` and override `write_on_batch_end` to save\n        # predictions at batch level\n        pred_writer = CustomWriter(output_dir=\"pred_path\", write_interval=\"epoch\")\n        trainer = Trainer(accelerator=\"gpu\", strategy=\"ddp\", devices=8, callbacks=[pred_writer])\n        model = BoringModel()\n        trainer.predict(model, return_predictions=False)\n\n    \"\"\"\n\n    def __init__(self, write_interval: Literal[\"batch\", \"epoch\", \"batch_and_epoch\"] = \"batch\") -> None:\n        if write_interval not in list(WriteInterval):\n            raise MisconfigurationException(f\"`write_interval` should be one of {[i.value for i in WriteInterval]}.\")\n        self.interval = WriteInterval(write_interval)\n\n    @override\n    def setup(self, trainer: \"pl.Trainer\", pl_module: \"pl.LightningModule\", stage: str) -> None:\n        if is_param_in_hook_signature(pl_module.predict_step, \"dataloader_iter\", explicit=True):\n            raise NotImplementedError(\"The `PredictionWriterCallback` does not support using `dataloader_iter`.\")\n\n    def write_on_batch_end(\n        self,\n        trainer: \"pl.Trainer\",\n        pl_module: \"pl.LightningModule\",\n        prediction: Any,\n        batch_indices: Optional[Sequence[int]],\n        batch: Any,\n        batch_idx: int,\n        dataloader_idx: int,\n    ) -> None:\n        \"\"\"Override with the logic to write a single batch.\"\"\"","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/prediction_writer.py#L94-L130","documentation":"BasePredictionWriter writes prediction batches/epochs to storage at a configurable interval. write_interval must be one of the WriteInterval enum values: 'batch', 'epoch', or 'batch_and_epoch'; any other string raises MisconfigurationException in __init__.","triggerScenarios":"Passing write_interval='step', 'every_batch', 'batch_epoch', or a typo like 'epcoh' to BasePredictionWriter; using a value from a config that doesn't match the enum.","commonSituations":"Guessing the API ('step' seems natural but is invalid); case sensitivity ('Batch' fails); stale configs written against a different callback's vocabulary.","solutions":["Use one of 'batch', 'epoch', or 'batch_and_epoch' exactly","Validate config-sourced values against ['batch','epoch','batch_and_epoch'] before constructing the callback"],"exampleFix":"# before\nBasePredictionWriter(write_interval='step')\n# after\nBasePredictionWriter(write_interval='batch')","handlingStrategy":"validation","validationCode":"VALID = {'batch', 'epoch', 'batch_and_epoch'}\ninterval = cfg.get('write_interval', 'batch')\nassert interval in VALID, f\"write_interval must be one of {VALID}, got {interval!r}\"","typeGuard":"def is_write_interval(v) -> bool:\n    return v in ('batch', 'epoch', 'batch_and_epoch')","tryCatchPattern":null,"preventionTips":["Copy enum values from the WriteInterval docs, not from memory","Centralize allowed-value sets for config validation"],"tags":["pytorch-lightning","prediction-writer","write-interval","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}