Repository: pytorch/ignite

Issue:
Fix CI warnings 
```

tests/ignite/handlers/test_state_param_scheduler.py: 15 warnings
  /opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/torch/testing/_deprecated.py:35: FutureWarning: torch.testing.assert_allclose() is deprecated since 1.12 and will be removed in 1.14. Use torch.testing.assert_close() instead. For detailed upgrade instructions see https://github.com/pytorch/pytorch/issues/61844.
    warnings.warn(msg, FutureWarning)

tests/ignite/metrics/test_classification_report.py: 48 warnings
  /opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/sklearn/metrics/_classification.py:1318: UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in samples with no predicted labels. Use `zero_division` parameter to control this behavior.
    _warn_prf(average, modifier, msg_start, len(result))

tests/ignite/metrics/test_classification_report.py: 48 warnings
  /opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/sklearn/metrics/_classification.py:1318: UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in samples with no true labels. Use `zero_division` parameter to control this behavior.
    _warn_prf(average, modifier, msg_start, len(result))

tests/ignite/metrics/test_precision.py: 40 warnings
tests/ignite/metrics/test_recall.py: 40 warnings
  /home/runner/work/ignite/ignite/ignite/metrics/precision.py:55: RuntimeWarning: `y` and `y_pred` should be of dtype long when entry type is binary and average!=False
    "`y` and `y_pred` should be of dtype long when entry type is binary and average!=False", RuntimeWarning

tests/ignite/metrics/test_precision.py: 30 warnings
  /opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/sklearn/metrics/_classification.py:1318: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.
    _warn_prf(average, modifier, msg_start, len(result))

tests/ignite/metrics/test_precision.py: 10 warnings
  /opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/sklearn/metrics/_classification.py:1318: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples. Use `zero_division` parameter to control this behavior.
    _warn_prf(average, modifier, msg_start, len(result))

tests/ignite/metrics/gan/test_inception_score.py::test_inception_score
tests/ignite/metrics/gan/test_utils.py::test_inception_extractor_wrong_inputs
tests/ignite/metrics/gan/test_utils.py::test_inception_model_probability
  /opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/torchvision/models/_utils.py:209: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.
    f"The parameter '{pretrained_param}' is deprecated since 0.13 and will be removed in 0.15, "

tests/ignite/metrics/gan/test_inception_score.py::test_inception_score
tests/ignite/metrics/gan/test_utils.py::test_inception_extractor_wrong_inputs
tests/ignite/metrics/gan/test_utils.py::test_inception_model_probability
  /opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=Inception_V3_Weights.IMAGENET1K_V1`. You can also use `weights=Inception_V3_Weights.DEFAULT` to get the most up-to-date weights.
    warnings.warn(msg)
