Repository: pfnet/pytorch-pfn-extras

Issue:
Fix nightly CPU test failures
https://github.com/pfnet/pytorch-pfn-extras/actions/workflows/nightly-test-cpu.yml


Discussion:
Latest summary https://github.com/pfnet/pytorch-pfn-extras/actions/runs/6764593441/job/18383088613#step:5:366
```
=========================== short test summary info ============================
FAILED tests/pytorch_pfn_extras_tests/distributed_tests/test_distributed_validation_sampler.py::test_no_distributed_available - ValueError: Default process group has not been initialized, please make sure to call init_process_group.
FAILED tests/pytorch_pfn_extras_tests/training_tests/test_manager.py::test_ignite_extensions_manager_state_dict - UserWarning: PairwiseParallel is deprecated and will be removed soon. Use ColwiseParallel and RowwiseParallel instead.
FAILED tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_evaluator.py::test_ignite_evaluator_reporting_metrics - UserWarning: PairwiseParallel is deprecated and will be removed soon. Use ColwiseParallel and RowwiseParallel instead.
FAILED tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_progress_bar_notebook.py::test_ignite_extensions_manager_with_progressbar_notebook - UserWarning: PairwiseParallel is deprecated and will be removed soon. Use ColwiseParallel and RowwiseParallel instead.
```

Resolving patch:
diff --git a/pytorch_pfn_extras/distributed/_distributed_validation_sampler.py b/pytorch_pfn_extras/distributed/_distributed_validation_sampler.py
--- a/pytorch_pfn_extras/distributed/_distributed_validation_sampler.py
+++ b/pytorch_pfn_extras/distributed/_distributed_validation_sampler.py
@@ -26,13 +26,13 @@ def __init__(
         seed: int = 0,
     ) -> None:
         if num_replicas is None:
-            if not dist.is_available():  # type: ignore[no-untyped-call]
+            if not dist.is_available() or not dist.is_initialized():  # type: ignore[no-untyped-call]
                 raise RuntimeError(
                     "Requires distributed package to be available"
                 )
             num_replicas = dist.get_world_size()  # type: ignore[no-untyped-call]
         if rank is None:
-            if not dist.is_available():  # type: ignore[no-untyped-call]
+            if not dist.is_available() or not dist.is_initialized():  # type: ignore[no-untyped-call]
                 raise RuntimeError(
                     "Requires distributed package to be available"
                 )


Test patch:
diff --git a/tests/pytorch_pfn_extras_tests/distributed_tests/test_distributed_validation_sampler.py b/tests/pytorch_pfn_extras_tests/distributed_tests/test_distributed_validation_sampler.py
--- a/tests/pytorch_pfn_extras_tests/distributed_tests/test_distributed_validation_sampler.py
+++ b/tests/pytorch_pfn_extras_tests/distributed_tests/test_distributed_validation_sampler.py
@@ -18,7 +18,7 @@ def test_default(base_dataset):
     sample_idxs = []
     with mock.patch.object(
         dist, "get_world_size", return_value=_world_size
-    ), mock.patch.object(dist, "is_available", return_value=True):
+    ), mock.patch.object(dist, "is_initialized", return_value=True):
         for rank in range(_world_size):
             with mock.patch.object(dist, "get_rank", return_value=rank):
                 sampler = DistributedValidationSampler(base_dataset)
@@ -41,7 +41,7 @@ def test_no_shuffle(base_dataset):
     ]
     with mock.patch.object(
         dist, "get_world_size", return_value=_world_size
-    ), mock.patch.object(dist, "is_available", return_value=True):
+    ), mock.patch.object(dist, "is_initialized", return_value=True):
         for rank in range(_world_size):
             with mock.patch.object(dist, "get_rank", return_value=rank):
                 sampler = DistributedValidationSampler(
@@ -57,7 +57,7 @@ def test_manual_num_replicas_and_ranks(base_dataset):
     with mock.patch.object(
         dist, "get_world_size", side_effect=AssertionError()
     ), mock.patch.object(
-        dist, "is_available", side_effect=AssertionError()
+        dist, "is_initialized", side_effect=AssertionError()
     ), mock.patch.object(
         dist, "get_rank", side_effect=AssertionError()
     ):
@@ -78,7 +78,7 @@ def test_seed(base_dataset):
     assert list(sampler1) != list(sampler2)
 
 
-def test_no_distributed_available(base_dataset):
+def test_no_distributed_initialized(base_dataset):
     with pytest.raises(RuntimeError):
         DistributedValidationSampler(base_dataset, num_replicas=_world_size)
     with pytest.raises(RuntimeError):
@@ -88,6 +88,10 @@ def test_no_distributed_available(base_dataset):
 def test_invalid_rank(base_dataset):
     with mock.patch.object(dist, "get_world_size", return_value=_world_size):
         with pytest.raises(ValueError):
-            DistributedValidationSampler(base_dataset, rank=-1)
+            DistributedValidationSampler(
+                base_dataset, num_replicas=_world_size, rank=-1
+            )
         with pytest.raises(ValueError):
-            DistributedValidationSampler(base_dataset, rank=_world_size)
+            DistributedValidationSampler(
+                base_dataset, num_replicas=_world_size, rank=_world_size
+            )
diff --git a/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_evaluator.py b/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_evaluator.py
--- a/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_evaluator.py
+++ b/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_evaluator.py
@@ -273,6 +273,7 @@ def update_fn(engine, batch):
     return evaluator
 
 
+@pytest.mark.filterwarnings("ignore::UserWarning")
 def test_ignite_evaluator_reporting_metrics():
     try:
         from ignite.metrics import MeanSquaredError
diff --git a/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_progress_bar_notebook.py b/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_progress_bar_notebook.py
--- a/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_progress_bar_notebook.py
+++ b/tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_progress_bar_notebook.py
@@ -47,6 +47,7 @@ def test_run_progress_bar_notebook():
     reason="progress bar notebook import failed, "
     "maybe ipython is not installed",
 )
+@pytest.mark.filterwarnings("ignore::UserWarning")
 def test_ignite_extensions_manager_with_progressbar_notebook():
     try:
         from ignite.engine import create_supervised_trainer
diff --git a/tests/pytorch_pfn_extras_tests/training_tests/test_manager.py b/tests/pytorch_pfn_extras_tests/training_tests/test_manager.py
--- a/tests/pytorch_pfn_extras_tests/training_tests/test_manager.py
+++ b/tests/pytorch_pfn_extras_tests/training_tests/test_manager.py
@@ -314,6 +314,7 @@ def test_extensions_manager_state_dict_future_ppe_version():
         manager_2.load_state_dict(state_dict)
 
 
+@pytest.mark.filterwarnings("ignore::UserWarning")
 def test_ignite_extensions_manager_state_dict():
     try:
         from ignite.engine import create_supervised_trainer