diff --git a/fastNLP/core/callbacks/torch_callbacks/torch_lr_sched_callback.py b/fastNLP/core/callbacks/torch_callbacks/torch_lr_sched_callback.py index 07c3c612..97e1c544 100644 --- a/fastNLP/core/callbacks/torch_callbacks/torch_lr_sched_callback.py +++ b/fastNLP/core/callbacks/torch_callbacks/torch_lr_sched_callback.py @@ -41,10 +41,9 @@ class TorchWarmupCallback(Callback): return max((progress - 1.) / (self.warmup - 1.), 0.) def on_train_begin(self, trainer): - self.t_steps = trainer.n_batches if self.warmup >1: - self.warmup = self.warmup / self.t_steps - self.t_steps = max(2, self.t_steps) # 不能小于2 + self.warmup = self.warmup / trainer.n_batches + self.t_steps = max(2, trainer.n_batches) # 不能小于2 # 防止 t_steps 不能整除 accumulation_steps self.t_steps = math.ceil(self.t_steps/trainer.accumulation_steps) * trainer.accumulation_steps # 获取param_group的初始learning rate diff --git a/fastNLP/core/collators/collator.py b/fastNLP/core/collators/collator.py index 0ff9fb2a..5a3b1967 100644 --- a/fastNLP/core/collators/collator.py +++ b/fastNLP/core/collators/collator.py @@ -107,7 +107,7 @@ class Collator: 如果需要某些 field 不要包含在 pad 之后的结果中,可以使用 :meth:`~fastNLP.Collator.set_ignore` 进行设置。 Collator 在第一次进行 pad 的时候自动根据设置以及数据情况,为每个 field 获取一个 padder ,在之后的每次调用中,都将使用对应 - 的 Padder 给对应的 field 。 + 的 Padder 给对应的 field 。由于 Collator 只能在某个 field 内进行 pad ,如果 pad 操作需要同时操作多个 field ,请不要使用 Collator 。 :param backend: 对于可以 pad 的 field,使用哪种 tensor,支持 ``['torch','jittor','paddle','oneflow','numpy','raw', 'auto', None]``。 若为 ``'auto'`` ,则在进行 pad 的时候会根据调用的环境决定其 ``backend`` 。该参数对不能进行 pad 的数据没有影响,无法 pad 的数据返回一定 diff --git a/fastNLP/core/controllers/utils/utils.py b/fastNLP/core/controllers/utils/utils.py index 0a351354..ca1e0b86 100644 --- a/fastNLP/core/controllers/utils/utils.py +++ b/fastNLP/core/controllers/utils/utils.py @@ -132,6 +132,17 @@ class _TruncatedDataLoader: def __getattr__(self, item): return getattr(self.dataloader, item) + 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): r""" diff --git a/fastNLP/core/metrics/element.py b/fastNLP/core/metrics/element.py index 5a52e4fa..359df3b8 100644 --- a/fastNLP/core/metrics/element.py +++ b/fastNLP/core/metrics/element.py @@ -88,7 +88,7 @@ class Element: """ 重置 value """ - if self.backend.is_specified(): + if self.backend.is_specified() and self._value is not None: self._value = self.backend.fill_value(self._value, self.init_value) @property diff --git a/fastNLP/io/utils.py b/fastNLP/io/utils.py index a3af71f5..c53d6158 100644 --- a/fastNLP/io/utils.py +++ b/fastNLP/io/utils.py @@ -52,8 +52,8 @@ def check_loader_paths(paths: Union[str, Dict[str, str]]) -> Dict[str, str]: path_pair = ('test', filename) if path_pair: if path_pair[0] in files: - raise FileExistsError(f"Two files contain `{path_pair[0]}` were found, please specify the " - f"filepath for `{path_pair[0]}`.") + raise FileExistsError(f"Two files contain `{path_pair[0]}` were found in {paths}, please specify " + f"the filepath for `{path_pair[0]}`.") files[path_pair[0]] = os.path.join(paths, path_pair[1]) # if 'train' not in files: # raise KeyError(f"There is no train file in {paths}.") diff --git a/setup.py b/setup.py index 21e4c0e4..a3447bf2 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ print(pkgs) setup( name='FastNLP', - version='1.0.0alpha', + version='1.0.0beta', url='https://gitee.com/fastnlp/fastNLP', description='fastNLP: Deep Learning Toolkit for NLP, developed by Fudan FastNLP Team', long_description=readme,