Lightning-AI/pytorch-lightning · error · MisconfigurationException
The {constructor.__name__} implementation has an error where
Error message
The {constructor.__name__} implementation has an error where more than one `__init__` argument can be passed to its parent's `{argument}=...` `__init__` argument. This is likely caused by allowing passing both a custom argument that will map to the `{argument}` argument as well as `**kwargs`. `kwargs` should be filtered to make sure they don't contain the `{argument}` key. This argument was automatically passed to your object by PyTorch Lightning. What it means
While re-instantiating a wrapped object (dataloader or batch sampler), Lightning caught a TypeError from the constructor indicating a duplicate keyword: the user's class both maps its own argument onto a parent argument (e.g. `ds` passed as `dataset`) and forwards unfiltered `**kwargs` that also contain that key. Lightning converts this into a MisconfigurationException pinpointing the duplicated argument.
Source
Thrown at src/lightning/fabric/utilities/data.py:275
result = constructor(*args, **kwargs)
except TypeError as ex:
# improve exception message due to an incorrect implementation of the `DataLoader` where multiple subclass
# `__init__` arguments map to one `DataLoader.__init__` argument
import re
match = re.match(r".*__init__\(\) got multiple values .* '(\w+)'", str(ex))
if not match:
# an unexpected `TypeError`, continue failure
raise
argument = match.groups()[0]
message = (
f"The {constructor.__name__} implementation has an error where more than one `__init__` argument"
f" can be passed to its parent's `{argument}=...` `__init__` argument. This is likely caused by allowing"
f" passing both a custom argument that will map to the `{argument}` argument as well as `**kwargs`."
f" `kwargs` should be filtered to make sure they don't contain the `{argument}` key."
" This argument was automatically passed to your object by PyTorch Lightning."
)
raise MisconfigurationException(message) from ex
attrs_record = getattr(orig_object, "__pl_attrs_record", [])
for args, fn in attrs_record:
fn(result, *args)
return result
def _wrap_init_method(init: Callable, store_explicit_arg: Optional[str] = None) -> Callable:
"""Wraps the ``__init__`` method of classes (currently :class:`~torch.utils.data.DataLoader` and
:class:`~torch.utils.data.BatchSampler`) in order to enable re-instantiation of custom subclasses."""
@functools.wraps(init)
def wrapper(obj: Any, *args: Any, **kwargs: Any) -> None:
# We need to inspect `init`, as inspecting `obj.__init__`
# can lead to inspecting the wrong function with multiple inheritance
old_inside_init = getattr(obj, "__pl_inside_init", False)
object.__setattr__(obj, "__pl_inside_init", True)View on GitHub (pinned to 9fed5c27d2)
Solutions
- Filter the overlapping key out of kwargs before forwarding: `kwargs.pop('dataset', None)` (or whichever argument the error names).
- Don't rename the argument — keep the parent's name (`dataset`) in your `__init__` and forward it directly.
- Accept the parent's exact signature (or `*args, **kwargs` only) so no duplicate mapping can occur.
Example fix
# before
class MyLoader(DataLoader):
def __init__(self, ds, **kwargs):
super().__init__(dataset=ds, **kwargs) # kwargs may contain 'dataset'
# after
class MyLoader(DataLoader):
def __init__(self, ds, **kwargs):
kwargs.pop('dataset', None)
super().__init__(dataset=ds, **kwargs) Defensive patterns
Strategy: validation
Validate before calling
import inspect
def has_duplicate_kwarg_forwarding(cls, parent_arg="dataset") -> bool:
params = inspect.signature(cls.__init__).parameters
has_var_kw = any(p.kind is inspect.Parameter.VAR_KEYWORD for p in params.values())
renamed = parent_arg not in params and has_var_kw # custom arg likely maps to parent_arg
return renamed
# if has_duplicate_kwarg_forwarding(MyLoader): fix class before use Try / catch
try:
fabric.setup_dataloaders(loader)
except MisconfigurationException as e:
if "more than one `__init__` argument" in str(e):
raise # fix the wrapper class as message instructs
raise Prevention
- Never rename parent arguments while also forwarding **kwargs; pop overlapping keys.
- Keep parent argument names (dataset, sampler, batch_sampler) in wrapper __init__ signatures.
- Unit-test wrapper constructors against the exact kwargs Lightning injects.
When it happens
Trigger: A custom class whose `__init__` signature has a custom parameter that it forwards to a parent's parameter (like `dataset` or `sampler`) while also passing `**kwargs` through unchanged; Lightning auto-passes that argument (e.g. when injecting a sampler or dataset), producing 'got multiple values for keyword argument'.
Common situations: Wrapper DataLoaders/batch samplers that rename arguments (e.g. `def __init__(self, ds, **kwargs): super().__init__(dataset=ds, **kwargs)`) combined with Lightning's automatic injection.
Related errors
- Trying to inject parameters into the `{dataloader_cls_name}`
- Trying to inject parameters into the `{dataloader_cls_name}`
- `setup_dataloaders` requires at least one dataloader as inpu
- A dataloader should be passed only once to the `setup_datalo
- Only PyTorch DataLoader are currently supported in `setup_da
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/41dd10e4782d8979.
Report an issue: GitHub.