{"record":{"id":"f2b8c46aa2380464","repo":"Lightning-AI/pytorch-lightning","slug":"both-name-configure-model-and-name-configu","errorCode":null,"errorMessage":"Both `{name}.configure_model`, and `{name}.configure_sharded_model` are overridden. The latter is deprecated and it should be replaced with the former.","messagePattern":"Both `(.+?)\\.configure_model`, and `(.+?)\\.configure_sharded_model` are overridden\\. The latter is deprecated and it should be replaced with the former\\.","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/configuration_validator.py","lineNumber":157,"sourceCode":"        is_param_in_hook_signature(step_fn, \"dataloader_iter\", explicit=True)\n        for step_fn in (model.training_step, model.validation_step, model.predict_step, model.test_step)\n        if step_fn is not None\n    ):\n        rank_zero_warn(\n            \"You are using the `dataloader_iter` step flavor. If you consume the iterator more than once per step, the\"\n            \" `batch_idx` argument in any hook that takes it will not match with the batch index of the last batch\"\n            \" consumed. This might have unforeseen effects on callbacks or code that expects to get the correct index.\"\n            \" This will also not work well with gradient accumulation. This feature is very experimental and subject to\"\n            \" change. Here be dragons.\",\n            category=PossibleUserWarning,\n        )\n\n\ndef __verify_configure_model_configuration(model: \"pl.LightningModule\") -> None:\n    if is_overridden(\"configure_sharded_model\", model):\n        name = type(model).__name__\n        if is_overridden(\"configure_model\", model):\n            raise RuntimeError(\n                f\"Both `{name}.configure_model`, and `{name}.configure_sharded_model` are overridden. The latter is\"\n                f\" deprecated and it should be replaced with the former.\"\n            )\n        rank_zero_deprecation(\n            f\"You have overridden `{name}.configure_sharded_model` which is deprecated. Please override the\"\n            \" `configure_model` hook instead. Instantiation with the newer hook will be created on the device right\"\n            \" away and have the right data type depending on the precision setting in the Trainer.\"\n        )\n","sourceCodeStart":139,"sourceCodeEnd":166,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/configuration_validator.py#L139-L166","documentation":"The model overrides both `configure_model` and the deprecated `configure_sharded_model`. Lightning instantiates the module via only one hook, so having both is ambiguous; it raises RuntimeError telling you to keep `configure_model`.","triggerScenarios":"A LightningModule defining both `configure_model` and `configure_sharded_model` methods, checked during loop configuration at fit/validate/test time. Often occurs when FSDP/deepspeed examples define `configure_sharded_model` and a base class defines `configure_model`.","commonSituations":"Migrating FSDP/Fabric code from Lightning 1.x to 2.x while adding the new hook without deleting the old one; inheriting from a base class that implements `configure_model` while the subclass implements `configure_sharded_model`.","solutions":["Delete `configure_sharded_model` and move its body into `configure_model`.","If the old hook comes from a base class, remove/override it there (an identity override won't help — `is_overridden` detects it).","Upgrade third-party base classes that still ship the deprecated hook."],"exampleFix":"# before\nclass Model(L.LightningModule):\n    def configure_model(self): ...       # inherited or own\n    def configure_sharded_model(self):   # deprecated, conflicts\n        self.layer = nn.Linear(4, 2)\n# after\nclass Model(L.LightningModule):\n    def configure_model(self):\n        self.layer = nn.Linear(4, 2)","handlingStrategy":"validation","validationCode":"from lightning.pytorch.utilities.model_helpers import is_overridden\n\ndef check_model_hooks(model):\n    if is_overridden('configure_sharded_model', model) and is_overridden('configure_model', model):\n        raise RuntimeError('Remove configure_sharded_model; keep configure_model only')","typeGuard":"def has_single_configure_hook(model) -> bool:\n    return not (is_overridden('configure_sharded_model', model) and is_overridden('configure_model', model))","tryCatchPattern":"except RuntimeError as e: if 'configure_sharded_model' in str(e): delete the legacy method and retry","preventionTips":["During 1.x→2.x migration, delete configure_sharded_model immediately after adding configure_model.","Lint/grep for configure_sharded_model in CI."],"tags":["pytorch-lightning","fsdp","deprecated-hook","configuration"],"backgroundTag":"removed-api-migration-error","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}