@@ -41,10 +41,9 @@ class TorchWarmupCallback(Callback): | |||||
return max((progress - 1.) / (self.warmup - 1.), 0.) | return max((progress - 1.) / (self.warmup - 1.), 0.) | ||||
def on_train_begin(self, trainer): | def on_train_begin(self, trainer): | ||||
self.t_steps = trainer.n_batches | |||||
if self.warmup >1: | 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 | # 防止 t_steps 不能整除 accumulation_steps | ||||
self.t_steps = math.ceil(self.t_steps/trainer.accumulation_steps) * trainer.accumulation_steps | self.t_steps = math.ceil(self.t_steps/trainer.accumulation_steps) * trainer.accumulation_steps | ||||
# 获取param_group的初始learning rate | # 获取param_group的初始learning rate | ||||
@@ -107,7 +107,7 @@ class Collator: | |||||
如果需要某些 field 不要包含在 pad 之后的结果中,可以使用 :meth:`~fastNLP.Collator.set_ignore` 进行设置。 | 如果需要某些 field 不要包含在 pad 之后的结果中,可以使用 :meth:`~fastNLP.Collator.set_ignore` 进行设置。 | ||||
Collator 在第一次进行 pad 的时候自动根据设置以及数据情况,为每个 field 获取一个 padder ,在之后的每次调用中,都将使用对应 | 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]``。 | :param backend: 对于可以 pad 的 field,使用哪种 tensor,支持 ``['torch','jittor','paddle','oneflow','numpy','raw', 'auto', None]``。 | ||||
若为 ``'auto'`` ,则在进行 pad 的时候会根据调用的环境决定其 ``backend`` 。该参数对不能进行 pad 的数据没有影响,无法 pad 的数据返回一定 | 若为 ``'auto'`` ,则在进行 pad 的时候会根据调用的环境决定其 ``backend`` 。该参数对不能进行 pad 的数据没有影响,无法 pad 的数据返回一定 | ||||
@@ -132,6 +132,17 @@ class _TruncatedDataLoader: | |||||
def __getattr__(self, item): | def __getattr__(self, item): | ||||
return getattr(self.dataloader, 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): | def check_evaluate_every(evaluate_every): | ||||
r""" | r""" | ||||
@@ -88,7 +88,7 @@ class Element: | |||||
""" | """ | ||||
重置 value | 重置 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) | self._value = self.backend.fill_value(self._value, self.init_value) | ||||
@property | @property | ||||
@@ -52,8 +52,8 @@ def check_loader_paths(paths: Union[str, Dict[str, str]]) -> Dict[str, str]: | |||||
path_pair = ('test', filename) | path_pair = ('test', filename) | ||||
if path_pair: | if path_pair: | ||||
if path_pair[0] in files: | 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]) | files[path_pair[0]] = os.path.join(paths, path_pair[1]) | ||||
# if 'train' not in files: | # if 'train' not in files: | ||||
# raise KeyError(f"There is no train file in {paths}.") | # raise KeyError(f"There is no train file in {paths}.") | ||||
@@ -16,7 +16,7 @@ print(pkgs) | |||||
setup( | setup( | ||||
name='FastNLP', | name='FastNLP', | ||||
version='1.0.0alpha', | |||||
version='1.0.0beta', | |||||
url='https://gitee.com/fastnlp/fastNLP', | url='https://gitee.com/fastnlp/fastNLP', | ||||
description='fastNLP: Deep Learning Toolkit for NLP, developed by Fudan FastNLP Team', | description='fastNLP: Deep Learning Toolkit for NLP, developed by Fudan FastNLP Team', | ||||
long_description=readme, | long_description=readme, | ||||