internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pytorch/ignite

Issue:
Suddenly failing tests with a NotImplementedError
## 🐛 Bug description

Getting a strange bug in recent commits to nussl with the latest ignite version. They look like this:

```
tests/separation/test_deep.py:62: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
nussl/ml/train/trainer.py:300: in add_stdout_handler
    pause=ValidationEvents.VALIDATION_COMPLETED
/opt/hostedtoolcache/Python/3.6.10/x64/lib/python3.6/site-packages/ignite/handlers/timing.py:115: in attach
    engine.add_event_handler(pause, self.pause)
/opt/hostedtoolcache/Python/3.6.10/x64/lib/python3.6/site-packages/ignite/engine/engine.py:269: in add_event_handler
    if event_name not in self._allowed_events:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Events.EPOCH_STARTED: 'epoch_started'>
other = <ValidationEvents.VALIDATION_COMPLETED: 'validation_completed'>

    def __eq__(self, other):
        if isinstance(other, CallableEventWithFilter):
            return self.name == other.name
        elif isinstance(other, str):
            return self.name == other
        else:
>           raise NotImplementedError
E           NotImplementedError

```

The full log is here:

https://github.com/nussl/nussl/runs/827399639

Did something in the Events API change? This worked in ignite 0.3 no problem.

Thanks!



Discussion:
@pseeth Thank you for this report. We will have a look on that!!
@pseeth the issue is about that all events and custom ones should inherit from `EventEnum`.
As `ValidationEvents` is an extension of `Enum`, that's why it fails, I think. @pseeth could you please check it ? 

We need to update :

- [x] Migration note
- [ ] Documentation 

to clearly state this in `Events` class description.

The only place where it is stated is https://pytorch.org/ignite/engine.html#ignite.engine.engine.Engine.register_events
@pseeth 

Your custom events are defined inheriting `Enum`. For now, you have to inherit from `EventEnum` (seen here https://github.com/nussl/nussl/blob/2c45df2ca4ba38db643f9f3903cee229b9ac301c/nussl/ml/train/trainer.py#L19).

Have a look here https://github.com/pytorch/ignite#custom-events-to-go-beyond-standard-events

HTH

EDIT : @vfdev-5 too fast 😂 
@sdesrozis you can be faster in doc fix :) Migration note is done.
I plan to update the doc this weekend 😉 

Resolving patch:
diff --git a/ignite/engine/events.py b/ignite/engine/events.py
--- a/ignite/engine/events.py
+++ b/ignite/engine/events.py
@@ -207,6 +207,13 @@ def call_once(engine):
         def call_on_events(engine):
             # do something
 
