{"record":{"id":"9552f558bb95b211","repo":"Lightning-AI/pytorch-lightning","slug":"you-set-type-self-name-use-orig-params-fal","errorCode":null,"errorMessage":"You set `{type(self).__name__}(use_orig_params=False)` but this is not supported when setting the model and optimizer up jointly. Either set it to `True` or set the objects up in this order: Create the model, call `setup_module`, create the optimizer, call `setup_optimizer`.","messagePattern":"You set `(.+?)\\(use_orig_params=False\\)` but this is not supported when setting the model and optimizer up jointly\\. Either set it to `True` or set the objects up in this order: Create the model, call `setup_module`, create the optimizer, call `setup_optimizer`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/fabric/strategies/fsdp.py","lineNumber":275,"sourceCode":"    def setup_environment(self) -> None:\n        super().setup_environment()\n        self._setup_distributed()\n\n        # if 'device_mesh' in the `_fsdp_kwargs` is provided as a tuple, update it into the `DeviceMesh` object here\n        if isinstance(self._fsdp_kwargs.get(\"device_mesh\"), tuple):\n            from torch.distributed.device_mesh import init_device_mesh\n\n            self._fsdp_kwargs[\"device_mesh\"] = init_device_mesh(\"cuda\", self._fsdp_kwargs[\"device_mesh\"])\n\n    @override\n    def setup_module_and_optimizers(\n        self, module: Module, optimizers: list[Optimizer], scheduler: Optional[\"_LRScheduler\"] = None\n    ) -> tuple[Module, list[Optimizer], Optional[\"_LRScheduler\"]]:\n        \"\"\"Wraps the model into a :class:`~torch.distributed.fsdp.fully_sharded_data_parallel.FullyShardedDataParallel`\n        module and sets `use_orig_params=True` to keep the reference to the original parameters in the optimizer.\"\"\"\n        use_orig_params = self._fsdp_kwargs.get(\"use_orig_params\")\n        if use_orig_params is False:\n            raise ValueError(\n                f\"You set `{type(self).__name__}(use_orig_params=False)` but this is not supported when\"\n                \" setting the model and optimizer up jointly. Either set it to `True` or set the objects\"\n                \" up in this order: Create the model, call `setup_module`, create the optimizer,\"\n                \" call `setup_optimizer`.\"\n            )\n        module = self.setup_module(module)\n        return module, optimizers, scheduler\n\n    @override\n    def setup_module(self, module: Module) -> Module:\n        \"\"\"Wraps the model into a :class:`~torch.distributed.fsdp.fully_sharded_data_parallel.FullyShardedDataParallel`\n        module.\"\"\"\n        from torch.distributed.fsdp import FullyShardedDataParallel\n\n        if any(isinstance(mod, FullyShardedDataParallel) for mod in module.modules()):\n            # The user has wrapped their submodules manually, don't apply the auto wrap policy.\n            if _has_meta_device_parameters_or_buffers(module):\n                rank_zero_warn(","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/fabric/strategies/fsdp.py#L257-L293","documentation":"setup_module_and_optimizers wraps model+optimizer jointly and requires use_orig_params=True so the optimizer keeps referencing the original parameters. If the user explicitly set use_orig_params=False in FSDP kwargs, this joint setup is impossible and ValueError is raised.","triggerScenarios":"FSDPStrategy(use_orig_params=False) followed by fabric.setup(model, optimizer) (which routes to setup_module_and_optimizers).","commonSituations":"Copying FSDP kwargs from a script that set up model and optimizer separately; disabling use_orig_params for torch.compile or state-dict compatibility reasons and then switching to joint setup.","solutions":["Set use_orig_params=True (or omit it)","Or change ordering: create model, call fabric.setup_module(model), create the optimizer, then fabric.setup_optimizer(optimizer)"],"exampleFix":"# before\nstrategy = FSDPStrategy(use_orig_params=False)\nmodel, opt = fabric.setup(model, optimizer)\n\n# after\nstrategy = FSDPStrategy(use_orig_params=True)\nmodel, opt = fabric.setup(model, optimizer)","handlingStrategy":"validation","validationCode":"strategy = FSDPStrategy(use_orig_params=True)\nassert strategy._fsdp_kwargs.get(\"use_orig_params\") is not False\nmodel, opt = fabric.setup(model, optimizer)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default use_orig_params to True when using joint setup","Keep one canonical setup order in your codebase"],"tags":["fsdp","use-orig-params","optimizer","setup"],"backgroundTag":"incompatible-strategy-options","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}