prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Patch MNIST dataset downloading to fix CI
  Currently, there is an issue with downloading MNIST dataset using torchvision. Let's introduce the following patch to our CI to fix it:
  - https://github.com/pytorch/vision/issues/3500#issuecomment-790491487
  
  Where to put that:
  - create new step with the patch before [here](https://github.com/pytorch/ignite/blob/700f0e1325efc5dc0dce88d26284e51bc2a7c87c/.github/workflows/unit-tests.yml#L106)
  - add patch [here](https://github.com/pytorch/ignite/blob/700f0e1325efc5dc0dce88d26284e51bc2a7c87c/.circleci/config.yml#L147).
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `examples/mnist/mnist_patch.py`
  Content:
  ```
  1 """Patch to fix MNIST download issue as described here:
  2 - https://github.com/pytorch/ignite/issues/1737
  3 - https://github.com/pytorch/vision/issues/3500
  4 """
  5 
  6 import os
  7 import subprocess as sp
  8 
  9 import torch
  10 from torchvision.datasets.mnist import MNIST, read_image_file, read_label_file
  11 from torchvision.datasets.utils import extract_archive
  12 
  13 
  14 def patched_download(self):
  15     """wget patched download method.
  16     """
  17     if self._check_exists():
  18         return
  19 
  20     os.makedirs(self.raw_folder, exist_ok=True)
  21     os.makedirs(self.processed_folder, exist_ok=True)
  22 
  23     # download files
  24     for url, md5 in self.resources:
  25         filename = url.rpartition("/")[2]
  26         download_root = os.path.expanduser(self.raw_folder)
  27         extract_root = None
  28         remove_finished = False
  29 
  30         if extract_root is None:
  31             extract_root = download_root
  32         if not filename:
  33             filename = os.path.basename(url)
  34 
  35         # Use wget to download archives
  36         sp.run(["wget", url, "-P", download_root])
  37 
  38         archive = os.path.join(download_root, filename)
  39         print("Extracting {} to {}".format(archive, extract_root))
  40         extract_archive(archive, extract_root, remove_finished)
  41 
  42     # process and save as torch files
  43     print("Processing...")
  44 
  45     training_set = (
  46         read_image_file(os.path.join(self.raw_folder, "train-images-idx3-ubyte")),
  47         read_label_file(os.path.join(self.raw_folder, "train-labels-idx1-ubyte")),
  48     )
  49     test_set = (
  50         read_image_file(os.path.join(self.raw_folder, "t10k-images-idx3-ubyte")),
  51         read_label_file(os.path.join(self.raw_folder, "t10k-labels-idx1-ubyte")),
  52     )
  53     with open(os.path.join(self.processed_folder, self.training_file), "wb") as f:
  54         torch.save(training_set, f)
  55     with open(os.path.join(self.processed_folder, self.test_file), "wb") as f:
  56         torch.save(test_set, f)
  57 
  58     print("Done!")
  59 
  60 
  61 def main():
  62     # Patch download method
  63     MNIST.download = patched_download
  64     # Download MNIST
  65     MNIST(".", download=True)
  66 
  67 
  68 if __name__ == "__main__":
  69     main()
  70
  ```
  --- 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/examples/mnist/mnist_patch.py b/examples/mnist/mnist_patch.py
  deleted file mode 100644
  --- a/examples/mnist/mnist_patch.py
  +++ /dev/null
  @@ -1,69 +0,0 @@
  -"""Patch to fix MNIST download issue as described here:
  -- https://github.com/pytorch/ignite/issues/1737
  -- https://github.com/pytorch/vision/issues/3500
  -"""
  -
  -import os
  -import subprocess as sp
  -
  -import torch
  -from torchvision.datasets.mnist import MNIST, read_image_file, read_label_file
  -from torchvision.datasets.utils import extract_archive
  -
  -
  -def patched_download(self):
  -    """wget patched download method.
  -    """
  -    if self._check_exists():
  -        return
  -
  -    os.makedirs(self.raw_folder, exist_ok=True)
  -    os.makedirs(self.processed_folder, exist_ok=True)
  -
  -    # download files
  -    for url, md5 in self.resources:
  -        filename = url.rpartition("/")[2]
  -        download_root = os.path.expanduser(self.raw_folder)
  -        extract_root = None
  -        remove_finished = False
  -
  -        if extract_root is None:
  -            extract_root = download_root
  -        if not filename:
  -            filename = os.path.basename(url)
  -
  -        # Use wget to download archives
  -        sp.run(["wget", url, "-P", download_root])
  -
  -        archive = os.path.join(download_root, filename)
  -        print("Extracting {} to {}".format(archive, extract_root))
  -        extract_archive(archive, extract_root, remove_finished)
  -
  -    # process and save as torch files
  -    print("Processing...")
  -
  -    training_set = (
  -        read_image_file(os.path.join(self.raw_folder, "train-images-idx3-ubyte")),
  -        read_label_file(os.path.join(self.raw_folder, "train-labels-idx1-ubyte")),
  -    )
  -    test_set = (
  -        read_image_file(os.path.join(self.raw_folder, "t10k-images-idx3-ubyte")),
  -        read_label_file(os.path.join(self.raw_folder, "t10k-labels-idx1-ubyte")),
  -    )
  -    with open(os.path.join(self.processed_folder, self.training_file), "wb") as f:
  -        torch.save(training_set, f)
  -    with open(os.path.join(self.processed_folder, self.test_file), "wb") as f:
  -        torch.save(test_set, f)
  -
  -    print("Done!")
  -
  -
  -def main():
  -    # Patch download method
  -    MNIST.download = patched_download
  -    # Download MNIST
  -    MNIST(".", download=True)
  -
  -
  -if __name__ == "__main__":
  -    main()
  
verification_info: {"golden_diff": "diff --git a/examples/mnist/mnist_patch.py b/examples/mnist/mnist_patch.py\ndeleted file mode 100644\n--- a/examples/mnist/mnist_patch.py\n+++ /dev/null\n@@ -1,69 +0,0 @@\n-\"\"\"Patch to fix MNIST download issue as described here:\n-- https://github.com/pytorch/ignite/issues/1737\n-- https://github.com/pytorch/vision/issues/3500\n-\"\"\"\n-\n-import os\n-import subprocess as sp\n-\n-import torch\n-from torchvision.datasets.mnist import MNIST, read_image_file, read_label_file\n-from torchvision.datasets.utils import extract_archive\n-\n-\n-def patched_download(self):\n-    \"\"\"wget patched download method.\n-    \"\"\"\n-    if self._check_exists():\n-        return\n-\n-    os.makedirs(self.raw_folder, exist_ok=True)\n-    os.makedirs(self.processed_folder, exist_ok=True)\n-\n-    # download files\n-    for url, md5 in self.resources:\n-        filename = url.rpartition(\"/\")[2]\n-        download_root = os.path.expanduser(self.raw_folder)\n-        extract_root = None\n-        remove_finished = False\n-\n-        if extract_root is None:\n-            extract_root = download_root\n-        if not filename:\n-            filename = os.path.basename(url)\n-\n-        # Use wget to download archives\n-        sp.run([\"wget\", url, \"-P\", download_root])\n-\n-        archive = os.path.join(download_root, filename)\n-        print(\"Extracting {} to {}\".format(archive, extract_root))\n-        extract_archive(archive, extract_root, remove_finished)\n-\n-    # process and save as torch files\n-    print(\"Processing...\")\n-\n-    training_set = (\n-        read_image_file(os.path.join(self.raw_folder, \"train-images-idx3-ubyte\")),\n-        read_label_file(os.path.join(self.raw_folder, \"train-labels-idx1-ubyte\")),\n-    )\n-    test_set = (\n-        read_image_file(os.path.join(self.raw_folder, \"t10k-images-idx3-ubyte\")),\n-        read_label_file(os.path.join(self.raw_folder, \"t10k-labels-idx1-ubyte\")),\n-    )\n-    with open(os.path.join(self.processed_folder, self.training_file), \"wb\") as f:\n-        torch.save(training_set, f)\n-    with open(os.path.join(self.processed_folder, self.test_file), \"wb\") as f:\n-        torch.save(test_set, f)\n-\n-    print(\"Done!\")\n-\n-\n-def main():\n-    # Patch download method\n-    MNIST.download = patched_download\n-    # Download MNIST\n-    MNIST(\".\", download=True)\n-\n-\n-if __name__ == \"__main__\":\n-    main()\n", "issue": "Patch MNIST dataset downloading to fix CI\nCurrently, there is an issue with downloading MNIST dataset using torchvision. Let's introduce the following patch to our CI to fix it:\r\n- https://github.com/pytorch/vision/issues/3500#issuecomment-790491487\r\n\r\nWhere to put that:\r\n- create new step with the patch before [here](https://github.com/pytorch/ignite/blob/700f0e1325efc5dc0dce88d26284e51bc2a7c87c/.github/workflows/unit-tests.yml#L106)\r\n- add patch [here](https://github.com/pytorch/ignite/blob/700f0e1325efc5dc0dce88d26284e51bc2a7c87c/.circleci/config.yml#L147).\n", "before_files": [{"content": "\"\"\"Patch to fix MNIST download issue as described here:\n- https://github.com/pytorch/ignite/issues/1737\n- https://github.com/pytorch/vision/issues/3500\n\"\"\"\n\nimport os\nimport subprocess as sp\n\nimport torch\nfrom torchvision.datasets.mnist import MNIST, read_image_file, read_label_file\nfrom torchvision.datasets.utils import extract_archive\n\n\ndef patched_download(self):\n    \"\"\"wget patched download method.\n    \"\"\"\n    if self._check_exists():\n        return\n\n    os.makedirs(self.raw_folder, exist_ok=True)\n    os.makedirs(self.processed_folder, exist_ok=True)\n\n    # download files\n    for url, md5 in self.resources:\n        filename = url.rpartition(\"/\")[2]\n        download_root = os.path.expanduser(self.raw_folder)\n        extract_root = None\n        remove_finished = False\n\n        if extract_root is None:\n            extract_root = download_root\n        if not filename:\n            filename = os.path.basename(url)\n\n        # Use wget to download archives\n        sp.run([\"wget\", url, \"-P\", download_root])\n\n        archive = os.path.join(download_root, filename)\n        print(\"Extracting {} to {}\".format(archive, extract_root))\n        extract_archive(archive, extract_root, remove_finished)\n\n    # process and save as torch files\n    print(\"Processing...\")\n\n    training_set = (\n        read_image_file(os.path.join(self.raw_folder, \"train-images-idx3-ubyte\")),\n        read_label_file(os.path.join(self.raw_folder, \"train-labels-idx1-ubyte\")),\n    )\n    test_set = (\n        read_image_file(os.path.join(self.raw_folder, \"t10k-images-idx3-ubyte\")),\n        read_label_file(os.path.join(self.raw_folder, \"t10k-labels-idx1-ubyte\")),\n    )\n    with open(os.path.join(self.processed_folder, self.training_file), \"wb\") as f:\n        torch.save(training_set, f)\n    with open(os.path.join(self.processed_folder, self.test_file), \"wb\") as f:\n        torch.save(test_set, f)\n\n    print(\"Done!\")\n\n\ndef main():\n    # Patch download method\n    MNIST.download = patched_download\n    # Download MNIST\n    MNIST(\".\", download=True)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "examples/mnist/mnist_patch.py"}], "after_files": [{"content": null, "path": "examples/mnist/mnist_patch.py"}]}