在
/usr/local/anaconda3/envs/pcd117/lib/python3.9/site-packages/pytorch_lightning/utilities/data.py
500多行处修改下面这个方法
@contextmanager
def _replace_init_method(base_cls: Type, store_explicit_arg: Optional[str] = None) -> Generator[None, None, None]:"""This context manager is used to add support for re-instantiation of custom (subclasses) of `base_cls`.It patches the ``__init__`` method."""classes = _get_all_subclasses(base_cls) | {base_cls}# wrapped = set()for cls in classes:# if cls.__init__ not in wrapped:# Check that __init__ belongs to the class# https://stackoverflow.com/a/5253424if "__init__" in cls.__dict__:cls._old_init = cls.__init__cls.__init__ = _wrap_init_method(cls.__init__, store_explicit_arg)# wrapped.add(cls.__init__)yieldfor cls in classes:# if hasattr(cls, "_old_init"):# Check that _old_init belongs to the class# https://stackoverflow.com/a/5253424if "_old_init" in cls.__dict__:cls.__init__ = cls._old_initdel cls._old_init
参考:
https://github.com/Lightning-AI/pytorch-lightning/pull/14117/files/cda679840d0637a943c8d3abef65f2df9468f37e#diff-bcd9154b8f707520d4bcfe2e1af39ce5011cc346e20fa22a3ae8754105c71862