prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  gpu_info crashes because it cannot parse "N/A"
  ## 🐛 Bug description
  
  When trying to use gpu_info, it throws:
  
  ```
   File "/home/blackhc/anaconda3/envs/hello-mnist/lib/python3.7/site-packages/ignite/contrib/metrics/gpu_info.py", line 91, in completed
      engine.state.metrics[util_name] = int(util_report['gpu_util'])
  ValueError: invalid literal for int() with base 10: 'N/A'
  ```
  
  There is error handling code above it, but it does not catch the issue ("N/A" is returned).
  
  I assume my GPU does not support it. However, it would be neat to have a graceful failure mode.
  
  Thank you!
  Andreas
  
  ## Environment
  
  torch 1.5 on a GTX 780 TI (source)
  ignite 0.3.0 (conda)
  pynvml 8.0.4 (pip)
  
  
  --- 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/metrics/gpu_info.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 import warnings
  3 
  4 import torch
  5 
  6 from ignite.engine import Events
  7 from ignite.metrics import Metric
  8 
  9 
  10 class GpuInfo(Metric):
  11     """Provides GPU information: a) used memory percentage, b) gpu utilization percentage values as Metric
  12     on each iterations.
  13 
  14     Examples:
  15 
  16         .. code-block:: python
  17 
  18             # Default GPU measurements
  19             GpuInfo().attach(trainer, name='gpu')  # metric names are 'gpu:X mem(%)', 'gpu:X util(%)'
  20 
  21             # Logging with TQDM
  22             ProgressBar(persist=True).attach(trainer, metric_names=['gpu:0 mem(%)', 'gpu:0 util(%)'])
  23             # Progress bar will looks like
  24             # Epoch [2/10]: [12/24]  50%|█████      , gpu:0 mem(%)=79, gpu:0 util(%)=59 [00:17<1:23]
  25 
  26             # Logging with Tensorboard
  27             tb_logger.attach(trainer,
  28                              log_handler=OutputHandler(tag="training", metric_names='all'),
  29                              event_name=Events.ITERATION_COMPLETED)
  30     """
  31 
  32     def __init__(self):
  33         try:
  34             import pynvml
  35         except ImportError:
  36             raise RuntimeError(
  37                 "This contrib module requires pynvml to be installed. "
  38                 "Please install it with command: \n pip install pynvml"
  39             )
  40             # Let's check available devices
  41         if not torch.cuda.is_available():
  42             raise RuntimeError("This contrib module requires available GPU")
  43 
  44         from pynvml.smi import nvidia_smi
  45 
  46         # Let it fail if no libnvidia drivers or NMVL library found
  47         self.nvsmi = nvidia_smi.getInstance()
  48         super(GpuInfo, self).__init__()
  49 
  50     def reset(self):
  51         pass
  52 
  53     def update(self, output):
  54         pass
  55 
  56     def compute(self):
  57         data = self.nvsmi.DeviceQuery("memory.used, memory.total, utilization.gpu")
  58         if len(data) == 0 or ("gpu" not in data):
  59             warnings.warn("No GPU information available")
  60             return []
  61         return data["gpu"]
  62 
  63     def completed(self, engine, name):
  64         data = self.compute()
  65         if len(data) < 1:
  66             warnings.warn("No GPU information available")
  67             return
  68 
  69         for i, data_by_rank in enumerate(data):
  70             mem_name = "{}:{} mem(%)".format(name, i)
  71 
  72             if "fb_memory_usage" not in data_by_rank:
  73                 warnings.warn("No GPU memory usage information available in {}".format(data_by_rank))
  74                 continue
  75             mem_report = data_by_rank["fb_memory_usage"]
  76             if not ("used" in mem_report and "total" in mem_report):
  77                 warnings.warn(
  78                     "GPU memory usage information does not provide used/total "
  79                     "memory consumption information in {}".format(mem_report)
  80                 )
  81                 continue
  82 
  83             engine.state.metrics[mem_name] = int(mem_report["used"] * 100.0 / mem_report["total"])
  84 
  85         for i, data_by_rank in enumerate(data):
  86             util_name = "{}:{} util(%)".format(name, i)
  87             if "utilization" not in data_by_rank:
  88                 warnings.warn("No GPU utilization information available in {}".format(data_by_rank))
  89                 continue
  90             util_report = data_by_rank["utilization"]
  91             if not ("gpu_util" in util_report):
  92                 warnings.warn(
  93                     "GPU utilization information does not provide 'gpu_util' information in " "{}".format(util_report)
  94                 )
  95                 continue
  96 
  97             engine.state.metrics[util_name] = int(util_report["gpu_util"])
  98 
  99     def attach(self, engine, name="gpu", event_name=Events.ITERATION_COMPLETED):
  100         engine.add_event_handler(event_name, self.completed, name)
  101
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/ignite/contrib/metrics/gpu_info.py b/ignite/contrib/metrics/gpu_info.py
  --- a/ignite/contrib/metrics/gpu_info.py
  +++ b/ignite/contrib/metrics/gpu_info.py
  @@ -11,6 +11,10 @@
       """Provides GPU information: a) used memory percentage, b) gpu utilization percentage values as Metric
       on each iterations.
   
  +    .. Note ::
  +
  +        In case if gpu utilization reports "N/A" on a given GPU, corresponding metric value is not set.
  +
       Examples:
   
           .. code-block:: python
  @@ -90,11 +94,14 @@
               util_report = data_by_rank["utilization"]
               if not ("gpu_util" in util_report):
                   warnings.warn(
  -                    "GPU utilization information does not provide 'gpu_util' information in " "{}".format(util_report)
  +                    "GPU utilization information does not provide 'gpu_util' information in {}".format(util_report)
                   )
                   continue
  -
  -            engine.state.metrics[util_name] = int(util_report["gpu_util"])
  +            try:
  +                engine.state.metrics[util_name] = int(util_report["gpu_util"])
  +            except ValueError:
  +                # Do not set GPU utilization information
  +                pass
   
       def attach(self, engine, name="gpu", event_name=Events.ITERATION_COMPLETED):
           engine.add_event_handler(event_name, self.completed, name)
  
verification_info: {"golden_diff": "diff --git a/ignite/contrib/metrics/gpu_info.py b/ignite/contrib/metrics/gpu_info.py\n--- a/ignite/contrib/metrics/gpu_info.py\n+++ b/ignite/contrib/metrics/gpu_info.py\n@@ -11,6 +11,10 @@\n     \"\"\"Provides GPU information: a) used memory percentage, b) gpu utilization percentage values as Metric\n     on each iterations.\n \n+    .. Note ::\n+\n+        In case if gpu utilization reports \"N/A\" on a given GPU, corresponding metric value is not set.\n+\n     Examples:\n \n         .. code-block:: python\n@@ -90,11 +94,14 @@\n             util_report = data_by_rank[\"utilization\"]\n             if not (\"gpu_util\" in util_report):\n                 warnings.warn(\n-                    \"GPU utilization information does not provide 'gpu_util' information in \" \"{}\".format(util_report)\n+                    \"GPU utilization information does not provide 'gpu_util' information in {}\".format(util_report)\n                 )\n                 continue\n-\n-            engine.state.metrics[util_name] = int(util_report[\"gpu_util\"])\n+            try:\n+                engine.state.metrics[util_name] = int(util_report[\"gpu_util\"])\n+            except ValueError:\n+                # Do not set GPU utilization information\n+                pass\n \n     def attach(self, engine, name=\"gpu\", event_name=Events.ITERATION_COMPLETED):\n         engine.add_event_handler(event_name, self.completed, name)\n", "issue": "gpu_info crashes because it cannot parse \"N/A\"\n## \ud83d\udc1b Bug description\r\n\r\nWhen trying to use gpu_info, it throws:\r\n\r\n```\r\n File \"/home/blackhc/anaconda3/envs/hello-mnist/lib/python3.7/site-packages/ignite/contrib/metrics/gpu_info.py\", line 91, in completed\r\n    engine.state.metrics[util_name] = int(util_report['gpu_util'])\r\nValueError: invalid literal for int() with base 10: 'N/A'\r\n```\r\n\r\nThere is error handling code above it, but it does not catch the issue (\"N/A\" is returned).\r\n\r\nI assume my GPU does not support it. However, it would be neat to have a graceful failure mode.\r\n\r\nThank you!\r\nAndreas\r\n\r\n## Environment\r\n\r\ntorch 1.5 on a GTX 780 TI (source)\r\nignite 0.3.0 (conda)\r\npynvml 8.0.4 (pip)\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nimport warnings\n\nimport torch\n\nfrom ignite.engine import Events\nfrom ignite.metrics import Metric\n\n\nclass GpuInfo(Metric):\n    \"\"\"Provides GPU information: a) used memory percentage, b) gpu utilization percentage values as Metric\n    on each iterations.\n\n    Examples:\n\n        .. code-block:: python\n\n            # Default GPU measurements\n            GpuInfo().attach(trainer, name='gpu')  # metric names are 'gpu:X mem(%)', 'gpu:X util(%)'\n\n            # Logging with TQDM\n            ProgressBar(persist=True).attach(trainer, metric_names=['gpu:0 mem(%)', 'gpu:0 util(%)'])\n            # Progress bar will looks like\n            # Epoch [2/10]: [12/24]  50%|\u2588\u2588\u2588\u2588\u2588      , gpu:0 mem(%)=79, gpu:0 util(%)=59 [00:17<1:23]\n\n            # Logging with Tensorboard\n            tb_logger.attach(trainer,\n                             log_handler=OutputHandler(tag=\"training\", metric_names='all'),\n                             event_name=Events.ITERATION_COMPLETED)\n    \"\"\"\n\n    def __init__(self):\n        try:\n            import pynvml\n        except ImportError:\n            raise RuntimeError(\n                \"This contrib module requires pynvml to be installed. \"\n                \"Please install it with command: \\n pip install pynvml\"\n            )\n            # Let's check available devices\n        if not torch.cuda.is_available():\n            raise RuntimeError(\"This contrib module requires available GPU\")\n\n        from pynvml.smi import nvidia_smi\n\n        # Let it fail if no libnvidia drivers or NMVL library found\n        self.nvsmi = nvidia_smi.getInstance()\n        super(GpuInfo, self).__init__()\n\n    def reset(self):\n        pass\n\n    def update(self, output):\n        pass\n\n    def compute(self):\n        data = self.nvsmi.DeviceQuery(\"memory.used, memory.total, utilization.gpu\")\n        if len(data) == 0 or (\"gpu\" not in data):\n            warnings.warn(\"No GPU information available\")\n            return []\n        return data[\"gpu\"]\n\n    def completed(self, engine, name):\n        data = self.compute()\n        if len(data) < 1:\n            warnings.warn(\"No GPU information available\")\n            return\n\n        for i, data_by_rank in enumerate(data):\n            mem_name = \"{}:{} mem(%)\".format(name, i)\n\n            if \"fb_memory_usage\" not in data_by_rank:\n                warnings.warn(\"No GPU memory usage information available in {}\".format(data_by_rank))\n                continue\n            mem_report = data_by_rank[\"fb_memory_usage\"]\n            if not (\"used\" in mem_report and \"total\" in mem_report):\n                warnings.warn(\n                    \"GPU memory usage information does not provide used/total \"\n                    \"memory consumption information in {}\".format(mem_report)\n                )\n                continue\n\n            engine.state.metrics[mem_name] = int(mem_report[\"used\"] * 100.0 / mem_report[\"total\"])\n\n        for i, data_by_rank in enumerate(data):\n            util_name = \"{}:{} util(%)\".format(name, i)\n            if \"utilization\" not in data_by_rank:\n                warnings.warn(\"No GPU utilization information available in {}\".format(data_by_rank))\n                continue\n            util_report = data_by_rank[\"utilization\"]\n            if not (\"gpu_util\" in util_report):\n                warnings.warn(\n                    \"GPU utilization information does not provide 'gpu_util' information in \" \"{}\".format(util_report)\n                )\n                continue\n\n            engine.state.metrics[util_name] = int(util_report[\"gpu_util\"])\n\n    def attach(self, engine, name=\"gpu\", event_name=Events.ITERATION_COMPLETED):\n        engine.add_event_handler(event_name, self.completed, name)\n", "path": "ignite/contrib/metrics/gpu_info.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nimport warnings\n\nimport torch\n\nfrom ignite.engine import Events\nfrom ignite.metrics import Metric\n\n\nclass GpuInfo(Metric):\n    \"\"\"Provides GPU information: a) used memory percentage, b) gpu utilization percentage values as Metric\n    on each iterations.\n\n    .. Note ::\n\n        In case if gpu utilization reports \"N/A\" on a given GPU, corresponding metric value is not set.\n\n    Examples:\n\n        .. code-block:: python\n\n            # Default GPU measurements\n            GpuInfo().attach(trainer, name='gpu')  # metric names are 'gpu:X mem(%)', 'gpu:X util(%)'\n\n            # Logging with TQDM\n            ProgressBar(persist=True).attach(trainer, metric_names=['gpu:0 mem(%)', 'gpu:0 util(%)'])\n            # Progress bar will looks like\n            # Epoch [2/10]: [12/24]  50%|\u2588\u2588\u2588\u2588\u2588      , gpu:0 mem(%)=79, gpu:0 util(%)=59 [00:17<1:23]\n\n            # Logging with Tensorboard\n            tb_logger.attach(trainer,\n                             log_handler=OutputHandler(tag=\"training\", metric_names='all'),\n                             event_name=Events.ITERATION_COMPLETED)\n    \"\"\"\n\n    def __init__(self):\n        try:\n            import pynvml\n        except ImportError:\n            raise RuntimeError(\n                \"This contrib module requires pynvml to be installed. \"\n                \"Please install it with command: \\n pip install pynvml\"\n            )\n            # Let's check available devices\n        if not torch.cuda.is_available():\n            raise RuntimeError(\"This contrib module requires available GPU\")\n\n        from pynvml.smi import nvidia_smi\n\n        # Let it fail if no libnvidia drivers or NMVL library found\n        self.nvsmi = nvidia_smi.getInstance()\n        super(GpuInfo, self).__init__()\n\n    def reset(self):\n        pass\n\n    def update(self, output):\n        pass\n\n    def compute(self):\n        data = self.nvsmi.DeviceQuery(\"memory.used, memory.total, utilization.gpu\")\n        if len(data) == 0 or (\"gpu\" not in data):\n            warnings.warn(\"No GPU information available\")\n            return []\n        return data[\"gpu\"]\n\n    def completed(self, engine, name):\n        data = self.compute()\n        if len(data) < 1:\n            warnings.warn(\"No GPU information available\")\n            return\n\n        for i, data_by_rank in enumerate(data):\n            mem_name = \"{}:{} mem(%)\".format(name, i)\n\n            if \"fb_memory_usage\" not in data_by_rank:\n                warnings.warn(\"No GPU memory usage information available in {}\".format(data_by_rank))\n                continue\n            mem_report = data_by_rank[\"fb_memory_usage\"]\n            if not (\"used\" in mem_report and \"total\" in mem_report):\n                warnings.warn(\n                    \"GPU memory usage information does not provide used/total \"\n                    \"memory consumption information in {}\".format(mem_report)\n                )\n                continue\n\n            engine.state.metrics[mem_name] = int(mem_report[\"used\"] * 100.0 / mem_report[\"total\"])\n\n        for i, data_by_rank in enumerate(data):\n            util_name = \"{}:{} util(%)\".format(name, i)\n            if \"utilization\" not in data_by_rank:\n                warnings.warn(\"No GPU utilization information available in {}\".format(data_by_rank))\n                continue\n            util_report = data_by_rank[\"utilization\"]\n            if not (\"gpu_util\" in util_report):\n                warnings.warn(\n                    \"GPU utilization information does not provide 'gpu_util' information in {}\".format(util_report)\n                )\n                continue\n            try:\n                engine.state.metrics[util_name] = int(util_report[\"gpu_util\"])\n            except ValueError:\n                # Do not set GPU utilization information\n                pass\n\n    def attach(self, engine, name=\"gpu\", event_name=Events.ITERATION_COMPLETED):\n        engine.add_event_handler(event_name, self.completed, name)\n", "path": "ignite/contrib/metrics/gpu_info.py"}]}