| @@ -70,6 +70,7 @@ def model_and_optimizers(request): | |||||
| return trainer_params | 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("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("version", [0, 1]) | ||||
| @pytest.mark.parametrize("only_state_dict", [True, False]) | @pytest.mark.parametrize("only_state_dict", [True, False]) | ||||
| @@ -201,6 +202,7 @@ def test_model_checkpoint_callback_1( | |||||
| dist.destroy_process_group() | 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("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]) | @pytest.mark.parametrize("only_state_dict", [True]) | ||||
| @magic_argv_env_context(timeout=100) | @magic_argv_env_context(timeout=100) | ||||
| @@ -293,6 +295,7 @@ def test_model_checkpoint_callback_2( | |||||
| dist.destroy_process_group() | 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("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("version", [0, 1]) | ||||
| @pytest.mark.parametrize("only_state_dict", [True, False]) | @pytest.mark.parametrize("only_state_dict", [True, False]) | ||||
| @@ -423,7 +426,7 @@ def test_trainer_checkpoint_callback_1( | |||||
| dist.destroy_process_group() | dist.destroy_process_group() | ||||
| @pytest.mark.torch | |||||
| # 通过自己编写 model_save_fn 和 model_load_fn 来测试 huggingface 的 transformers 的模型的保存和加载; | # 通过自己编写 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("driver,device", [("torch_ddp", [6, 7]), ("torch", 7)]) # ("torch", "cpu"), ("torch_ddp", [0, 1]), ("torch", 1) | ||||
| @pytest.mark.parametrize("version", [0, 1]) | @pytest.mark.parametrize("version", [0, 1]) | ||||
| @@ -70,8 +70,8 @@ def model_and_optimizers(request): | |||||
| return trainer_params | 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("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("save_folder", ['save_models', None]) | ||||
| @pytest.mark.parametrize("only_state_dict", [True, False]) | @pytest.mark.parametrize("only_state_dict", [True, False]) | ||||
| @@ -95,6 +95,7 @@ def model_and_optimizers(request): | |||||
| return trainer_params | 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("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("version", [0, 1]) | ||||
| @pytest.mark.parametrize("only_state_dict", [True, False]) | @pytest.mark.parametrize("only_state_dict", [True, False]) | ||||
| @@ -179,6 +180,7 @@ def test_model_more_evaluate_callback_1( | |||||
| dist.destroy_process_group() | 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("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("version", [0, 1]) | ||||
| @pytest.mark.parametrize("only_state_dict", [True, False]) | @pytest.mark.parametrize("only_state_dict", [True, False]) | ||||
| @@ -25,6 +25,7 @@ class CheckClipCallback(Callback): | |||||
| assert np.linalg.norm(param.grad.cpu().view(-1).numpy())<=self.clip_value | 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('accumulation_steps', [1, 3, 5]) | ||||
| @pytest.mark.parametrize('fp16', [True, False]) | @pytest.mark.parametrize('fp16', [True, False]) | ||||
| @pytest.mark.parametrize('clip_type', ['norm', 'value']) | @pytest.mark.parametrize('clip_type', ['norm', 'value']) | ||||
| @@ -15,6 +15,7 @@ class RecordLrCallback(Callback): | |||||
| self.lrs.append(trainer.driver.optimizers[0].param_groups[0]['lr']) | self.lrs.append(trainer.driver.optimizers[0].param_groups[0]['lr']) | ||||
| @pytest.mark.torch | |||||
| @pytest.mark.parametrize('warmup', [5, 0.1]) | @pytest.mark.parametrize('warmup', [5, 0.1]) | ||||
| @pytest.mark.parametrize('schedule', ['constant', 'linear']) | @pytest.mark.parametrize('schedule', ['constant', 'linear']) | ||||
| @pytest.mark.parametrize('accumulation_steps', [1, 3, 4]) | @pytest.mark.parametrize('accumulation_steps', [1, 3, 4]) | ||||
| @@ -72,6 +72,7 @@ def dataloader_with_randomsampler(dataset, batch_size, shuffle, drop_last, seed= | |||||
| # | # | ||||
| ############################################################################ | ############################################################################ | ||||
| @pytest.mark.torch | |||||
| class TestDDPDriverFunction: | class TestDDPDriverFunction: | ||||
| """ | """ | ||||
| 测试 TorchDDPDriver 一些简单函数的测试类,基本都是测试能否运行、是否存在 import 错误等问题 | 测试 TorchDDPDriver 一些简单函数的测试类,基本都是测试能否运行、是否存在 import 错误等问题 | ||||
| @@ -180,6 +181,7 @@ class TestDDPDriverFunction: | |||||
| # | # | ||||
| ############################################################################ | ############################################################################ | ||||
| @pytest.mark.torch | |||||
| class TestSetDistReproDataloader: | class TestSetDistReproDataloader: | ||||
| @classmethod | @classmethod | ||||
| @@ -526,6 +528,7 @@ class TestSetDistReproDataloader: | |||||
| # 测试 save 和 load 相关的功能 | # 测试 save 和 load 相关的功能 | ||||
| # | # | ||||
| ############################################################################ | ############################################################################ | ||||
| @pytest.mark.torch | |||||
| class TestSaveLoad: | class TestSaveLoad: | ||||
| """ | """ | ||||
| 测试多卡情况下 save 和 load 相关函数的表现 | 测试多卡情况下 save 和 load 相关函数的表现 | ||||
| @@ -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 | from tests.helpers.utils import re_run_current_cmd_for_torch, magic_argv_env_context | ||||
| @pytest.mark.torch | |||||
| @magic_argv_env_context | @magic_argv_env_context | ||||
| def test_fastnlp_torch_all_gather(): | def test_fastnlp_torch_all_gather(): | ||||
| os.environ['MASTER_ADDR'] = '127.0.0.1' | os.environ['MASTER_ADDR'] = '127.0.0.1' | ||||
| @@ -59,6 +60,7 @@ def test_fastnlp_torch_all_gather(): | |||||
| dist.destroy_process_group() | dist.destroy_process_group() | ||||
| @pytest.mark.torch | |||||
| @magic_argv_env_context | @magic_argv_env_context | ||||
| def test_fastnlp_torch_broadcast_object(): | def test_fastnlp_torch_broadcast_object(): | ||||
| os.environ['MASTER_ADDR'] = '127.0.0.1' | os.environ['MASTER_ADDR'] = '127.0.0.1' | ||||
| @@ -8,12 +8,16 @@ from tests.helpers.utils import magic_argv_env_context | |||||
| import torch | import torch | ||||
| @pytest.mark.torch | |||||
| def test_incorrect_driver(): | def test_incorrect_driver(): | ||||
| model = TorchNormalModel_Classification_1(2, 100) | model = TorchNormalModel_Classification_1(2, 100) | ||||
| with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
| driver = initialize_torch_driver("paddle", 0, model) | driver = initialize_torch_driver("paddle", 0, model) | ||||
| @pytest.mark.torch | |||||
| @pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
| "device", | "device", | ||||
| ["cpu", "cuda:0", 0, torch.device("cuda:0")] | ["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) | driver = initialize_torch_driver(driver, device, model) | ||||
| assert isinstance(driver, TorchSingleDriver) | assert isinstance(driver, TorchSingleDriver) | ||||
| @pytest.mark.torch | |||||
| @pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
| "device", | "device", | ||||
| [0, 1] | [0, 1] | ||||
| @@ -50,6 +56,8 @@ def test_get_ddp_2(driver, device): | |||||
| assert isinstance(driver, TorchDDPDriver) | assert isinstance(driver, TorchDDPDriver) | ||||
| @pytest.mark.torch | |||||
| @pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
| "device", | "device", | ||||
| [[0, 2, 3], -1] | [[0, 2, 3], -1] | ||||
| @@ -69,6 +77,8 @@ def test_get_ddp(driver, device): | |||||
| assert isinstance(driver, TorchDDPDriver) | assert isinstance(driver, TorchDDPDriver) | ||||
| @pytest.mark.torch | |||||
| @pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
| ("driver", "device"), | ("driver", "device"), | ||||
| [("torch_ddp", "cpu")] | [("torch_ddp", "cpu")] | ||||
| @@ -82,6 +92,8 @@ def test_get_ddp_cpu(driver, device): | |||||
| with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
| driver = initialize_torch_driver(driver, device, model) | driver = initialize_torch_driver(driver, device, model) | ||||
| @pytest.mark.torch | |||||
| @pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
| "device", | "device", | ||||
| [-2, [0, torch.cuda.device_count() + 1, 3], [-2], torch.cuda.device_count() + 1] | [-2, [0, torch.cuda.device_count() + 1, 3], [-2], torch.cuda.device_count() + 1] | ||||
| @@ -9,6 +9,8 @@ from torch.utils.data import DataLoader, BatchSampler | |||||
| from tests.helpers.datasets.torch_data import TorchNormalDataset | from tests.helpers.datasets.torch_data import TorchNormalDataset | ||||
| @pytest.mark.torch | |||||
| def test_replace_batch_sampler(): | def test_replace_batch_sampler(): | ||||
| dataset = TorchNormalDataset(10) | dataset = TorchNormalDataset(10) | ||||
| dataloader = DataLoader(dataset, batch_size=32) | dataloader = DataLoader(dataset, batch_size=32) | ||||
| @@ -22,6 +24,8 @@ def test_replace_batch_sampler(): | |||||
| assert len(replaced_loader.dataset) == len(dataset) | assert len(replaced_loader.dataset) == len(dataset) | ||||
| assert replaced_loader.batch_sampler.batch_size == 16 | assert replaced_loader.batch_sampler.batch_size == 16 | ||||
| @pytest.mark.torch | |||||
| def test_replace_sampler(): | def test_replace_sampler(): | ||||
| dataset = TorchNormalDataset(10) | dataset = TorchNormalDataset(10) | ||||
| dataloader = DataLoader(dataset, batch_size=32) | dataloader = DataLoader(dataset, batch_size=32) | ||||
| @@ -4,6 +4,7 @@ import datetime | |||||
| from pathlib import Path | from pathlib import Path | ||||
| import logging | import logging | ||||
| import re | import re | ||||
| import pytest | |||||
| from fastNLP.envs.env import FASTNLP_LAUNCH_TIME | from fastNLP.envs.env import FASTNLP_LAUNCH_TIME | ||||
| from fastNLP.core import rank_zero_rm | 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 | from tests.helpers.utils import magic_argv_env_context, recover_logger | ||||
| @pytest.mark.torch | |||||
| # 测试 TorchDDPDriver; | # 测试 TorchDDPDriver; | ||||
| @magic_argv_env_context | @magic_argv_env_context | ||||
| @recover_logger | @recover_logger | ||||
| @@ -61,6 +63,7 @@ def test_add_file_ddp_1_torch(): | |||||
| dist.destroy_process_group() | dist.destroy_process_group() | ||||
| @pytest.mark.torch | |||||
| @magic_argv_env_context | @magic_argv_env_context | ||||
| @recover_logger | @recover_logger | ||||
| def test_add_file_ddp_2_torch(): | def test_add_file_ddp_2_torch(): | ||||
| @@ -111,6 +114,7 @@ def test_add_file_ddp_2_torch(): | |||||
| dist.destroy_process_group() | dist.destroy_process_group() | ||||
| @pytest.mark.torch | |||||
| @magic_argv_env_context | @magic_argv_env_context | ||||
| @recover_logger | @recover_logger | ||||
| def test_add_file_ddp_3_torch(): | def test_add_file_ddp_3_torch(): | ||||
| @@ -159,6 +163,8 @@ def test_add_file_ddp_3_torch(): | |||||
| dist.barrier() | dist.barrier() | ||||
| dist.destroy_process_group() | dist.destroy_process_group() | ||||
| @pytest.mark.torch | |||||
| @magic_argv_env_context | @magic_argv_env_context | ||||
| @recover_logger | @recover_logger | ||||
| def test_add_file_ddp_4_torch(): | def test_add_file_ddp_4_torch(): | ||||
| @@ -208,6 +214,7 @@ def test_add_file_ddp_4_torch(): | |||||
| dist.destroy_process_group() | dist.destroy_process_group() | ||||
| @pytest.mark.torch | |||||
| class TestLogger: | class TestLogger: | ||||
| msg = 'some test log msg' | msg = 'some test log msg' | ||||
| @@ -1,4 +1,5 @@ | |||||
| import os | import os | ||||
| import pytest | |||||
| from fastNLP.envs.distributed import rank_zero_call, all_rank_call_context | 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 | 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): | def test_all_rank_run(self): | ||||
| pass | pass | ||||
| @pytest.mark.torch | |||||
| class TestTorch: | class TestTorch: | ||||
| @magic_argv_env_context | @magic_argv_env_context | ||||
| def test_rank_zero_call(self): | def test_rank_zero_call(self): | ||||
| @@ -1,5 +1,5 @@ | |||||
| import unittest | import unittest | ||||
| import pytest | |||||
| import paddle | import paddle | ||||
| from fastNLP.core.utils.paddle_utils import paddle_to, paddle_move_data_to_device | 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): | class PaddleToDeviceTestCase(unittest.TestCase): | ||||
| def test_case(self): | def test_case(self): | ||||
| tensor = paddle.rand((4, 5)) | tensor = paddle.rand((4, 5)) | ||||
| @@ -1,6 +1,7 @@ | |||||
| import unittest | import unittest | ||||
| import paddle | import paddle | ||||
| import pytest | |||||
| import torch | import torch | ||||
| from fastNLP.core.utils.torch_paddle_utils import torch_paddle_move_data_to_device | 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): | class TorchPaddleMoveDataToDeviceTestCase(unittest.TestCase): | ||||
| def check_gpu(self, tensor, idx): | def check_gpu(self, tensor, idx): | ||||