-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
test_windows.py
55 lines (40 loc) · 1.43 KB
/
test_windows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""This is a very minimal set of windows tests for Train/Tune."""
import os
import pytest
import ray
from ray import train, tune
from ray.train.data_parallel_trainer import DataParallelTrainer
from ray.train.tests.util import create_dict_checkpoint
@pytest.fixture
def ray_start_4_cpus():
address_info = ray.init(num_cpus=4)
yield address_info
# The code after the yield will run as teardown code.
ray.shutdown()
@pytest.fixture
def chdir_tmpdir(tmp_path):
original_path = os.getcwd()
os.chdir(tmp_path)
yield
os.chdir(original_path)
def test_storage_path(ray_start_4_cpus, chdir_tmpdir):
"""Tests that Train/Tune with a local storage path works on Windows."""
def train_fn(config):
for i in range(5):
if train.get_context().get_world_rank() == 0:
with create_dict_checkpoint({"dummy": "data"}) as checkpoint:
train.report({"loss": i}, checkpoint=checkpoint)
else:
train.report({"loss": i})
tuner = tune.Tuner(train_fn, run_config=train.RunConfig(storage_path=os.getcwd()))
results = tuner.fit()
assert not results.errors
trainer = DataParallelTrainer(
train_fn,
scaling_config=train.ScalingConfig(num_workers=2),
run_config=train.RunConfig(storage_path=os.getcwd()),
)
trainer.fit()
if __name__ == "__main__":
import sys
sys.exit(pytest.main(["-v", "-x", __file__]))