Lightning-AI/pytorch-lightning · error · RuntimeError
Both `{name}.configure_model`, and `{name}.configure_sharded
Error message
Both `{name}.configure_model`, and `{name}.configure_sharded_model` are overridden. The latter is deprecated and it should be replaced with the former. What it means
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`.
Source
Thrown at src/lightning/pytorch/trainer/configuration_validator.py:157
is_param_in_hook_signature(step_fn, "dataloader_iter", explicit=True)
for step_fn in (model.training_step, model.validation_step, model.predict_step, model.test_step)
if step_fn is not None
):
rank_zero_warn(
"You are using the `dataloader_iter` step flavor. If you consume the iterator more than once per step, the"
" `batch_idx` argument in any hook that takes it will not match with the batch index of the last batch"
" consumed. This might have unforeseen effects on callbacks or code that expects to get the correct index."
" This will also not work well with gradient accumulation. This feature is very experimental and subject to"
" change. Here be dragons.",
category=PossibleUserWarning,
)
def __verify_configure_model_configuration(model: "pl.LightningModule") -> None:
if is_overridden("configure_sharded_model", model):
name = type(model).__name__
if is_overridden("configure_model", model):
raise RuntimeError(
f"Both `{name}.configure_model`, and `{name}.configure_sharded_model` are overridden. The latter is"
f" deprecated and it should be replaced with the former."
)
rank_zero_deprecation(
f"You have overridden `{name}.configure_sharded_model` which is deprecated. Please override the"
" `configure_model` hook instead. Instantiation with the newer hook will be created on the device right"
" away and have the right data type depending on the precision setting in the Trainer."
)
View on GitHub (pinned to 9fed5c27d2)
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.
Example fix
# before
class Model(L.LightningModule):
def configure_model(self): ... # inherited or own
def configure_sharded_model(self): # deprecated, conflicts
self.layer = nn.Linear(4, 2)
# after
class Model(L.LightningModule):
def configure_model(self):
self.layer = nn.Linear(4, 2) Defensive patterns
Strategy: validation
Validate before calling
from lightning.pytorch.utilities.model_helpers import is_overridden
def check_model_hooks(model):
if is_overridden('configure_sharded_model', model) and is_overridden('configure_model', model):
raise RuntimeError('Remove configure_sharded_model; keep configure_model only') Type guard
def has_single_configure_hook(model) -> bool:
return not (is_overridden('configure_sharded_model', model) and is_overridden('configure_model', model)) Try / catch
except RuntimeError as e: if 'configure_sharded_model' in str(e): delete the legacy method and retry
Prevention
- During 1.x→2.x migration, delete configure_sharded_model immediately after adding configure_model.
- Lint/grep for configure_sharded_model in CI.
When it happens
Trigger: 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`.
Common situations: 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`.
Related errors
- The optimizer has references to the model's meta-device para
- `precision={precision!r})` is not supported in FSDP. `precis
- `precision={precision!r}` does not use a scaler, found {scal
- Gradient clipping is not implemented for optimizers handling
- Found multiple FSDP models in the given state. Saving checkp
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/f2b8c46aa2380464.
Report an issue: GitHub.