Skip to content

Commit

Permalink
Add marks nightly and weakly for torch tests (#2092)
Browse files Browse the repository at this point in the history
### Changes

- Add marks `nightly` and `weakly` for tests.
- Mark sanity tests as `nightly`
- Split `test_functions.TestParametrized` to fast for precommit and long
for nightly
- Time of torch precommit reduced from 60 to 40 mins
- Set `xfail` for sanity tests with `--mode train` in case of segment
fault.
Sporadic segment fault reproduced on torch>=2.0.0 on call `backward`
function.

### Related tickets

119128
  • Loading branch information
AlexanderDokuchaev authored Sep 11, 2023
1 parent 05ae916 commit 2c4d290
Show file tree
Hide file tree
Showing 6 changed files with 475 additions and 436 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ ifdef DATA
DATA_ARG := --data $(DATA)
endif

ifdef WEEKLY_MODELS
WEEKLY_MODELS_ARG := --weekly-models $(WEEKLY_MODELS)
endif

install-pre-commit:
pip install pre-commit==3.2.2

Expand Down Expand Up @@ -124,7 +128,13 @@ install-torch-dev: install-torch-test install-pre-commit install-pylint
pip install -r examples/post_training_quantization/torch/ssd300_vgg16/requirements.txt

test-torch:
pytest ${COVERAGE_ARGS} tests/common tests/torch --junitxml ${JUNITXML_PATH} $(DATA_ARG)
pytest ${COVERAGE_ARGS} tests/common tests/torch -m "not weekly and not nightly" --junitxml ${JUNITXML_PATH} $(DATA_ARG)

test-torch-nightly:
pytest ${COVERAGE_ARGS} tests/torch -m nightly --junitxml ${JUNITXML_PATH} $(DATA_ARG)

test-torch-weekly:
pytest ${COVERAGE_ARGS} tests/torch -m weekly --junitxml ${JUNITXML_PATH} $(DATA_ARG) ${WEEKLY_MODELS_ARG}

COMMON_PYFILES := $(shell python3 tools/collect_pylint_input_files_for_backend.py common)
pylint-torch:
Expand Down
1 change: 1 addition & 0 deletions tests/torch/nas/test_sanity_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def fixture_nas_desc(request, dataset_dir):
return desc.finalize(dataset_dir)


@pytest.mark.nightly
def test_e2e_supernet_training(nas_desc: NASSampleTestDescriptor, tmp_path, mocker):
validator = nas_desc.get_validator()
args = validator.get_default_args(tmp_path)
Expand Down
2 changes: 2 additions & 0 deletions tests/torch/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ markers =
convert
train
install
nightly
weekly
python_files = test_*
xfail_strict = true
36 changes: 23 additions & 13 deletions tests/torch/quantization/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ def skip_if_half_on_cpu(is_fp16, use_cuda):
def check_quant_moved(test_input, test_val, ref_val, quant_len, input_low, input_range, is_fp16, rtol, atol=1e-10):
"""
Checks values in `test_val` are inside of closest quant and
values in `test_val` and `ref_val` elementwise eather equal with given rtol/atol or
values in `test_val` and `ref_val` elementwise either equal with given rtol/atol or
values differ by correspondent `quant_len` +- rtol.
:param test_input: Input of a quantizer.
:param test_val: Given test value.
:param ref_val: Given reference value.
:param quant_len: Lenghts of quants in quantizers
:param quant_len: Length of quants in quantizers
(for each channel in case per channel quantization).
:param atol: Absolute tollerance.
:param rtol: Relative tollerance.
:param atol: Absolute tolerance.
:param rtol: Relative tolerance.
"""

def to_tensor(a):
Expand Down Expand Up @@ -214,15 +214,10 @@ def check_outputs_for_quantization_functions(test_val: torch.Tensor, ref_val: np
PTTensorListComparator.check_equal(test_val, ref_val, rtol, atol)


@pytest.mark.parametrize(
"input_size",
[[1, 48, 112, 112], [1, 96, 28, 28], [1, 288, 14, 14], [16, 96, 112, 112], [16, 192, 28, 28], [16, 576, 14, 14]],
ids=idfn,
)
@pytest.mark.parametrize("bits", (8, 4), ids=("8bit", "4bit"))
@pytest.mark.parametrize("scale_mode", ["single_scale", "per_channel_scale"])
@pytest.mark.parametrize("is_fp16", (True, False), ids=("fp16", "fp32"))
class TestParametrized:
class BaseParametrized:
class TestSymmetric:
@staticmethod
def generate_scale(input_size, scale_mode, is_weights, is_fp16, fixed=None):
Expand Down Expand Up @@ -523,12 +518,12 @@ def test_quantize_asymmetric_backward(self, _seed, input_size, bits, use_cuda, i
if is_fp16:
# This is needed to make scale == 1 to prevent
# quant movement on forward pass in FP16 precision.
# In case scale != 1., not precice scale multiplication in FP16
# In case scale != 1., not precise scale multiplication in FP16
# could lead to big deviations, so even if an input point
# lies in safe range (far from middles of quants) after a scaling
# it could end up in the middle of a quant. It happens mostly
# when target quant > 150 because in real life scenarious quantization range
# usualy less than 2 ** quantization bits,
# when target quant > 150 because in real life scenarios quantization range
# usually less than 2 ** quantization bits,
# so input is small and scale is big, small FP16 input multiplies big fp16 scale,
# deviation is significant.
fixed = {}
Expand Down Expand Up @@ -589,6 +584,21 @@ def test_quantize_asymmetric_backward(self, _seed, input_size, bits, use_cuda, i
check_outputs_for_quantization_functions(test_grads, ref_grads, rtol=1e-2 if is_fp16 else 1e-3)


@pytest.mark.parametrize("input_size", [[1, 16, 64, 64], [4, 16, 16, 16]], ids=idfn)
class TestParametrizedFast(BaseParametrized):
pass


@pytest.mark.nightly
@pytest.mark.parametrize(
"input_size",
[[1, 48, 112, 112], [1, 96, 28, 28], [1, 288, 14, 14], [16, 96, 112, 112], [16, 192, 28, 28], [16, 576, 14, 14]],
ids=idfn,
)
class TestParametrizedLong(BaseParametrized):
pass


@pytest.mark.parametrize("device", ["cuda", "cpu"])
def test_mapping_to_zero(quantization_mode, device):
torch.manual_seed(42)
Expand Down
2 changes: 2 additions & 0 deletions tests/torch/quantization/test_sanity_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def fixture_precision_desc(request, dataset_dir):
return desc.finalize(dataset_dir)


@pytest.mark.nightly
def test_precision_init(precision_desc: PrecisionTestCaseDescriptor, tmp_path, mocker):
validator = precision_desc.get_validator()
args = validator.get_default_args(tmp_path)
Expand Down Expand Up @@ -351,6 +352,7 @@ def fixture_export_desc(request):
return desc.finalize()


@pytest.mark.nightly
@pytest.mark.parametrize(
("extra_args", "is_export_called"),
(({}, False), ({"-m": ["export", "train"]}, True)),
Expand Down
Loading

0 comments on commit 2c4d290

Please sign in to comment.