{"record":{"id":"73219ab7c519761c","repo":"Lightning-AI/pytorch-lightning","slug":"precision-precision-r-does-not-use-a-scaler-f","errorCode":null,"errorMessage":"`precision={precision!r}` does not use a scaler, found {scaler}.","messagePattern":"`precision=(.+?)` does not use a scaler, found (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/plugins/precision/fsdp.py","lineNumber":64,"sourceCode":"\n    Raises:\n        ValueError:\n            If unsupported ``precision`` is provided.\n\n    \"\"\"\n\n    def __init__(self, precision: _PRECISION_INPUT, scaler: Optional[\"ShardedGradScaler\"] = None) -> None:\n        supported_precision = get_args(_PRECISION_INPUT)\n        if precision not in supported_precision:\n            raise ValueError(\n                f\"`precision={precision!r})` is not supported in FSDP.\"\n                f\" `precision` must be one of: {supported_precision}.\"\n            )\n\n        from torch.distributed.fsdp.sharded_grad_scaler import ShardedGradScaler\n\n        if scaler is not None and self.precision != \"16-mixed\":\n            raise ValueError(f\"`precision={precision!r}` does not use a scaler, found {scaler}.\")\n\n        self.scaler = ShardedGradScaler() if scaler is None and precision == \"16-mixed\" else None\n        self.precision = precision\n\n        precision_to_type = {\n            \"bf16-mixed\": torch.float32,\n            \"16-mixed\": torch.float32,\n            \"bf16-true\": torch.bfloat16,\n            \"16-true\": torch.float16,\n            \"32-true\": torch.float32,\n        }\n        self._desired_input_dtype = precision_to_type[self.precision]\n\n    @override\n    def convert_module(self, module: Module) -> Module:\n        if \"true\" in self.precision:\n            return module.to(dtype=self._desired_input_dtype)\n        return module","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/plugins/precision/fsdp.py#L46-L82","documentation":"FSDPPrecision only uses a GradScaler with '16-mixed' precision. If you explicitly pass a scaler instance while using any other precision (e.g. 'bf16-mixed' or '32-true'), the constructor raises this ValueError because the scaler would never be used.","triggerScenarios":"Calling FSDPPrecision(precision='bf16-mixed', scaler=ShardedGradScaler()) — i.e. providing a non-None scaler together with a precision other than '16-mixed'.","commonSituations":"Copy-pasting a 16-mixed setup when switching to bf16; programmatically passing a scaler regardless of precision setting.","solutions":["Remove the scaler argument when precision is not '16-mixed' (bfloat16/32 do not need loss scaling)","Only construct and pass a ShardedGradScaler when precision == '16-mixed'","Let the plugin auto-create the scaler by passing scaler=None with '16-mixed'"],"exampleFix":"# before\nprecision = FSDPPrecision(precision=\"bf16-mixed\", scaler=ShardedGradScaler())\n# after\nprecision = FSDPPrecision(precision=\"bf16-mixed\")","handlingStrategy":"validation","validationCode":"if scaler is not None and precision != \"16-mixed\":\n    raise ValueError(\"scaler only valid with 16-mixed\")\nplugin = FSDPPrecision(precision, scaler=scaler if precision == \"16-mixed\" else None)","typeGuard":"def scaler_compatible(precision: str, scaler: object) -> bool:\n    return scaler is None or precision == \"16-mixed\"","tryCatchPattern":"try:\n    plugin = FSDPPrecision(precision, scaler=scaler)\nexcept ValueError:\n    plugin = FSDPPrecision(precision)","preventionTips":["Only build a scaler when precision == '16-mixed'","Prefer scaler=None and let the plugin auto-create it"],"tags":["fsdp","precision","grad-scaler","pytorch-lightning"],"backgroundTag":"invalid-argument-combination","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}