Skip to content

Commit 9ea721c

Browse files
authored
Fix typo and mark some slow tests (aws#265)
* Fix typo and mark some slow tests * Fix flaky tests
1 parent 713f610 commit 9ea721c

17 files changed

+38
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ log
115115
cm.json
116116
cm.ts
117117
collections.json
118+
worker*.json
118119

119120
# Wheel and tar files from running `python bin/build_containers.py`
120121
*.whl

tests/analysis/rules/test_confusion.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from tornasole.core.writer import FileWriter
22
from tornasole.core.collection_manager import CollectionManager
3-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
3+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
44

55
from tornasole.rules.generic import Confusion
66
from tornasole.trials import create_trial
7+
import pytest
78
import os
89

910
import uuid
@@ -22,9 +23,10 @@ def gen_y_and_y_hat( path, trial, step, y, y_name, y_hat, y_hat_name, colls={}):
2223
for coll in colls:
2324
c.add(coll)
2425
c.get(coll).tensor_names = colls[coll]
25-
c.export(os.path.join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
26+
c.export(os.path.join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
2627

2728

29+
@pytest.mark.slow # 0:06 to run
2830
def test_confusion():
2931
base_path = 'ts_output1/rule_invoker/'
3032
path = base_path

tests/analysis/rules/test_invoker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from tornasole.trials import create_trial
55
import uuid
66
import numpy as np
7+
import pytest
78
from tornasole.exceptions import *
89
from tornasole.rules.rule_invoker import invoke_rule
910

@@ -62,6 +63,7 @@ def test_invoker_rule_pass_kwargs():
6263
assert rcode == 0
6364
shutil.rmtree(path)
6465

66+
@pytest.mark.slow # 0:04 to run
6567
def test_invoker_rule_pass_other_trials():
6668
path1 = dump_data()
6769
path2 = dump_data()

tests/analysis/trials/test_modes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from datetime import datetime
77
from tornasole.core.writer import FileWriter
88
from tornasole.core.collection_manager import CollectionManager
9-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
9+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
1010

1111

1212
def test_modes_on_global_data():
@@ -20,7 +20,7 @@ def test_mode_data():
2020
c = CollectionManager()
2121
c.add("default")
2222
c.get("default").tensor_names = ["arr"]
23-
c.export(os.path.join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
23+
c.export(os.path.join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
2424
tr = create_trial(trial_dir)
2525
for s in range(0, 10):
2626
fw = FileWriter(trial_dir=trial_dir, step=s)

tests/analysis/trials/test_s3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from tornasole.trials import S3Trial
22
from tornasole.core.collection_manager import CollectionManager
3-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
3+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
44
import uuid
55
import os
66
import pytest
@@ -33,8 +33,8 @@ def help_test_multiple_trials(num_steps = 20, num_tensors = 10):
3333
c = CollectionManager()
3434
c.add("default")
3535
c.get("default").tensor_names = ["foo_" + str(i) for i in range(num_tensors)]
36-
c.export(path + trial_name + "/" + TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
37-
c.export(path + trial_name + "/" + TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
36+
c.export(path + trial_name + "/" + TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
37+
c.export(path + trial_name + "/" + TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
3838
for i in range(num_steps):
3939
generate_data(path=path, trial=trial_name, num_tensors=num_tensors,
4040
step=i, tname_prefix='foo', worker='algo-1', shape=(3, 3, 3), rank=0)

tests/analysis/trials/test_trial_modes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_local_index_mode():
2222
assert bool(trial_obj.index_tensors_dict) is True
2323

2424

25+
@pytest.mark.slow # 0:03 to run
2526
def test_local_event_mode():
2627
trial_name = str(uuid.uuid4())
2728
path = 'ts_output/train/'

tests/analysis/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from tornasole.core.writer import FileWriter
22
import numpy as np
33
from tornasole.core.collection_manager import CollectionManager
4-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
4+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
55
import os
66
import aioboto3
77
import asyncio
@@ -25,7 +25,7 @@ def generate_data(path, trial, step, tname_prefix,
2525
c.get("default").tensor_names = [f'{tname_prefix}_{i}' for i in range(num_tensors)]
2626
c.add('gradients')
2727
c.get("gradients").tensor_names = [f'{tname_prefix}_{i}' for i in range(num_tensors)]
28-
c.export(os.path.join(path, trial, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
28+
c.export(os.path.join(path, trial, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
2929

3030

3131
def check_trial(trial_obj, num_steps, num_tensors):

tests/core/test_collections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from tornasole.core.collection import Collection
22
from tornasole.core.collection_manager import CollectionManager
3-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
3+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
44
from tornasole.core.reduction_config import ReductionConfig
55
from tornasole.core.save_config import SaveConfig, SaveConfigMode
66
from tornasole.core.modes import ModeKeys
@@ -42,8 +42,8 @@ def test_manager_export_load():
4242
cm.add(Collection('trial1'))
4343
cm.add('trial2')
4444
cm.get('trial2').include('total_loss')
45-
cm.export(TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
46-
cm2 = CollectionManager.load(TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
45+
cm.export(TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
46+
cm2 = CollectionManager.load(TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME)
4747
assert cm == cm2
4848

4949
def test_manager():

tests/mxnet/test_hook.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def test_hook_from_json_config_full():
4141

4242
def test_default_hook():
4343
reset_collections()
44+
shutil.rmtree('/opt/ml/output/tensors', ignore_errors=True)
4445
if TORNASOLE_CONFIG_FILE_PATH_ENV_STR in os.environ:
4546
del os.environ[TORNASOLE_CONFIG_FILE_PATH_ENV_STR]
4647
hook = t_hook.hook_from_config()

tests/tensorflow/hooks/test_dist_horovod.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from tornasole.trials import create_trial
2+
import pytest
23

3-
4+
@pytest.mark.slow # 0:11 to run
45
def test_s3_read():
56
path = "s3://tornasole-testing/dist-logs-10/"
67
trial = create_trial(path)

tests/tensorflow/hooks/test_save_all_full.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import shutil, glob
44
from tornasole.core.reader import FileReader
55
from tornasole.core.json_config import TORNASOLE_CONFIG_FILE_PATH_ENV_STR
6-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
6+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
77

88

99
def test_save_all_full(hook=None, trial_dir=None):
@@ -29,8 +29,8 @@ def test_save_all_full(hook=None, trial_dir=None):
2929
assert len(coll['gradients'].tensor_names) == 1
3030
assert len(coll['losses'].tensor_names) == 1
3131

32-
assert TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME in files
33-
cm = CollectionManager.load(join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
32+
assert TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME in files
33+
cm = CollectionManager.load(join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
3434

3535
assert len(cm.collections) == 6
3636
assert len(cm.collections['weights'].tensor_names) == 1

tests/tensorflow/hooks/test_save_reductions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import glob
55
from tornasole.core.reader import FileReader
66
from tornasole.core.json_config import TORNASOLE_CONFIG_FILE_PATH_ENV_STR
7-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
7+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
88

99
def helper_save_reductions(trial_dir, hook):
1010
simple_model(hook)
@@ -14,8 +14,8 @@ def helper_save_reductions(trial_dir, hook):
1414
assert len(coll['weights'].tensor_names) == 1
1515
assert len(coll['gradients'].tensor_names) == 1
1616

17-
assert TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME in files
18-
cm = CollectionManager.load(join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
17+
assert TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME in files
18+
cm = CollectionManager.load(join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
1919
assert len(cm.collections) == 5
2020
assert len(cm.collections['weights'].tensor_names) == 1
2121
assert len(cm.collections['gradients'].tensor_names) == 1

tests/tensorflow/hooks/test_simple_include.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import glob, shutil
55
from tornasole.core.reader import FileReader
66
from tornasole.core.json_config import TORNASOLE_CONFIG_FILE_PATH_ENV_STR
7-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
7+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
88

99

1010

@@ -14,7 +14,7 @@ def helper_test_simple_include(trial_dir, hook):
1414
_, files = get_dirs_files(trial_dir)
1515
steps, _ = get_dirs_files(os.path.join(trial_dir, 'events'))
1616

17-
cm = CollectionManager.load(join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
17+
cm = CollectionManager.load(join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
1818
assert len(cm.collections['default'].tensor_names) == 1
1919
assert len(steps) == 5
2020
for step in steps:
@@ -58,7 +58,7 @@ def helper_test_simple_include_regex(trial_dir, hook):
5858
_, files = get_dirs_files(trial_dir)
5959
steps, _ = get_dirs_files(os.path.join(trial_dir, 'events'))
6060

61-
cm = CollectionManager.load(join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
61+
cm = CollectionManager.load(join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
6262
assert len(cm.collections['default'].tensor_names) == 1
6363
assert len(steps) == 5
6464

@@ -105,7 +105,7 @@ def helper_test_multi_collection_match(trial_dir, hook):
105105
_, files = get_dirs_files(trial_dir)
106106
steps, _ = get_dirs_files(os.path.join(trial_dir, 'events'))
107107

108-
cm = CollectionManager.load(join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
108+
cm = CollectionManager.load(join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
109109
assert len(cm.collections['default'].tensor_names) == 1
110110
assert len(cm.collections['trial'].tensor_names) == 1
111111
assert len(steps) == 5

tests/tensorflow/hooks/test_weights_gradients.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .utils import *
22
from tornasole.tensorflow import reset_collections
33
import tensorflow.compat.v1 as tf
4-
from tornasole.core.config_constants import TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME
4+
from tornasole.core.config_constants import TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME
55
from tornasole.core.json_config import TORNASOLE_CONFIG_FILE_PATH_ENV_STR
66
import tornasole.tensorflow as ts
77
import shutil
@@ -12,8 +12,8 @@ def helper_test_only_w_g(trial_dir, hook):
1212
steps, _ = get_dirs_files(os.path.join(trial_dir, 'events'))
1313
_, files = get_dirs_files(trial_dir)
1414

15-
assert TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME in files
16-
cm = CollectionManager.load(join(trial_dir, TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
15+
assert TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME in files
16+
cm = CollectionManager.load(join(trial_dir, TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME))
1717
num_tensors_loaded_collection = len(cm.collections['weights'].tensor_names) + \
1818
len(cm.collections['gradients'].tensor_names) + \
1919
len(cm.collections['default'].tensor_names)

tests/xgboost/test_hook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import uuid
33
import numpy as np
44
import pytest
5+
import shutil
56
import xgboost
67

78
from .run_xgboost_model import run_xgboost_model
@@ -49,6 +50,7 @@ def test_hook_from_json_config_full(tmpdir, monkeypatch):
4950

5051
def test_default_hook(monkeypatch):
5152
reset_collections()
53+
shutil.rmtree('/opt/ml/output/tensors', ignore_errors=True)
5254
monkeypatch.delenv(TORNASOLE_CONFIG_FILE_PATH_ENV_STR, raising=False)
5355
hook = TornasoleHook.hook_from_config()
5456
assert hook.out_dir == DEFAULT_SAGEMAKER_TORNASOLE_PATH

tornasole/core/config_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
TORNASOLE_CONFIG_INCLUDE_REGEX_KEY = "include_regex"
1010
TORNASOLE_CONFIG_SAVE_ALL_KEY = "save_all"
1111
DEFAULT_SAGEMAKER_TORNASOLE_PATH = "/opt/ml/output/tensors"
12-
TORASOLE_DEFAULT_COLLECTIONS_FILE_NAME = 'worker_0_collections.json'
12+
TORNASOLE_DEFAULT_COLLECTIONS_FILE_NAME = 'worker_0_collections.json'

tornasole/trials/trial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _wait():
112112
else:
113113
collection_files = list_collection_files_in_directory(self.trial_dir)
114114

115-
time.sleep(2)
115+
# time.sleep(2)
116116
num_times_before_warning -= 1
117117
if num_times_before_warning < 0:
118118
self.logger.warning('Waiting to read collections')

0 commit comments

Comments
 (0)