2020-12-15 17:59:13 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2020-04-02 16:28:44 +00:00
|
|
|
import os
|
|
|
|
|
2020-04-22 00:33:10 +00:00
|
|
|
import numpy as np
|
2021-02-11 12:04:57 +00:00
|
|
|
import torch
|
|
|
|
|
|
|
|
from pytorch_lightning.utilities import _TORCH_LOWER_EQUAL_1_4, _TORCH_QUANTIZE_AVAILABLE
|
2020-04-22 00:33:10 +00:00
|
|
|
|
2020-12-23 23:11:42 +00:00
|
|
|
_TEST_ROOT = os.path.dirname(__file__)
|
|
|
|
_PROJECT_ROOT = os.path.dirname(_TEST_ROOT)
|
|
|
|
_TEMP_PATH = os.path.join(_PROJECT_ROOT, 'test_temp')
|
2021-01-08 15:36:49 +00:00
|
|
|
DATASETS_PATH = os.path.join(_PROJECT_ROOT, 'Datasets')
|
|
|
|
LEGACY_PATH = os.path.join(_PROJECT_ROOT, 'legacy')
|
2020-12-02 10:00:05 +00:00
|
|
|
|
2020-12-07 09:31:33 +00:00
|
|
|
# todo: this setting `PYTHONPATH` may not be used by other evns like Conda for import packages
|
2020-12-23 23:11:42 +00:00
|
|
|
if _PROJECT_ROOT not in os.getenv('PYTHONPATH', ""):
|
2020-12-07 09:31:33 +00:00
|
|
|
splitter = ":" if os.environ.get("PYTHONPATH", "") else ""
|
2020-12-23 23:11:42 +00:00
|
|
|
os.environ['PYTHONPATH'] = f'{_PROJECT_ROOT}{splitter}{os.environ.get("PYTHONPATH", "")}'
|
2020-04-22 00:33:10 +00:00
|
|
|
|
|
|
|
# generate a list of random seeds for each test
|
|
|
|
RANDOM_PORTS = list(np.random.randint(12000, 19000, 1000))
|
|
|
|
|
2020-12-23 23:11:42 +00:00
|
|
|
if not os.path.isdir(_TEMP_PATH):
|
|
|
|
os.mkdir(_TEMP_PATH)
|
2021-02-11 12:04:57 +00:00
|
|
|
|
|
|
|
_SKIPIF_ARGS_PT_LE_1_4 = dict(condition=_TORCH_LOWER_EQUAL_1_4, reason="test pytorch > 1.4")
|
|
|
|
_SKIPIF_ARGS_NO_GPU = dict(condition=not torch.cuda.is_available(), reason="test requires single-GPU machine")
|
|
|
|
_SKIPIF_ARGS_NO_GPUS = dict(condition=torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
|
|
|
|
_SKIPIF_ARGS_NO_PT_QUANT = dict(
|
|
|
|
condition=not _TORCH_QUANTIZE_AVAILABLE, reason="PyTorch quantization is needed for this test"
|
|
|
|
)
|