{"record":{"id":"92c57999142ced4b","repo":"Lightning-AI/pytorch-lightning","slug":"f-gradient-clip-algorithm-gradient-clip-algorit","errorCode":null,"errorMessage":"f\"`gradient_clip_algorithm` {gradient_clip_algorithm} is invalid. \" f\"Allowed algorithms: {GradClipAlgorithmType.supported_types()}.\"","messagePattern":"f\"`gradient_clip_algorithm` (.+?) is invalid\\. \" f\"Allowed algorithms: (.+?)\\.\"","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/trainer.py","lineNumber":477,"sourceCode":"            max_time,\n        )\n\n        # init data flags\n        self.check_val_every_n_epoch: Optional[int]\n        self._data_connector.on_trainer_init(\n            val_check_interval,\n            reload_dataloaders_every_n_epochs,\n            check_val_every_n_epoch,\n        )\n\n        # gradient clipping\n        if gradient_clip_val is not None and not isinstance(gradient_clip_val, (int, float)):\n            raise TypeError(f\"`gradient_clip_val` should be an int or a float. Got {gradient_clip_val}.\")\n\n        if gradient_clip_algorithm is not None and not GradClipAlgorithmType.supported_type(\n            gradient_clip_algorithm.lower()\n        ):\n            raise MisconfigurationException(\n                f\"`gradient_clip_algorithm` {gradient_clip_algorithm} is invalid. \"\n                f\"Allowed algorithms: {GradClipAlgorithmType.supported_types()}.\"\n            )\n\n        self.gradient_clip_val: Optional[Union[int, float]] = gradient_clip_val\n        self.gradient_clip_algorithm: Optional[GradClipAlgorithmType] = (\n            GradClipAlgorithmType(gradient_clip_algorithm.lower()) if gradient_clip_algorithm is not None else None\n        )\n\n        if detect_anomaly:\n            rank_zero_info(\n                \"You have turned on `Trainer(detect_anomaly=True)`. This will significantly slow down compute speed and\"\n                \" is recommended only for model debugging.\"\n            )\n        self._detect_anomaly: bool = detect_anomaly\n\n        setup._log_device_info(self)\n","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/trainer.py#L459-L495","documentation":"gradient_clip_algorithm was not one of the supported clipping algorithms. Lightning supports only the values in GradClipAlgorithmType (norm and value); anything else is rejected as a MisconfigurationException.","triggerScenarios":"Trainer(gradient_clip_algorithm=\"gradd\") (typo), \"global_norm\", or another framework's algorithm name; the check is case-insensitive against the allowed set.","commonSituations":"Typos, porting code from other frameworks expecting different algorithm names, or assuming more clipping modes exist than are implemented.","solutions":["Use gradient_clip_algorithm=\"norm\" (default) or \"value\"","Check the error message which lists GradClipAlgorithmType.supported_types()","Fix the typo in the string"],"exampleFix":"# before\ntrainer = Trainer(gradient_clip_algorithm=\"gradd_norm\")\n# after\ntrainer = Trainer(gradient_clip_algorithm=\"norm\")","handlingStrategy":"validation","validationCode":"from lightning.pytorch.trainer import GradClipAlgorithmType  # or lightning_fabric.utilities\nalgo = cfg.get(\"gradient_clip_algorithm\")\nif algo is not None and algo.lower() not in (\"norm\", \"value\"):\n    raise ValueError(f\"unsupported clip algo {algo}\")","typeGuard":"def is_valid_clip_algo(a) -> bool:\n    return a is None or str(a).lower() in {\"norm\", \"value\"}","tryCatchPattern":null,"preventionTips":["Only 'norm' and 'value' are supported — validate against the enum before constructing the Trainer","Log the value at startup to catch typo'd config keys"],"tags":["trainer","gradient-clipping","invalid-argument","misconfiguration","pytorch-lightning"],"backgroundTag":"invalid-enum-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}