Skip to content

Commit ab7c947

Browse files
authored
simplify CI horovod (#4951)
* simplify CI horovod * reorder
1 parent b00991e commit ab7c947

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

tests/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
PROJECT_ROOT = os.path.dirname(TEST_ROOT)
77
TEMP_PATH = os.path.join(PROJECT_ROOT, 'test_temp')
88

9+
# todo: this setting `PYTHONPATH` may not be used by other evns like Conda for import packages
910
if PROJECT_ROOT not in os.getenv('PYTHONPATH', ""):
10-
os.environ['PYTHONPATH'] = f'{PROJECT_ROOT}:{os.environ.get("PYTHONPATH", "")}'
11+
splitter = ":" if os.environ.get("PYTHONPATH", "") else ""
12+
os.environ['PYTHONPATH'] = f'{PROJECT_ROOT}{splitter}{os.environ.get("PYTHONPATH", "")}'
1113

1214
# generate a list of random seeds for each test
1315
RANDOM_PORTS = list(np.random.randint(12000, 19000, 1000))

tests/models/data/horovod/train_default_model.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@
2121
import os
2222
import sys
2323

24-
PATH_HERE = os.path.abspath(os.path.dirname(__file__))
25-
PATH_ROOT = os.path.abspath(os.path.join(PATH_HERE, '..', '..', '..', '..'))
26-
sys.path.insert(0, os.path.abspath(PATH_ROOT))
24+
# this is need as e.g. Conda do not uses `PYTHONPATH` env var as pip or/and virtualenv
25+
sys.path = os.getenv('PYTHONPATH').split(':') + sys.path
2726

2827
from pytorch_lightning import Trainer # noqa: E402
2928
from pytorch_lightning.callbacks import ModelCheckpoint # noqa: E402
@@ -34,11 +33,6 @@
3433
else:
3534
print('You requested to import Horovod which is missing or not supported for your OS.')
3635

37-
38-
# Move project root to the front of the search path, as some imports may have reordered things
39-
idx = sys.path.index(PATH_ROOT)
40-
sys.path[0], sys.path[idx] = sys.path[idx], sys.path[0]
41-
4236
from tests.base import EvalModelTemplate # noqa: E402
4337
from tests.base.develop_pipelines import run_prediction # noqa: E402
4438
from tests.base.develop_utils import set_random_master_port, reset_seed # noqa: E402

0 commit comments

Comments
 (0)