We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
tqm_logger: metric_names is currently not optional 
Hi,

https://github.com/pytorch/ignite/blob/master/ignite/contrib/handlers/tqdm_logger.py#L75
This line should be modified to make `metric_names` optional. Here is a suggestion:
```
if metric_names is not None and not isinstance(metric_names, list):
    raise TypeError("metric_names should be a list, got {} instead".format(type(metric_names)))
```

Thanks

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ignite/contrib/handlers/tqdm_logger.py`
Content:
```
1 try:
2     from tqdm import tqdm
3 except ImportError:
4     raise RuntimeError("This contrib module requires tqdm to be installed")
5 
6 from ignite.engine import Events
7 
8 
9 class ProgressBar:
10     """
11     TQDM progress bar handler to log training progress and computed metrics.
12 
13     Examples:
14 
15         Create a progress bar that shows you some metrics as they are computed,
16         by simply attaching the progress bar object to your engine.
17 
18         .. code-block:: python
19 
20             pbar = ProgressBar()
21             pbar.attach(trainer, ['loss'])
22 
23     Note:
24         When adding attaching the progress bar to an engine, it is recommend that you replace
25         every print operation in the engine's handlers triggered every iteration with
26         ``pbar.log_message`` to guarantee the correct format of the stdout.
27     """
28 
29     def __init__(self):
30         self.pbar = None
31 
32     def _reset(self, engine):
33         self.pbar = tqdm(
34             total=len(engine.state.dataloader),
35             leave=False,
36             bar_format='{desc}[{n_fmt}/{total_fmt}] {percentage:3.0f}%|{bar}{postfix} [{elapsed}<{remaining}]')
37 
38     def _close(self, engine):
39         self.pbar.close()
40         self.pbar = None
41 
42     def _update(self, engine, metric_names=None):
43         if self.pbar is None:
44             self._reset(engine)
45 
46         self.pbar.set_description('Epoch {}'.format(engine.state.epoch))
47 
48         if metric_names is not None:
49             if not all(metric in engine.state.metrics for metric in metric_names):
50                 raise KeyError("metrics not found in engine.state.metrics")
51 
52             metrics = {name: '{:.2e}'.format(engine.state.metrics[name]) for name in metric_names}
53             self.pbar.set_postfix(**metrics)
54 
55         self.pbar.update()
56 
57     @staticmethod
58     def log_message(message):
59         """
60         Logs a message, preserving the progress bar correct output format
61 
62         Args:
63             message (str): string you wish to log
64         """
65         tqdm.write(message)
66 
67     def attach(self, engine, metric_names=None):
68         """
69         Attaches the progress bar to an engine object
70 
71         Args:
72             engine (Engine): engine object
73             metric_names (list): (Optional) list of the metrics names to log as the bar progresses
74         """
75         if not isinstance(metric_names, list):
76             raise TypeError("metric_names should be a list, got {} instead".format(type(metric_names)))
77 
78         engine.add_event_handler(Events.EPOCH_COMPLETED, self._close)
79         engine.add_event_handler(Events.ITERATION_COMPLETED, self._update, metric_names)
80
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ignite/contrib/handlers/tqdm_logger.py b/ignite/contrib/handlers/tqdm_logger.py
--- a/ignite/contrib/handlers/tqdm_logger.py
+++ b/ignite/contrib/handlers/tqdm_logger.py
@@ -47,6 +47,7 @@
 
         if metric_names is not None:
             if not all(metric in engine.state.metrics for metric in metric_names):
+                self._close(engine)
                 raise KeyError("metrics not found in engine.state.metrics")
 
             metrics = {name: '{:.2e}'.format(engine.state.metrics[name]) for name in metric_names}
