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

This commit is contained in:
MorningForest 2022-05-01 17:19:50 +08:00
commit ac61430aa1
13 changed files with 44 additions and 4 deletions

View File

@ -70,6 +70,7 @@ def model_and_optimizers(request):
return trainer_params
@pytest.mark.torch
@pytest.mark.parametrize("driver,device", [("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)
@pytest.mark.parametrize("version", [0, 1])
@pytest.mark.parametrize("only_state_dict", [True, False])
@ -201,6 +202,7 @@ def test_model_checkpoint_callback_1(
dist.destroy_process_group()
@pytest.mark.torch
@pytest.mark.parametrize("driver,device", [("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)
@pytest.mark.parametrize("only_state_dict", [True])
@magic_argv_env_context(timeout=100)
@ -293,6 +295,7 @@ def test_model_checkpoint_callback_2(
dist.destroy_process_group()
@pytest.mark.torch
@pytest.mark.parametrize("driver,device", [("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 0)]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)
@pytest.mark.parametrize("version", [0, 1])
@pytest.mark.parametrize("only_state_dict", [True, False])
@ -423,7 +426,7 @@ def test_trainer_checkpoint_callback_1(
dist.destroy_process_group()
@pytest.mark.torch
# 通过自己编写 model_save_fn 和 model_load_fn 来测试 huggingface 的 transformers 的模型的保存和加载;
@pytest.mark.parametrize("driver,device", [("torch_ddp", [6, 7]), ("torch", 7)]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)
@pytest.mark.parametrize("version", [0, 1])

View File

@ -70,8 +70,8 @@ def model_and_optimizers(request):
return trainer_params
# pytest test_load_best_model_callback_torch.py::test_load_best_model_callback -s
@pytest.mark.torch
@pytest.mark.parametrize("driver,device", [("torch_ddp", [4, 5]), ("torch", 1), ("torch", "cpu")]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)
@pytest.mark.parametrize("save_folder", ['save_models', None])
@pytest.mark.parametrize("only_state_dict", [True, False])

View File

@ -95,6 +95,7 @@ def model_and_optimizers(request):
return trainer_params
@pytest.mark.torch
@pytest.mark.parametrize("driver,device", [("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)
@pytest.mark.parametrize("version", [0, 1])
@pytest.mark.parametrize("only_state_dict", [True, False])
@ -179,6 +180,7 @@ def test_model_more_evaluate_callback_1(
dist.destroy_process_group()
@pytest.mark.torch
@pytest.mark.parametrize("driver,device", [("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 0)]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1)
@pytest.mark.parametrize("version", [0, 1])
@pytest.mark.parametrize("only_state_dict", [True, False])

View File

@ -25,6 +25,7 @@ class CheckClipCallback(Callback):
assert np.linalg.norm(param.grad.cpu().view(-1).numpy())<=self.clip_value
@pytest.mark.torch
@pytest.mark.parametrize('accumulation_steps', [1, 3, 5])
@pytest.mark.parametrize('fp16', [True, False])
@pytest.mark.parametrize('clip_type', ['norm', 'value'])

View File

@ -15,6 +15,7 @@ class RecordLrCallback(Callback):
self.lrs.append(trainer.driver.optimizers[0].param_groups[0]['lr'])
@pytest.mark.torch
@pytest.mark.parametrize('warmup', [5, 0.1])
@pytest.mark.parametrize('schedule', ['constant', 'linear'])
@pytest.mark.parametrize('accumulation_steps', [1, 3, 4])

View File

@ -72,6 +72,7 @@ def dataloader_with_randomsampler(dataset, batch_size, shuffle, drop_last, seed=
#
############################################################################
@pytest.mark.torch
class TestDDPDriverFunction:
"""
测试 TorchDDPDriver 一些简单函数的测试类基本都是测试能否运行是否存在 import 错误等问题
@ -180,6 +181,7 @@ class TestDDPDriverFunction:
#
############################################################################
@pytest.mark.torch
class TestSetDistReproDataloader:
@classmethod
@ -526,6 +528,7 @@ class TestSetDistReproDataloader:
# 测试 save 和 load 相关的功能
#
############################################################################
@pytest.mark.torch
class TestSaveLoad:
"""
测试多卡情况下 save load 相关函数的表现

View File

@ -11,6 +11,7 @@ from fastNLP.core.drivers.torch_driver.dist_utils import fastnlp_torch_all_gathe
from tests.helpers.utils import re_run_current_cmd_for_torch, magic_argv_env_context
@pytest.mark.torch
@magic_argv_env_context
def test_fastnlp_torch_all_gather():
os.environ['MASTER_ADDR'] = '127.0.0.1'
@ -59,6 +60,7 @@ def test_fastnlp_torch_all_gather():
dist.destroy_process_group()
@pytest.mark.torch
@magic_argv_env_context
def test_fastnlp_torch_broadcast_object():
os.environ['MASTER_ADDR'] = '127.0.0.1'

View File

@ -8,12 +8,16 @@ from tests.helpers.utils import magic_argv_env_context
import torch
@pytest.mark.torch
def test_incorrect_driver():
model = TorchNormalModel_Classification_1(2, 100)
with pytest.raises(ValueError):
driver = initialize_torch_driver("paddle", 0, model)
@pytest.mark.torch
@pytest.mark.parametrize(
"device",
["cpu", "cuda:0", 0, torch.device("cuda:0")]
@ -31,6 +35,8 @@ def test_get_single_device(driver, device):
driver = initialize_torch_driver(driver, device, model)
assert isinstance(driver, TorchSingleDriver)
@pytest.mark.torch
@pytest.mark.parametrize(
"device",
[0, 1]
@ -50,6 +56,8 @@ def test_get_ddp_2(driver, device):
assert isinstance(driver, TorchDDPDriver)
@pytest.mark.torch
@pytest.mark.parametrize(
"device",
[[0, 2, 3], -1]
@ -69,6 +77,8 @@ def test_get_ddp(driver, device):
assert isinstance(driver, TorchDDPDriver)
@pytest.mark.torch
@pytest.mark.parametrize(
("driver", "device"),
[("torch_ddp", "cpu")]
@ -82,6 +92,8 @@ def test_get_ddp_cpu(driver, device):
with pytest.raises(ValueError):
driver = initialize_torch_driver(driver, device, model)
@pytest.mark.torch
@pytest.mark.parametrize(
"device",
[-2, [0, torch.cuda.device_count() + 1, 3], [-2], torch.cuda.device_count() + 1]

View File

@ -9,6 +9,8 @@ from torch.utils.data import DataLoader, BatchSampler
from tests.helpers.datasets.torch_data import TorchNormalDataset
@pytest.mark.torch
def test_replace_batch_sampler():
dataset = TorchNormalDataset(10)
dataloader = DataLoader(dataset, batch_size=32)
@ -22,6 +24,8 @@ def test_replace_batch_sampler():
assert len(replaced_loader.dataset) == len(dataset)
assert replaced_loader.batch_sampler.batch_size == 16
@pytest.mark.torch
def test_replace_sampler():
dataset = TorchNormalDataset(10)
dataloader = DataLoader(dataset, batch_size=32)

View File

@ -4,6 +4,7 @@ import datetime
from pathlib import Path
import logging
import re
import pytest
from fastNLP.envs.env import FASTNLP_LAUNCH_TIME
from fastNLP.core import rank_zero_rm
@ -12,6 +13,7 @@ from fastNLP.core.log.logger import logger
from tests.helpers.utils import magic_argv_env_context, recover_logger
@pytest.mark.torch
# 测试 TorchDDPDriver
@magic_argv_env_context
@recover_logger
@ -61,6 +63,7 @@ def test_add_file_ddp_1_torch():
dist.destroy_process_group()
@pytest.mark.torch
@magic_argv_env_context
@recover_logger
def test_add_file_ddp_2_torch():
@ -111,6 +114,7 @@ def test_add_file_ddp_2_torch():
dist.destroy_process_group()
@pytest.mark.torch
@magic_argv_env_context
@recover_logger
def test_add_file_ddp_3_torch():
@ -159,6 +163,8 @@ def test_add_file_ddp_3_torch():
dist.barrier()
dist.destroy_process_group()
@pytest.mark.torch
@magic_argv_env_context
@recover_logger
def test_add_file_ddp_4_torch():
@ -208,6 +214,7 @@ def test_add_file_ddp_4_torch():
dist.destroy_process_group()
@pytest.mark.torch
class TestLogger:
msg = 'some test log msg'

View File

@ -1,4 +1,5 @@
import os
import pytest
from fastNLP.envs.distributed import rank_zero_call, all_rank_call_context
from tests.helpers.utils import re_run_current_cmd_for_torch, Capturing, magic_argv_env_context
@ -30,7 +31,7 @@ class JittorTest:
def test_all_rank_run(self):
pass
@pytest.mark.torch
class TestTorch:
@magic_argv_env_context
def test_rank_zero_call(self):

View File

@ -1,5 +1,5 @@
import unittest
import pytest
import paddle
from fastNLP.core.utils.paddle_utils import paddle_to, paddle_move_data_to_device
@ -11,6 +11,7 @@ from fastNLP.core.utils.paddle_utils import paddle_to, paddle_move_data_to_devic
#
############################################################################
@pytest.mark.paddle
class PaddleToDeviceTestCase(unittest.TestCase):
def test_case(self):
tensor = paddle.rand((4, 5))

View File

@ -1,6 +1,7 @@
import unittest
import paddle
import pytest
import torch
from fastNLP.core.utils.torch_paddle_utils import torch_paddle_move_data_to_device
@ -11,6 +12,8 @@ from fastNLP.core.utils.torch_paddle_utils import torch_paddle_move_data_to_devi
#
############################################################################
# @pytest.mark.paddle
# @pytest.mark.torch
class TorchPaddleMoveDataToDeviceTestCase(unittest.TestCase):
def check_gpu(self, tensor, idx):