修正 _TruncatedDataLoader 2

This commit is contained in:
YWMditto 2022-08-08 20:32:52 +08:00
parent e86645380a
commit 0033219fe1

View File

@ -132,9 +132,16 @@ class _TruncatedDataLoader:
def __getattr__(self, item):
return getattr(self.dataloader, item)
# def __setattr__(self, key, value):
# # 添加该函数使得在进行实验性训练或者评测时,用户对于 trainer.dataloader 的感觉和正常训练完全一样;
# setattr(self.dataloader, key, value)
def __setattr__(self, key, value):
# 添加该函数使得在进行实验性训练或者评测时,用户对于 trainer.dataloader 的感觉和正常训练完全一样;
# 注意这里不能直接 ``setattr(self.dataloader, key, value)``,会导致死循环;
if "dataloader" in self.__dict__:
if hasattr(self.dataloader, key):
setattr(self.dataloader, key, value)
else:
self.__dict__[key] = value
else:
self.__dict__[key] = value
def check_evaluate_every(evaluate_every):