|
@@ -1,8 +1,6 @@ |
|
|
import os |
|
|
|
|
|
import pytest |
|
|
import pytest |
|
|
|
|
|
|
|
|
from fastNLP.core.drivers.paddle_driver.utils import ( |
|
|
from fastNLP.core.drivers.paddle_driver.utils import ( |
|
|
get_device_from_visible, |
|
|
|
|
|
replace_batch_sampler, |
|
|
replace_batch_sampler, |
|
|
replace_sampler, |
|
|
replace_sampler, |
|
|
) |
|
|
) |
|
@@ -14,24 +12,6 @@ if _NEED_IMPORT_PADDLE: |
|
|
|
|
|
|
|
|
from tests.helpers.datasets.paddle_data import PaddleNormalDataset |
|
|
from tests.helpers.datasets.paddle_data import PaddleNormalDataset |
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
|
|
("user_visible_devices, cuda_visible_devices, device, output_type, correct"), |
|
|
|
|
|
( |
|
|
|
|
|
("0,1,2,3,4,5,6,7", "0", "cpu", str, "cpu"), |
|
|
|
|
|
("0,1,2,3,4,5,6,7", "0", "cpu", int, "cpu"), |
|
|
|
|
|
("0,1,2,3,4,5,6,7", "3,4,5", "gpu:4", int, 1), |
|
|
|
|
|
("0,1,2,3,4,5,6,7", "3,4,5", "gpu:5", str, "gpu:2"), |
|
|
|
|
|
("3,4,5,6", "3,5", 0, int, 0), |
|
|
|
|
|
("3,6,7,8", "6,7,8", "gpu:2", str, "gpu:1"), |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
@pytest.mark.paddle |
|
|
|
|
|
def test_get_device_from_visible_str(user_visible_devices, cuda_visible_devices, device, output_type, correct): |
|
|
|
|
|
os.environ["CUDA_VISIBLE_DEVICES"] = cuda_visible_devices |
|
|
|
|
|
os.environ["USER_CUDA_VISIBLE_DEVICES"] = user_visible_devices |
|
|
|
|
|
res = get_device_from_visible(device, output_type) |
|
|
|
|
|
assert res == correct |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.paddle |
|
|
@pytest.mark.paddle |
|
|
def test_replace_batch_sampler(): |
|
|
def test_replace_batch_sampler(): |
|
|
dataset = PaddleNormalDataset(10) |
|
|
dataset = PaddleNormalDataset(10) |
|
|