```


Discussion:

Resolving patch:
diff --git a/ignite/metrics/gan/utils.py b/ignite/metrics/gan/utils.py
--- a/ignite/metrics/gan/utils.py
+++ b/ignite/metrics/gan/utils.py
@@ -1,6 +1,7 @@
 from typing import Callable, Optional, Union
 
 import torch
+from packaging.version import Version
 
 from ignite.metrics.metric import Metric
 
@@ -23,7 +24,13 @@ def __init__(self, return_features: bool, device: Union[str, torch.device] = "cp
             raise RuntimeError("This module requires torchvision to be installed.")
         super(InceptionModel, self).__init__()
         self._device = device
-        self.model = models.inception_v3(pretrained=True).to(self._device)
+        if Version(torch.__version__) <= Version("1.7.0"):
+            model_kwargs = {"pretrained": True}
+        else:
+            model_kwargs = {"weights": models.Inception_V3_Weights.DEFAULT}
+
+        self.model = models.inception_v3(**model_kwargs).to(self._device)
+
         if return_features:
             self.model.fc = torch.nn.Identity()
         else:


Test patch:
diff --git a/tests/ignite/handlers/test_state_param_scheduler.py b/tests/ignite/handlers/test_state_param_scheduler.py
--- a/tests/ignite/handlers/test_state_param_scheduler.py
+++ b/tests/ignite/handlers/test_state_param_scheduler.py
@@ -5,6 +5,7 @@
 import pytest
 import torch
 import torch.nn as nn
+from packaging.version import Version
 
 from ignite.engine import Engine, Events
 from ignite.handlers.state_param_scheduler import (
@@ -37,6 +38,11 @@
     },
 )
 
+if Version(torch.__version__) <= Version("1.7.0"):
+    torch_testing_assert_close = torch.testing.assert_allclose
+else:
+    torch_testing_assert_close = torch.testing.assert_close
+
 
 class LambdaState:
     def __init__(self, initial_value, gamma):
@@ -95,7 +101,7 @@ def test_pwlinear_scheduler_step_constant(max_epochs, milestones_values):
     )
     linear_state_parameter_scheduler.attach(engine, Events.EPOCH_COMPLETED)
     engine.run([0] * 8, max_epochs=max_epochs)
-    torch.testing.assert_allclose(getattr(engine.state, "pwlinear_scheduled_param"), milestones_values[0][1])
+    torch_testing_assert_close(getattr(engine.state, "pwlinear_scheduled_param"), float(milestones_values[0][1]))
 
     state_dict = linear_state_parameter_scheduler.state_dict()
     linear_state_parameter_scheduler.load_state_dict(state_dict)
@@ -113,7 +119,7 @@ def test_pwlinear_scheduler_linear_increase(max_epochs, milestones_values, expec
     )
     linear_state_parameter_scheduler.attach(engine, Events.EPOCH_COMPLETED)
     engine.run([0] * 8, max_epochs=max_epochs)
-    torch.testing.assert_allclose(getattr(engine.state, "pwlinear_scheduled_param"), expected_val, atol=0.001, rtol=0.0)
+    torch_testing_assert_close(getattr(engine.state, "pwlinear_scheduled_param"), expected_val, atol=0.001, rtol=0.0)
 
     state_dict = linear_state_parameter_scheduler.state_dict()
     linear_state_parameter_scheduler.load_state_dict(state_dict)
@@ -128,7 +134,7 @@ def test_pwlinear_scheduler_max_value(max_epochs, milestones_values):
     )
     linear_state_parameter_scheduler.attach(engine, Events.EPOCH_COMPLETED)
     engine.run([0] * 8, max_epochs=max_epochs)
-    torch.testing.assert_allclose(getattr(engine.state, "linear_scheduled_param"), milestones_values[-1][1])
+    torch_testing_assert_close(getattr(engine.state, "linear_scheduled_param"), float(milestones_values[-1][1]))
 
     state_dict = linear_state_parameter_scheduler.state_dict()
     linear_state_parameter_scheduler.load_state_dict(state_dict)
@@ -163,7 +169,7 @@ def test_exponential_scheduler(max_epochs, initial_value, gamma):
     )
     exp_state_parameter_scheduler.attach(engine, Events.EPOCH_COMPLETED)
     engine.run([0] * 8, max_epochs=max_epochs)
-    torch.testing.assert_allclose(getattr(engine.state, "exp_scheduled_param"), initial_value * gamma ** max_epochs)
+    torch_testing_assert_close(getattr(engine.state, "exp_scheduled_param"), initial_value * gamma ** max_epochs)
 
     state_dict = exp_state_parameter_scheduler.state_dict()
     exp_state_parameter_scheduler.load_state_dict(state_dict)
@@ -181,7 +187,7 @@ def test_step_scheduler(max_epochs, initial_value, gamma, step_size):
     )
     step_state_parameter_scheduler.attach(engine, Events.EPOCH_COMPLETED)
     engine.run([0] * 8, max_epochs=max_epochs)
-    torch.testing.assert_allclose(
+    torch_testing_assert_close(
         getattr(engine.state, "step_scheduled_param"), initial_value * gamma ** (max_epochs // step_size)
     )
 
@@ -206,7 +212,7 @@ def test_multistep_scheduler(max_epochs, initial_value, gamma, milestones):
     )
     multi_step_state_parameter_scheduler.attach(engine, Events.EPOCH_COMPLETED)
     engine.run([0] * 8, max_epochs=max_epochs)
-    torch.testing.assert_allclose(
+    torch_testing_assert_close(
         getattr(engine.state, "multistep_scheduled_param"),
         initial_value * gamma ** bisect_right(milestones, max_epochs),
     )
@@ -232,11 +238,11 @@ def __call__(self, event_index):
     )
     lambda_state_parameter_scheduler.attach(engine, Events.EPOCH_COMPLETED)
     engine.run([0] * 8, max_epochs=2)
-    torch.testing.assert_allclose(
+    torch_testing_assert_close(
         getattr(engine.state, "custom_scheduled_param"), LambdaState(initial_value=10, gamma=0.99)(2)
     )
     engine.run([0] * 8, max_epochs=20)
-    torch.testing.assert_allclose(
+    torch_testing_assert_close(
         getattr(engine.state, "custom_scheduled_param"), LambdaState(initial_value=10, gamma=0.99)(20)
     )
 
@@ -305,18 +311,17 @@ def test_torch_save_load(dirname):
     engine1 = Engine(lambda e, b: None)
     lambda_state_parameter_scheduler.attach(engine1, Events.EPOCH_COMPLETED)
     engine1.run([0] * 8, max_epochs=2)
-    torch.testing.assert_allclose(
+    torch_testing_assert_close(
         getattr(engine1.state, "custom_scheduled_param"), LambdaState(initial_value=10, gamma=0.99)(2)
     )
 
     engine2 = Engine(lambda e, b: None)
     loaded_lambda_state_parameter_scheduler.attach(engine2, Events.EPOCH_COMPLETED)
     engine2.run([0] * 8, max_epochs=2)
-    torch.testing.assert_allclose(
+    torch_testing_assert_close(
         getattr(engine2.state, "custom_scheduled_param"), LambdaState(initial_value=10, gamma=0.99)(2)
     )
-
-    torch.testing.assert_allclose(
+    torch_testing_assert_close(
         getattr(engine1.state, "custom_scheduled_param"), getattr(engine2.state, "custom_scheduled_param")
     )
 
@@ -363,7 +368,7 @@ def test_multiple_scheduler_with_save_history():
         _scheduler = scheduler(**config, save_history=True)
         _scheduler.attach(engine)
         engine.run([0] * 8, max_epochs=2)
-        torch.testing.assert_allclose(
+        torch_testing_assert_close(
             engine_multiple_schedulers.state.param_history[config["param_name"]],
             engine.state.param_history[config["param_name"]],
         )
diff --git a/tests/ignite/metrics/test_classification_report.py b/tests/ignite/metrics/test_classification_report.py
--- a/tests/ignite/metrics/test_classification_report.py
+++ b/tests/ignite/metrics/test_classification_report.py
@@ -48,7 +48,7 @@ def update(engine, i):
         from sklearn.metrics import classification_report as sklearn_classification_report
 
         sklearn_result = sklearn_classification_report(
-            y_true.cpu().numpy(), torch.argmax(y_preds, dim=1).cpu().numpy(), output_dict=True
+            y_true.cpu().numpy(), torch.argmax(y_preds, dim=1).cpu().numpy(), output_dict=True, zero_division=1
         )
 
         for i in range(n_classes):
@@ -118,7 +118,7 @@ def update(engine, i):
 
         from sklearn.metrics import classification_report as sklearn_classification_report
 
-        sklearn_result = sklearn_classification_report(np_y_true, np_y_preds, output_dict=True)
+        sklearn_result = sklearn_classification_report(np_y_true, np_y_preds, output_dict=True, zero_division=1)
 
         for i in range(n_classes):
             label_i = labels[i] if labels else str(i)
diff --git a/tests/ignite/metrics/test_precision.py b/tests/ignite/metrics/test_precision.py
--- a/tests/ignite/metrics/test_precision.py
+++ b/tests/ignite/metrics/test_precision.py
@@ -127,7 +127,9 @@ def _test(y_pred, y, batch_size):
         assert isinstance(pr.compute(), torch.Tensor if not average else float)
         pr_compute = pr.compute().numpy() if not average else pr.compute()
         sk_average_parameter = ignite_average_to_scikit_average(average, "binary")
-        assert precision_score(np_y, np_y_pred, average=sk_average_parameter) == pytest.approx(pr_compute)
+        assert precision_score(np_y, np_y_pred, average=sk_average_parameter, zero_division=0) == pytest.approx(
+            pr_compute
+        )
 
     def get_test_cases():
 
@@ -151,8 +153,8 @@ def get_test_cases():
             (torch.randint(0, 2, size=(50, 12, 10)), torch.randint(0, 2, size=(50, 12, 10)), 16),
             (torch.randint(0, 2, size=(50, 1, 12, 10)), torch.randint(0, 2, size=(50, 1, 12, 10)), 16),
             # Corner case with all zeros predictions
-            (torch.zeros(size=(10,)), torch.randint(0, 2, size=(10,)), 1),
-            (torch.zeros(size=(10, 1)), torch.randint(0, 2, size=(10, 1)), 1),
+            (torch.zeros(size=(10,), dtype=torch.long), torch.randint(0, 2, size=(10,)), 1),
+            (torch.zeros(size=(10, 1), dtype=torch.long), torch.randint(0, 2, size=(10, 1)), 1),
         ]
 
         return test_cases
diff --git a/tests/ignite/metrics/test_recall.py b/tests/ignite/metrics/test_recall.py
--- a/tests/ignite/metrics/test_recall.py
+++ b/tests/ignite/metrics/test_recall.py
@@ -155,8 +155,8 @@ def get_test_cases():
             (torch.randint(0, 2, size=(50, 12, 10)), torch.randint(0, 2, size=(50, 12, 10)), 16),
             (torch.randint(0, 2, size=(50, 1, 12, 10)), torch.randint(0, 2, size=(50, 1, 12, 10)), 16),
             # Corner case with all zeros predictions
-            (torch.zeros(size=(10,)), torch.randint(0, 2, size=(10,)), 1),
-            (torch.zeros(size=(10, 1)), torch.randint(0, 2, size=(10, 1)), 1),
+            (torch.zeros(size=(10,), dtype=torch.long), torch.randint(0, 2, size=(10,)), 1),
+            (torch.zeros(size=(10, 1), dtype=torch.long), torch.randint(0, 2, size=(10, 1)), 1),
         ]
 
         return test_cases