Browse Source

Merge branch 'dev0.8.0' of github.com:fastnlp/fastNLP into dev0.8.0

tags/1.0.0beta2
x54-729 2 years ago
parent
commit
8b8dcdd82b
6 changed files with 18 additions and 8 deletions
  1. +2
    -3
      fastNLP/core/callbacks/torch_callbacks/torch_lr_sched_callback.py
  2. +1
    -1
      fastNLP/core/collators/collator.py
  3. +11
    -0
      fastNLP/core/controllers/utils/utils.py
  4. +1
    -1
      fastNLP/core/metrics/element.py
  5. +2
    -2
      fastNLP/io/utils.py
  6. +1
    -1
      setup.py

+ 2
- 3
fastNLP/core/callbacks/torch_callbacks/torch_lr_sched_callback.py View File

@@ -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


+ 1
- 1
fastNLP/core/collators/collator.py View File

@@ -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 的数据返回一定


+ 11
- 0
fastNLP/core/controllers/utils/utils.py View File

@@ -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"""


+ 1
- 1
fastNLP/core/metrics/element.py View File

@@ -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


+ 2
- 2
fastNLP/io/utils.py View File

@@ -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}.")


+ 1
- 1
setup.py View File

@@ -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,


Loading…
Cancel
Save