@@ -72,7 +73,7 @@
             engine (Engine): engine object
             metric_names (list): (Optional) list of the metrics names to log as the bar progresses
         """
-        if not isinstance(metric_names, list):
+        if metric_names is not None and not isinstance(metric_names, list):
             raise TypeError("metric_names should be a list, got {} instead".format(type(metric_names)))
 
         engine.add_event_handler(Events.EPOCH_COMPLETED, self._close)

{"golden_diff": "diff --git a/ignite/contrib/handlers/tqdm_logger.py b/ignite/contrib/handlers/tqdm_logger.py\n--- a/ignite/contrib/handlers/tqdm_logger.py\n+++ b/ignite/contrib/handlers/tqdm_logger.py\n@@ -47,6 +47,7 @@\n \n         if metric_names is not None:\n             if not all(metric in engine.state.metrics for metric in metric_names):\n+                self._close(engine)\n                 raise KeyError(\"metrics not found in engine.state.metrics\")\n \n             metrics = {name: '{:.2e}'.format(engine.state.metrics[name]) for name in metric_names}\n@@ -72,7 +73,7 @@\n             engine (Engine): engine object\n             metric_names (list): (Optional) list of the metrics names to log as the bar progresses\n         \"\"\"\n-        if not isinstance(metric_names, list):\n+        if metric_names is not None and not isinstance(metric_names, list):\n             raise TypeError(\"metric_names should be a list, got {} instead\".format(type(metric_names)))\n \n         engine.add_event_handler(Events.EPOCH_COMPLETED, self._close)\n", "issue": "tqm_logger: metric_names is currently not optional \nHi,\r\n\r\nhttps://github.com/pytorch/ignite/blob/master/ignite/contrib/handlers/tqdm_logger.py#L75\r\nThis line should be modified to make `metric_names` optional. Here is a suggestion:\r\n```\r\nif metric_names is not None and not isinstance(metric_names, list):\r\n    raise TypeError(\"metric_names should be a list, got {} instead\".format(type(metric_names)))\r\n```\r\n\r\nThanks\n", "before_files": [{"content": "try:\n    from tqdm import tqdm\nexcept ImportError:\n    raise RuntimeError(\"This contrib module requires tqdm to be installed\")\n\nfrom ignite.engine import Events\n\n\nclass ProgressBar:\n    \"\"\"\n    TQDM progress bar handler to log training progress and computed metrics.\n\n    Examples:\n\n        Create a progress bar that shows you some metrics as they are computed,\n        by simply attaching the progress bar object to your engine.\n\n        .. code-block:: python\n\n            pbar = ProgressBar()\n            pbar.attach(trainer, ['loss'])\n\n    Note:\n        When adding attaching the progress bar to an engine, it is recommend that you replace\n        every print operation in the engine's handlers triggered every iteration with\n        ``pbar.log_message`` to guarantee the correct format of the stdout.\n    \"\"\"\n\n    def __init__(self):\n        self.pbar = None\n\n    def _reset(self, engine):\n        self.pbar = tqdm(\n            total=len(engine.state.dataloader),\n            leave=False,\n            bar_format='{desc}[{n_fmt}/{total_fmt}] {percentage:3.0f}%|{bar}{postfix} [{elapsed}<{remaining}]')\n\n    def _close(self, engine):\n        self.pbar.close()\n        self.pbar = None\n\n    def _update(self, engine, metric_names=None):\n        if self.pbar is None:\n            self._reset(engine)\n\n        self.pbar.set_description('Epoch {}'.format(engine.state.epoch))\n\n        if metric_names is not None:\n            if not all(metric in engine.state.metrics for metric in metric_names):\n                raise KeyError(\"metrics not found in engine.state.metrics\")\n\n            metrics = {name: '{:.2e}'.format(engine.state.metrics[name]) for name in metric_names}\n            self.pbar.set_postfix(**metrics)\n\n        self.pbar.update()\n\n    @staticmethod\n    def log_message(message):\n        \"\"\"\n        Logs a message, preserving the progress bar correct output format\n\n        Args:\n            message (str): string you wish to log\n        \"\"\"\n        tqdm.write(message)\n\n    def attach(self, engine, metric_names=None):\n        \"\"\"\n        Attaches the progress bar to an engine object\n\n        Args:\n            engine (Engine): engine object\n            metric_names (list): (Optional) list of the metrics names to log as the bar progresses\n        \"\"\"\n        if not isinstance(metric_names, list):\n            raise TypeError(\"metric_names should be a list, got {} instead\".format(type(metric_names)))\n\n        engine.add_event_handler(Events.EPOCH_COMPLETED, self._close)\n        engine.add_event_handler(Events.ITERATION_COMPLETED, self._update, metric_names)\n", "path": "ignite/contrib/handlers/tqdm_logger.py"}], "after_files": [{"content": "try:\n    from tqdm import tqdm\nexcept ImportError:\n    raise RuntimeError(\"This contrib module requires tqdm to be installed\")\n\nfrom ignite.engine import Events\n\n\nclass ProgressBar:\n    \"\"\"\n    TQDM progress bar handler to log training progress and computed metrics.\n\n    Examples:\n\n        Create a progress bar that shows you some metrics as they are computed,\n        by simply attaching the progress bar object to your engine.\n\n        .. code-block:: python\n\n            pbar = ProgressBar()\n            pbar.attach(trainer, ['loss'])\n\n    Note:\n        When adding attaching the progress bar to an engine, it is recommend that you replace\n        every print operation in the engine's handlers triggered every iteration with\n        ``pbar.log_message`` to guarantee the correct format of the stdout.\n    \"\"\"\n\n    def __init__(self):\n        self.pbar = None\n\n    def _reset(self, engine):\n        self.pbar = tqdm(\n            total=len(engine.state.dataloader),\n            leave=False,\n            bar_format='{desc}[{n_fmt}/{total_fmt}] {percentage:3.0f}%|{bar}{postfix} [{elapsed}<{remaining}]')\n\n    def _close(self, engine):\n        self.pbar.close()\n        self.pbar = None\n\n    def _update(self, engine, metric_names=None):\n        if self.pbar is None:\n            self._reset(engine)\n\n        self.pbar.set_description('Epoch {}'.format(engine.state.epoch))\n\n        if metric_names is not None:\n            if not all(metric in engine.state.metrics for metric in metric_names):\n                self._close(engine)\n                raise KeyError(\"metrics not found in engine.state.metrics\")\n\n            metrics = {name: '{:.2e}'.format(engine.state.metrics[name]) for name in metric_names}\n            self.pbar.set_postfix(**metrics)\n\n        self.pbar.update()\n\n    @staticmethod\n    def log_message(message):\n        \"\"\"\n        Logs a message, preserving the progress bar correct output format\n\n        Args:\n            message (str): string you wish to log\n        \"\"\"\n        tqdm.write(message)\n\n    def attach(self, engine, metric_names=None):\n        \"\"\"\n        Attaches the progress bar to an engine object\n\n        Args:\n            engine (Engine): engine object\n            metric_names (list): (Optional) list of the metrics names to log as the bar progresses\n        \"\"\"\n        if metric_names is not None and not isinstance(metric_names, list):\n            raise TypeError(\"metric_names should be a list, got {} instead\".format(type(metric_names)))\n\n        engine.add_event_handler(Events.EPOCH_COMPLETED, self._close)\n        engine.add_event_handler(Events.ITERATION_COMPLETED, self._update, metric_names)\n", "path": "ignite/contrib/handlers/tqdm_logger.py"}]}