+    Since v0.4.0, custom events defined by user should inherit from :class:`~ignite.engine.events.EventEnum` :
+
+    .. code-block:: python
+
+        class CustomEvents(EventEnum):
+            FOO_EVENT = "foo_event"
+            BAR_EVENT = "bar_event"
     """
 
     EPOCH_STARTED = "epoch_started"


Test patch:
Repository: pytorch/ignite

Issue:
Pascal training bug with CM
## 🐛 Bug description

```
 File "./code/scripts/training.py", line 252, in log_cm
cm = cm_metric.compute().numpy()
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
2020-07-14 03:01:54,416 ignite.distributed.launcher.Parallel INFO: Finalized processing group with backend: 'nccl'
2020-07-14 03:01:54,417|training|ERROR|
```

## Environment

 - PyTorch Version (e.g., 1.4):
 - Ignite Version (e.g., 0.3.0):
 - OS (e.g., Linux):
 - How you installed Ignite (`conda`, `pip`, source):
 - Python version:
 - Any other relevant information:



Discussion:

Resolving patch:
diff --git a/examples/references/segmentation/pascal_voc2012/code/scripts/training.py b/examples/references/segmentation/pascal_voc2012/code/scripts/training.py
--- a/examples/references/segmentation/pascal_voc2012/code/scripts/training.py
+++ b/examples/references/segmentation/pascal_voc2012/code/scripts/training.py
@@ -179,7 +179,7 @@ def training(local_rank, config, logger=None):
 
     # Setup evaluators
     num_classes = config.num_classes
-    cm_metric = ConfusionMatrix(num_classes=num_classes)
+    cm_metric = ConfusionMatrix(num_classes=num_classes, average="recall")
 
     val_metrics = {
         "IoU": IoU(cm_metric),
@@ -241,16 +241,17 @@ def run_validation():
             event_name=Events.ITERATION_COMPLETED(once=len(val_loader) // 2),
         )
 
-        # Log confusion matrix to Trains:
-        if exp_tracking.has_trains:
-            from trains import Task
+    # Log confusion matrix to Trains:
+    if exp_tracking.has_trains:
+
+        @trainer.on(Events.COMPLETED)
+        def compute_and_log_cm():
+            cm = cm_metric.compute().cpu().numpy()
 
-            trains_logger = Task.current_task().get_logger()
+            if idist.get_rank() == 0:
+                from trains import Task
 
-            @trainer.on(Events.COMPLETED)
-            def log_cm():
-                cm = cm_metric.compute().numpy()
-                cm = cm / (cm.sum(axis=1)[:, None] + 1e-15)
+                trains_logger = Task.current_task().get_logger()
                 trains_logger.report_confusion_matrix(
                     title="Final Confusion Matrix",
                     series="cm-preds-gt",


Test patch:
Repository: pytorch/ignite

Issue:
Fix backward compatibilty
## 🐛 Bug description

Recent PR on the change of `mp.spawn` by `mp.start_process` brakes compatibility with PyTorch 1.3.1 and 1.4.0 versions.

https://github.com/pytorch/ignite/actions?query=workflow%3A.github%2Fworkflows%2Fpytorch-version-tests.yml

We have to fix that.


Discussion:

Resolving patch:
diff --git a/ignite/distributed/comp_models/native.py b/ignite/distributed/comp_models/native.py
--- a/ignite/distributed/comp_models/native.py
+++ b/ignite/distributed/comp_models/native.py
@@ -275,11 +275,14 @@ def spawn(
                 "join": kwargs.get("join", True),
                 "daemon": kwargs.get("daemon", False),
             }
-            # start_method in pytorch >= 1.5
+
+            start_processes = mp.spawn
+            # start_method and start_processes in pytorch >= 1.5
             if LooseVersion(torch.__version__) >= LooseVersion("1.5.0"):
                 spawn_kwargs["start_method"] = kwargs.get("start_method", "spawn")
+                start_processes = mp.start_processes
 
-            mp.start_processes(
+            start_processes(
                 _NativeDistModel._dist_worker_task_fn,
                 nprocs=nproc_per_node,
                 args=(


Test patch:
Repository: pytorch/ignite

Issue:
Docstring of Canberra metric warning
Following this comment 


> @sdesrozis could you please investigate why there is a warning here : https://travis-ci.org/github/pytorch/ignite/jobs/730492404#L2924 
thanks !
> Doc link is apparently badly rendered : https://pytorch.org/ignite/master/contrib/metrics.html#ignite.contrib.metrics.regression.CanberraMetric
> _Originally posted by @vfdev-5 in https://github.com/pytorch/ignite/pull/1314#issuecomment-699506241_

Namespace are shared so reference should be unique



Discussion:

Resolving patch:
diff --git a/ignite/contrib/metrics/regression/canberra_metric.py b/ignite/contrib/metrics/regression/canberra_metric.py
--- a/ignite/contrib/metrics/regression/canberra_metric.py
+++ b/ignite/contrib/metrics/regression/canberra_metric.py
@@ -19,7 +19,6 @@ class CanberraMetric(_BaseRegression):
     - ``update`` must receive output of the form ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.
     - `y` and `y_pred` must be of same shape `(N, )` or `(N, 1)`.
 
-    .. _Botchkarev 2018: https://arxiv.org/abs/1809.03006
     .. _scikit-learn distance metrics:
         https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.DistanceMetric.html
 


Test patch:
Repository: pytorch/ignite

Issue:
MyPy: improve ignite.utils module
## 🚀 Feature

Currently, mypy ignores all errors for all modules. We have to rework our typing such that mypy checks the code.
In this issue, let's improve https://github.com/pytorch/ignite/blob/master/ignite/utils.py module such that mypy passes on it.

For Hacktoberfest contributors, feel free to ask questions for details if any and say that you would like to tackle the issue.
Please, take a look at CONTRIBUTING guide.



Discussion:
Should be no problem, happy to help 😄 
Nice, thanks @gruebel !

Resolving patch:
diff --git a/ignite/utils.py b/ignite/utils.py
--- a/ignite/utils.py
+++ b/ignite/utils.py
@@ -1,7 +1,7 @@
 import collections.abc as collections
 import logging
 import random
-from typing import Any, Callable, Optional, Tuple, Type, Union
+from typing import Any, Callable, Optional, Tuple, Type, Union, cast
 
 import torch
 
@@ -41,11 +41,13 @@ def apply_to_type(
     if isinstance(input_, (str, bytes)):
         return input_
     if isinstance(input_, collections.Mapping):
-        return type(input_)({k: apply_to_type(sample, input_type, func) for k, sample in input_.items()})
+        return cast(Callable, type(input_))(
+            {k: apply_to_type(sample, input_type, func) for k, sample in input_.items()}
+        )
     if isinstance(input_, tuple) and hasattr(input_, "_fields"):  # namedtuple
-        return type(input_)(*(apply_to_type(sample, input_type, func) for sample in input_))
+        return cast(Callable, type(input_))(*(apply_to_type(sample, input_type, func) for sample in input_))
     if isinstance(input_, collections.Sequence):
-        return type(input_)([apply_to_type(sample, input_type, func) for sample in input_])
+        return cast(Callable, type(input_))([apply_to_type(sample, input_type, func) for sample in input_])
     raise TypeError(("input must contain {}, dicts or lists; found {}".format(input_type, type(input_))))
 
 


Test patch:
Repository: pytorch/ignite

Issue:
Expose EventEnum in the docs and fix custom events example
## 🚀 Feature

Currently, `EventEnum` is absent in the docs and below there is no link in the docs:

<img width="663" alt="Screen Shot 2020-10-03 at 23 34 44" src="https://user-images.githubusercontent.com/2459423/95002160-565a6300-05d1-11eb-9af2-a79886069af0.png">

https://pytorch.org/ignite/master/engine.html#ignite.engine.events.Events

Idea is to introduce it in the docs by adding a docstring here 
https://github.com/pytorch/ignite/blob/d384dc664b0e9d7241b5f688ca0f92b600a3cb4d/ignite/engine/events.py#L144-L145

and improve above and all other examples where `EventEnum` is mentioned (please, search for it in the whole repository) by adding
```
from ignite.engine import EventEnum
```


For Hacktoberfest contributors, feel free to ask questions for details if any and say that you would like to tackle the issue.
Please, take a look at CONTRIBUTING guide.


Discussion:
I would like to work on this. Could you please assign this to me? Also one quick question, can you elaborate on `improve above and all other examples where EventEnum is mentioned`?
@harsh8398 sure !

> Also one quick question, can you elaborate on improve above and all other examples where EventEnum is mentioned?

Please, search for all `EventEnum` mentions in the repository. It should be mentioned in several docstrings and examples that probably missing an explanation on how to import `EventEnum`. Idea is to add `from ignite.engine import EventEnum` to all those examples.




Resolving patch:
diff --git a/ignite/engine/events.py b/ignite/engine/events.py
--- a/ignite/engine/events.py
+++ b/ignite/engine/events.py
@@ -142,6 +142,36 @@ def __init__(self, *args, **kwargs):
 
 
 class EventEnum(CallableEventWithFilter, Enum):
+    """Base class for all :class:`~ignite.engine.events.Events`. User defined custom events should also inherit
+    this class. For example, Custom events based on the loss calculation and backward pass can be created as follows:
+
+        .. code-block:: python
+
+            from ignite.engine import EventEnum
+
+            class BackpropEvents(EventEnum):
+                BACKWARD_STARTED = 'backward_started'
+                BACKWARD_COMPLETED = 'backward_completed'
+                OPTIM_STEP_COMPLETED = 'optim_step_completed'
+
+            def update(engine, batch):
+                # ...
+                loss = criterion(y_pred, y)
+                engine.fire_event(BackpropEvents.BACKWARD_STARTED)
+                loss.backward()
+                engine.fire_event(BackpropEvents.BACKWARD_COMPLETED)
+                optimizer.step()
+                engine.fire_event(BackpropEvents.OPTIM_STEP_COMPLETED)
+                # ...
+
+            trainer = Engine(update)
+            trainer.register_events(*BackpropEvents)
+
+            @trainer.on(BackpropEvents.BACKWARD_STARTED)
+            def function_before_backprop(engine):
+                # ...
+    """
+
     pass
 
 


Test patch:
Repository: pytorch/ignite

Issue:
MyPy: improve ignite.base module
## 🚀 Feature

Currently, mypy ignores all errors for all modules. We have to rework our typing such that mypy checks the code.
In this issue, let's improve https://github.com/pytorch/ignite/tree/master/ignite/base module such that mypy passes on it.

For Hacktoberfest contributors, feel free to ask questions for details if any and say that you would like to tackle the issue.
Please, take a look at CONTRIBUTING guide.
Improve typing for ignite.handlers module (1343)
Fixes #1343 

Description:

Improves typing (when possible) for `ignite.handlers` module.

Check list:
* [x] New tests are added (if a new feature is added)
* [ ] New doc strings: description and/or example code are in RST format
* [ ] Documentation is updated (if required)



Discussion:
Hey, would love to contribute!  I've read through the contributing guide & should be able to complete this over the weekend.
Thanks @thescripted ! Let me assign it to you.

Hah... [`Found 5 errors in 3 files (checked 84 source files`)](https://travis-ci.org/github/pytorch/ignite/jobs/732630149#L281) on Travis, BUT
`Success: no issues found in 84 source files` on local machine... Interesting...
@trsvchn I think it is related to wha we discussed with @gruebel here : https://github.com/pytorch/ignite/pull/1352#discussion_r499236256
I merge his PR first and then we restart yours and it should be OK...
@trsvchn there still something incorrect : https://travis-ci.org/github/pytorch/ignite/jobs/732921246#L1409

Resolving patch:
diff --git a/ignite/base/mixins.py b/ignite/base/mixins.py
--- a/ignite/base/mixins.py
+++ b/ignite/base/mixins.py
@@ -4,8 +4,8 @@
 
 class Serializable:
 
-    _state_dict_all_req_keys = ()
-    _state_dict_one_of_opt_keys = ()
+    _state_dict_all_req_keys = ()  # type: tuple
+    _state_dict_one_of_opt_keys = ()  # type: tuple
 
     def state_dict(self) -> OrderedDict:
         pass


Test patch:
Repository: pytorch/ignite

Issue:
Fix mypy issue with pytorch nightly
## 🐛 Bug description

Currently, there is an issue with running mypy on ignite when using pytorch-nightly : 
```
 ignite/distributed/comp_models/native.py:334: error: Incompatible types in
assignment (expression has type "ReduceOp", variable has type "str") 
[assignment]
                op = self._reduce_op_map[op]
                     ^
Found 1 error in 1 file (checked 84 source files)
```

https://github.com/pytorch/ignite/runs/1373059337#step:5:17

@gruebel could you please take a look if we can fix it ? Thanks 



Discussion:
Sure, I can take a look today
Thanks @gruebel ! And couldy you please also remove `namedtuple` import (https://github.com/pytorch/ignite/pull/1433#discussion_r516991700). I merged too fast that PR :)
yeah, good point. Already forgot about it 🙈 

Resolving patch:
diff --git a/ignite/distributed/comp_models/native.py b/ignite/distributed/comp_models/native.py
--- a/ignite/distributed/comp_models/native.py
+++ b/ignite/distributed/comp_models/native.py
@@ -331,8 +331,8 @@ def spawn(  # type: ignore[override]
         def _do_all_reduce(self, tensor: torch.Tensor, op: str = "SUM") -> torch.Tensor:
             if op not in self._reduce_op_map:
                 raise ValueError("Unsupported reduction operation: '{}'".format(op))
-            op = self._reduce_op_map[op]
-            dist.all_reduce(tensor, op)
+            reduce_op = self._reduce_op_map[op]
+            dist.all_reduce(tensor, reduce_op)
             return tensor
 
         def _do_all_gather(self, tensor: torch.Tensor) -> torch.Tensor:
diff --git a/ignite/handlers/checkpoint.py b/ignite/handlers/checkpoint.py
--- a/ignite/handlers/checkpoint.py
+++ b/ignite/handlers/checkpoint.py
@@ -4,7 +4,7 @@
 import tempfile
 import warnings
 from abc import ABCMeta, abstractmethod
-from collections import OrderedDict, namedtuple
+from collections import OrderedDict
 from tempfile import _TemporaryFileWrapper  # type: ignore[attr-defined]
 from typing import Any, Callable, Dict, List, Mapping, NamedTuple, Optional, Tuple, Union
 


Test patch:
Repository: pytorch/ignite

Issue:
favicon for documentation
## 🚀 Feature

There shall be a favicon for Ignite documentation, currently it's pytorch favicon

cc: @vfdev-5 



Discussion:

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -105,6 +105,8 @@
 
 html_logo = "_static/img/ignite_logo.svg"
 
+html_favicon = "_templates/_static/img/ignite_logomark.svg"
+
 # Theme options are theme-specific and customize the look and feel of a theme
 # further.  For a list of options available for each theme, see the
 # documentation.


Test patch:
Repository: pytorch/ignite

Issue:
[docs] use katex instead of mathjax
## 🚀 Feature
Currently, math equation in the `contrib.metrics` are so small that we have to zoom to look at.
I want to suggest for using `katex` instead of `mathjax` and also `pytorch_sphinx_theme` has preloaded with `katex` font.

What's need to change here is
- install `sphinxcontrib-katex`
- add `sphinxcontrib.katex` in `extensions` of `conf.py`
- add the below code block in head tag of `layout.html`
```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">

    <!-- The loading of KaTeX is deferred to speed up page rendering -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>

    <!-- To automatically render math in text elements, include the auto-render extension: -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"
        onload="renderMathInElement(document.body);"></script>
```
Katex: https://katex.org/docs/browser.html


Discussion:
Yes, I agree, that if using katex docs rendering could be improved, it is something to do. Thanks @ydcjeff !

cc @trsvchn 
I have tried locally when implementing #1570 and it works!

Resolving patch:
diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -56,12 +56,15 @@
     "sphinx.ext.intersphinx",
     "sphinx.ext.todo",
     "sphinx.ext.coverage",
-    "sphinx.ext.mathjax",
+    "sphinxcontrib.katex",
     "sphinx.ext.napoleon",
     "sphinx.ext.viewcode",
     "sphinx.ext.autosectionlabel",
 ]
 
+# katex options
+katex_prerender = True
+
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ["_templates"]
 


Test patch:
Repository: pytorch/ignite

Issue:
Use setup_logger in handlers
## 🚀 Feature

Idea is to replace in handlers (`EarlyStopping`, `TerminateOnNan`, etc.)
```
self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
```
by `setup_logger` from `ignite.utils`
```
self.logger = setup_logger(__name__ + "." + self.__class__.__name__)
```


Discussion:
Can I work on this?

Resolving patch:
diff --git a/ignite/handlers/early_stopping.py b/ignite/handlers/early_stopping.py
--- a/ignite/handlers/early_stopping.py
+++ b/ignite/handlers/early_stopping.py
@@ -1,9 +1,9 @@
-import logging
 from collections import OrderedDict
 from typing import Callable, Mapping, Optional, cast
 
 from ignite.base import Serializable
 from ignite.engine import Engine
+from ignite.utils import setup_logger
 
 __all__ = ["EarlyStopping"]
 
@@ -76,7 +76,7 @@ def __init__(
         self.trainer = trainer
         self.counter = 0
         self.best_score = None  # type: Optional[float]
-        self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
+        self.logger = setup_logger(__name__ + "." + self.__class__.__name__)
 
     def __call__(self, engine: Engine) -> None:
         score = self.score_function(engine)
diff --git a/ignite/handlers/terminate_on_nan.py b/ignite/handlers/terminate_on_nan.py
--- a/ignite/handlers/terminate_on_nan.py
+++ b/ignite/handlers/terminate_on_nan.py
@@ -5,7 +5,7 @@
 import torch
 
 from ignite.engine import Engine
-from ignite.utils import apply_to_type
+from ignite.utils import apply_to_type, setup_logger
 
 __all__ = ["TerminateOnNan"]
 
@@ -33,7 +33,7 @@ class TerminateOnNan:
     """
 
     def __init__(self, output_transform: Callable = lambda x: x):
-        self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
+        self.logger = setup_logger(__name__ + "." + self.__class__.__name__)
         self.logger.addHandler(logging.StreamHandler())
         self._output_transform = output_transform
 
diff --git a/ignite/handlers/time_limit.py b/ignite/handlers/time_limit.py
--- a/ignite/handlers/time_limit.py
+++ b/ignite/handlers/time_limit.py
@@ -1,4 +1,3 @@
-import logging
 import time
 from typing import Optional
 
@@ -6,6 +5,8 @@
 
 __all__ = ["TimeLimit"]
 
+from ignite.utils import setup_logger
+
 
 class TimeLimit:
     """TimeLimit handler can be used to control training time for computing environments where session time is limited.
@@ -37,7 +38,7 @@ def __init__(self, limit_sec: Optional[int] = 28800):
 
         self.limit_sec = limit_sec
         self.start_time = time.time()
-        self.logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
+        self.logger = setup_logger(__name__ + "." + self.__class__.__name__)
 
     def __call__(self, engine: Engine) -> None:
         elapsed_time = time.time() - self.start_time


Test patch: