From 0033219fe126a8505400f84dee3a0d9b1a8bdf7a Mon Sep 17 00:00:00 2001 From: YWMditto Date: Mon, 8 Aug 2022 20:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20=5FTruncatedDataLoader=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastNLP/core/controllers/utils/utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fastNLP/core/controllers/utils/utils.py b/fastNLP/core/controllers/utils/utils.py index 998b3787..ca1e0b86 100644 --- a/fastNLP/core/controllers/utils/utils.py +++ b/fastNLP/core/controllers/utils/utils.py @@ -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):