lightning/tests/deprecated_api/test_remove_1-4.py

187 lines
8.5 KiB
Python
Raw Normal View History

# 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.
"""Test deprecated functionality which will be removed in vX.Y.Z"""
import sys
import pytest
Classification metrics overhaul: stat scores (3/n) (#4839) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Break down error checking for inputs into separate functions * Remove the (N, ..., C) option in MD-MC * Simplify select_topk * Remove detach for inputs * Fix typos * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Update docs/source/metrics.rst Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Minor error message changes * Update pytorch_lightning/metrics/utils.py Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Reuse case from validation in formatting * Refactor code in _input_format_classification * Small improvements * PEP 8 * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Update docs/source/metrics.rst Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Apply suggestions from code review Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Alphabetical reordering of regression metrics * Change default value of top_k and add error checking * Extract basic validation into separate function * Update to new top_k default * Update desciption of parameters in input formatting * Apply suggestions from code review Co-authored-by: Nicki Skafte <skaftenicki@gmail.com> * Check that probabilities in preds sum to 1 (for MC) * Fix coverage * Split accuracy and hamming loss * Remove old redundant accuracy * Minor changes * Fix imports * Improve docstring descriptions * Fix imports * Fix edge case and simplify testing * Fix docs * PEP8 * Reorder imports * Add top_k parameter * Update changelog * Update docstring * Update docstring * Reverse formatting changes for tests * Change parameter order * Remove formatting changes 2/2 * Remove formatting 3/3 * . * Improve description of top_k parameter * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Remove unneeded assert * Update pytorch_lightning/metrics/functional/accuracy.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Remove unneeded assert * Explicit checking of parameter values * Apply suggestions from code review Co-authored-by: Nicki Skafte <skaftenicki@gmail.com> * Apply suggestions from code review * Fix top_k checking * PEP8 * Don't check dist_sync in test * add back check_dist_sync_on_step * Make sure half-precision inputs are transformed (#5013) * Fix typo * Rename hamming loss to hamming distance * Fix tests for half precision * Fix docs underline length * Fix doc undeline length * Replace mdmc_accuracy parameter with subset_accuracy * Update changelog * Fix unwanted accuracy change * Enable top_k for ML prob inputs * Test that default threshold is 0.5 * Fix typo * Update top_k description in helpers * updates * Update styling and add back tests * Remove excess spaces * fix torch.where for old versions * fix linting * Update docstring * Fix docstring * Apply suggestions from code review (mostly docs) * Default threshold to None, accept only (0,1) * Change wrong threshold message * Improve documentation and add tests * Add back ddp tests * Change stat reduce method and default * Remove DDP tests and fix doctests * Fix doctest * Update changelog * Refactoring * Fix typo * Refactor * Increase coverage * Fix linting * Consistent use of backticks * Fix too long line in docs * Apply suggestions from code review * Fix deprecation test * Fix deprecation test * Default threshold back to 0.5 * Minor documentation fixes * Add types to tests Co-authored-by: Teddy Koker <teddy.koker@gmail.com> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> Co-authored-by: Nicki Skafte <skaftenicki@gmail.com> Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
2020-12-30 19:49:50 +00:00
import torch
from pytorch_lightning import Trainer
from pytorch_lightning.overrides.data_parallel import (
LightningDataParallel,
LightningDistributedDataParallel,
LightningParallelModule,
)
from pytorch_lightning.overrides.distributed import LightningDistributedModule
from pytorch_lightning.plugins.legacy.ddp_plugin import DDPPlugin
from tests.deprecated_api import _soft_unimport_module
from tests.helpers import BoringModel
def test_v1_4_0_deprecated_imports():
_soft_unimport_module('pytorch_lightning.utilities.argparse_utils')
with pytest.deprecated_call(match='will be removed in v1.4'):
from pytorch_lightning.utilities.argparse_utils import from_argparse_args # noqa: F811 F401
_soft_unimport_module('pytorch_lightning.utilities.model_utils')
with pytest.deprecated_call(match='will be removed in v1.4'):
from pytorch_lightning.utilities.model_utils import is_overridden # noqa: F811 F401
_soft_unimport_module('pytorch_lightning.utilities.warning_utils')
with pytest.deprecated_call(match='will be removed in v1.4'):
from pytorch_lightning.utilities.warning_utils import WarningCache # noqa: F811 F401
_soft_unimport_module('pytorch_lightning.utilities.xla_device_utils')
with pytest.deprecated_call(match='will be removed in v1.4'):
from pytorch_lightning.utilities.xla_device_utils import XLADeviceUtils # noqa: F811 F401
def test_v1_4_0_deprecated_trainer_device_distrib():
"""Test that Trainer attributes works fine."""
trainer = Trainer()
trainer._distrib_type = None
trainer._device_type = None
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.on_cpu = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.on_cpu
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.on_gpu = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.on_gpu
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.on_tpu = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.on_tpu
trainer._device_type = None
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.use_tpu = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.use_tpu
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.use_dp = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.use_dp
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.use_ddp = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.use_ddp
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.use_ddp2 = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.use_ddp2
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
trainer.use_horovod = True
with pytest.deprecated_call(match='deprecated in v1.2 and will be removed in v1.4'):
assert trainer.use_horovod
Classification metrics overhaul: stat scores (3/n) (#4839) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Break down error checking for inputs into separate functions * Remove the (N, ..., C) option in MD-MC * Simplify select_topk * Remove detach for inputs * Fix typos * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Update docs/source/metrics.rst Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Minor error message changes * Update pytorch_lightning/metrics/utils.py Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Reuse case from validation in formatting * Refactor code in _input_format_classification * Small improvements * PEP 8 * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Update docs/source/metrics.rst Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Update pytorch_lightning/metrics/classification/utils.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Apply suggestions from code review Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Alphabetical reordering of regression metrics * Change default value of top_k and add error checking * Extract basic validation into separate function * Update to new top_k default * Update desciption of parameters in input formatting * Apply suggestions from code review Co-authored-by: Nicki Skafte <skaftenicki@gmail.com> * Check that probabilities in preds sum to 1 (for MC) * Fix coverage * Split accuracy and hamming loss * Remove old redundant accuracy * Minor changes * Fix imports * Improve docstring descriptions * Fix imports * Fix edge case and simplify testing * Fix docs * PEP8 * Reorder imports * Add top_k parameter * Update changelog * Update docstring * Update docstring * Reverse formatting changes for tests * Change parameter order * Remove formatting changes 2/2 * Remove formatting 3/3 * . * Improve description of top_k parameter * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Remove unneeded assert * Update pytorch_lightning/metrics/functional/accuracy.py Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> * Remove unneeded assert * Explicit checking of parameter values * Apply suggestions from code review Co-authored-by: Nicki Skafte <skaftenicki@gmail.com> * Apply suggestions from code review * Fix top_k checking * PEP8 * Don't check dist_sync in test * add back check_dist_sync_on_step * Make sure half-precision inputs are transformed (#5013) * Fix typo * Rename hamming loss to hamming distance * Fix tests for half precision * Fix docs underline length * Fix doc undeline length * Replace mdmc_accuracy parameter with subset_accuracy * Update changelog * Fix unwanted accuracy change * Enable top_k for ML prob inputs * Test that default threshold is 0.5 * Fix typo * Update top_k description in helpers * updates * Update styling and add back tests * Remove excess spaces * fix torch.where for old versions * fix linting * Update docstring * Fix docstring * Apply suggestions from code review (mostly docs) * Default threshold to None, accept only (0,1) * Change wrong threshold message * Improve documentation and add tests * Add back ddp tests * Change stat reduce method and default * Remove DDP tests and fix doctests * Fix doctest * Update changelog * Refactoring * Fix typo * Refactor * Increase coverage * Fix linting * Consistent use of backticks * Fix too long line in docs * Apply suggestions from code review * Fix deprecation test * Fix deprecation test * Default threshold back to 0.5 * Minor documentation fixes * Add types to tests Co-authored-by: Teddy Koker <teddy.koker@gmail.com> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Rohit Gupta <rohitgr1998@gmail.com> Co-authored-by: Nicki Skafte <skaftenicki@gmail.com> Co-authored-by: Justus Schock <12886177+justusschock@users.noreply.github.com>
2020-12-30 19:49:50 +00:00
def test_v1_4_0_deprecated_metrics():
from pytorch_lightning.metrics.functional.classification import stat_scores_multiple_classes
with pytest.deprecated_call(match='will be removed in v1.4'):
stat_scores_multiple_classes(pred=torch.tensor([0, 1]), target=torch.tensor([0, 1]))
from pytorch_lightning.metrics.functional.classification import iou
with pytest.deprecated_call(match='will be removed in v1.4'):
iou(torch.randint(0, 2, (10, 3, 3)), torch.randint(0, 2, (10, 3, 3)))
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
from pytorch_lightning.metrics.functional.classification import recall
with pytest.deprecated_call(match='will be removed in v1.4'):
recall(torch.randint(0, 2, (10, 3, 3)), torch.randint(0, 2, (10, 3, 3)))
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
from pytorch_lightning.metrics.functional.classification import precision
with pytest.deprecated_call(match='will be removed in v1.4'):
precision(torch.randint(0, 2, (10, 3, 3)), torch.randint(0, 2, (10, 3, 3)))
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
from pytorch_lightning.metrics.functional.classification import precision_recall
with pytest.deprecated_call(match='will be removed in v1.4'):
precision_recall(torch.randint(0, 2, (10, 3, 3)), torch.randint(0, 2, (10, 3, 3)))
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
# Testing deprecation of class_reduction arg in the *new* precision
from pytorch_lightning.metrics.functional import precision
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
with pytest.deprecated_call(match='will be removed in v1.4'):
precision(torch.randint(0, 2, (10, )), torch.randint(0, 2, (10, )), class_reduction='micro')
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
# Testing deprecation of class_reduction arg in the *new* recall
from pytorch_lightning.metrics.functional import recall
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
with pytest.deprecated_call(match='will be removed in v1.4'):
recall(torch.randint(0, 2, (10, )), torch.randint(0, 2, (10, )), class_reduction='micro')
Classification metrics overhaul: precision & recall (4/n) (#4842) * Add stuff * Change metrics documentation layout * Add stuff * Add stat scores * Change testing utils * Replace len(*.shape) with *.ndim * More descriptive error message for input formatting * Replace movedim with permute * PEP 8 compliance * WIP * Add reduce_scores function * Temporarily add back legacy class_reduce * Division with float * PEP 8 compliance * Remove precision recall * Replace movedim with permute * Add back tests * Add empty newlines * Add precision recall back * Add empty line * Fix permute * Fix some issues with old versions of PyTorch * Style changes in error messages * More error message style improvements * Fix typo in docs * Add more descriptive variable names in utils * Change internal var names * Revert unwanted changes * Revert unwanted changes pt 2 * Update metrics interface * Add top_k parameter * Add back reduce function * Add stuff * PEP3 * Add depreciation * PEP8 * Deprecate param * PEP8 * Fix and simplify testing for older PT versions * Update Changelog * Remove redundant import * Add tests to increase coverage * Remove zero_division * fix zero_division * Add zero_div + edge case tests * Reorder cls metric args * Add back quotes for is_multiclass * Add precision_recall and tests * PEP8 * Fix docs * Fix docs * Update * Change precision_recall output * PEP8/isort * Add method _get_final_stats * Fix depr test * Add comment to deprecation tests * isort * Apply suggestions from code review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Add typing to test * Add matc str to pytest.raises Co-authored-by: chaton <thomas@grid.ai> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2021-01-18 08:24:13 +00:00
from pytorch_lightning.metrics.functional.classification import auc
with pytest.deprecated_call(match='will be removed in v1.4'):
auc(torch.rand(10, ).sort().values, torch.rand(10, ))
from pytorch_lightning.metrics.functional.classification import auroc
with pytest.deprecated_call(match='will be removed in v1.4'):
auroc(torch.rand(10, ), torch.randint(0, 2, (10, )))
from pytorch_lightning.metrics.functional.classification import multiclass_auroc
with pytest.deprecated_call(match='will be removed in v1.4'):
multiclass_auroc(torch.rand(20, 5).softmax(dim=-1), torch.randint(0, 5, (20, )), num_classes=5)
from pytorch_lightning.metrics.functional.classification import auc_decorator
with pytest.deprecated_call(match='will be removed in v1.4'):
auc_decorator()
from pytorch_lightning.metrics.functional.classification import multiclass_auc_decorator
with pytest.deprecated_call(match='will be removed in v1.4'):
multiclass_auc_decorator()
class CustomDDPPlugin(DDPPlugin):
def configure_ddp(self, model, device_ids):
# old, deprecated implementation
with pytest.deprecated_call(
match='`LightningDistributedDataParallel` is deprecated since v1.2 and will be removed in v1.4.'
):
model = LightningDistributedDataParallel(
module=model,
device_ids=device_ids,
**self._ddp_kwargs,
)
assert isinstance(model, torch.nn.parallel.DistributedDataParallel)
assert isinstance(model.module, LightningDistributedModule)
return model
@pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires GPU machine")
@pytest.mark.skipif(sys.platform == "win32", reason="DDP not available on windows")
def test_v1_4_0_deprecated_lightning_distributed_data_parallel(tmpdir):
model = BoringModel()
trainer = Trainer(
default_root_dir=tmpdir,
fast_dev_run=True,
gpus=2,
accelerator="ddp_spawn",
plugins=[CustomDDPPlugin()],
)
trainer.fit(model)
@pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires GPU machine")
def test_v1_4_0_deprecated_lightning_data_parallel():
model = BoringModel()
with pytest.deprecated_call(match="`LightningDataParallel` is deprecated since v1.2 and will be removed in v1.4."):
dp_model = LightningDataParallel(model, device_ids=[0])
assert isinstance(dp_model, torch.nn.DataParallel)
assert isinstance(dp_model.module, LightningParallelModule)