prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  torchvision sanity check requires a GPU
  #2931 added a sanity check to torchvision, but this requires a GPU to be available when building. We should, instead, check if a GPU is available and only run the sanity check if there is one. If there is no GPU available then we should print a warning instead.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `easybuild/easyblocks/t/torchvision.py`
  Content:
  ```
  1 ##
  2 # Copyright 2021-2023 Ghent University
  3 #
  4 # This file is part of EasyBuild,
  5 # originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
  6 # with support of Ghent University (http://ugent.be/hpc),
  7 # the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
  8 # Flemish Research Foundation (FWO) (http://www.fwo.be/en)
  9 # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
  10 #
  11 # https://github.com/easybuilders/easybuild
  12 #
  13 # EasyBuild is free software: you can redistribute it and/or modify
  14 # it under the terms of the GNU General Public License as published by
  15 # the Free Software Foundation v2.
  16 #
  17 # EasyBuild is distributed in the hope that it will be useful,
  18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20 # GNU General Public License for more details.
  21 #
  22 # You should have received a copy of the GNU General Public License
  23 # along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.
  24 ##
  25 """
  26 EasyBuild support for building and installing torchvision, implemented as an easyblock
  27 
  28 @author: Alexander Grund (TU Dresden)
  29 @author: Kenneth Hoste (HPC-UGent)
  30 """
  31 from easybuild.easyblocks.generic.pythonpackage import PythonPackage, det_pylibdir
  32 from easybuild.tools.build_log import EasyBuildError
  33 from easybuild.tools.config import build_option
  34 from easybuild.tools.modules import get_software_version
  35 import easybuild.tools.environment as env
  36 
  37 
  38 class EB_torchvision(PythonPackage):
  39     """Support for building/installing TorchVison."""
  40 
  41     @staticmethod
  42     def extra_options():
  43         """Change some defaults for easyconfig parameters."""
  44         extra_vars = PythonPackage.extra_options()
  45         extra_vars['use_pip'][0] = True
  46         extra_vars['download_dep_fail'][0] = True
  47         extra_vars['sanity_pip_check'][0] = True
  48         return extra_vars
  49 
  50     def __init__(self, *args, **kwargs):
  51         """Initialize torchvision easyblock."""
  52         super(EB_torchvision, self).__init__(*args, **kwargs)
  53 
  54         dep_names = set(dep['name'] for dep in self.cfg.dependencies())
  55 
  56         # require that PyTorch is listed as dependency
  57         if 'PyTorch' not in dep_names:
  58             raise EasyBuildError('PyTorch not found as a dependency')
  59 
  60         # enable building with GPU support if CUDA is included as dependency
  61         if 'CUDA' in dep_names:
  62             self.with_cuda = True
  63         else:
  64             self.with_cuda = False
  65 
  66     def configure_step(self):
  67         """Set up torchvision config"""
  68 
  69         # Note: Those can be overwritten by e.g. preinstallopts
  70         env.setvar('BUILD_VERSION', self.version)
  71         env.setvar('PYTORCH_VERSION', get_software_version('PyTorch'))
  72 
  73         if self.with_cuda:
  74             # make sure that torchvision is installed with CUDA support by setting $FORCE_CUDA
  75             env.setvar('FORCE_CUDA', '1')
  76             # specify CUDA compute capabilities via $TORCH_CUDA_ARCH_LIST
  77             cuda_cc = self.cfg['cuda_compute_capabilities'] or build_option('cuda_compute_capabilities')
  78             if cuda_cc:
  79                 env.setvar('TORCH_CUDA_ARCH_LIST', ';'.join(cuda_cc))
  80 
  81         super(EB_torchvision, self).configure_step()
  82 
  83     def sanity_check_step(self):
  84         """Custom sanity check for torchvision."""
  85         custom_commands = None
  86         custom_paths = None
  87 
  88         # check whether torchvision was indeed built with CUDA support,
  89         # cfr. https://discuss.pytorch.org/t/notimplementederror-could-not-run-torchvision-nms-with-arguments-from-\
  90         #      the-cuda-backend-this-could-be-because-the-operator-doesnt-exist-for-this-backend/132352/4
  91         if self.with_cuda:
  92             custom_commands = []
  93             python_code = '; '.join([
  94                 "import torch, torchvision",
  95                 "boxes = torch.tensor([[0., 1., 2., 3.]]).to('cuda')",
  96                 "scores = torch.randn(1).to('cuda')",
  97                 "print(torchvision.ops.nms(boxes, scores, 0.5))",
  98             ])
  99             custom_commands.append('python -c "%s"' % python_code)
  100             custom_paths = {
  101                 'files': [],
  102                 'dirs': [det_pylibdir()],
  103             }
  104 
  105         return super(EB_torchvision, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)
  106
  ```
  --- 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/easybuild/easyblocks/t/torchvision.py b/easybuild/easyblocks/t/torchvision.py
  --- a/easybuild/easyblocks/t/torchvision.py
  +++ b/easybuild/easyblocks/t/torchvision.py
  @@ -90,11 +90,12 @@
           #      the-cuda-backend-this-could-be-because-the-operator-doesnt-exist-for-this-backend/132352/4
           if self.with_cuda:
               custom_commands = []
  -            python_code = '; '.join([
  +            python_code = '\n'.join([
                   "import torch, torchvision",
  -                "boxes = torch.tensor([[0., 1., 2., 3.]]).to('cuda')",
  -                "scores = torch.randn(1).to('cuda')",
  -                "print(torchvision.ops.nms(boxes, scores, 0.5))",
  +                "if torch.cuda.device_count():",
  +                "    boxes = torch.tensor([[0., 1., 2., 3.]]).to('cuda')",
  +                "    scores = torch.randn(1).to('cuda')",
  +                "    print(torchvision.ops.nms(boxes, scores, 0.5))",
               ])
               custom_commands.append('python -c "%s"' % python_code)
               custom_paths = {
  
verification_info: {"golden_diff": "diff --git a/easybuild/easyblocks/t/torchvision.py b/easybuild/easyblocks/t/torchvision.py\n--- a/easybuild/easyblocks/t/torchvision.py\n+++ b/easybuild/easyblocks/t/torchvision.py\n@@ -90,11 +90,12 @@\n         #      the-cuda-backend-this-could-be-because-the-operator-doesnt-exist-for-this-backend/132352/4\n         if self.with_cuda:\n             custom_commands = []\n-            python_code = '; '.join([\n+            python_code = '\\n'.join([\n                 \"import torch, torchvision\",\n-                \"boxes = torch.tensor([[0., 1., 2., 3.]]).to('cuda')\",\n-                \"scores = torch.randn(1).to('cuda')\",\n-                \"print(torchvision.ops.nms(boxes, scores, 0.5))\",\n+                \"if torch.cuda.device_count():\",\n+                \"    boxes = torch.tensor([[0., 1., 2., 3.]]).to('cuda')\",\n+                \"    scores = torch.randn(1).to('cuda')\",\n+                \"    print(torchvision.ops.nms(boxes, scores, 0.5))\",\n             ])\n             custom_commands.append('python -c \"%s\"' % python_code)\n             custom_paths = {\n", "issue": "torchvision sanity check requires a GPU\n#2931 added a sanity check to torchvision, but this requires a GPU to be available when building. We should, instead, check if a GPU is available and only run the sanity check if there is one. If there is no GPU available then we should print a warning instead.\n", "before_files": [{"content": "##\n# Copyright 2021-2023 Ghent University\n#\n# This file is part of EasyBuild,\n# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),\n# with support of Ghent University (http://ugent.be/hpc),\n# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),\n# Flemish Research Foundation (FWO) (http://www.fwo.be/en)\n# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).\n#\n# https://github.com/easybuilders/easybuild\n#\n# EasyBuild is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation v2.\n#\n# EasyBuild is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.\n##\n\"\"\"\nEasyBuild support for building and installing torchvision, implemented as an easyblock\n\n@author: Alexander Grund (TU Dresden)\n@author: Kenneth Hoste (HPC-UGent)\n\"\"\"\nfrom easybuild.easyblocks.generic.pythonpackage import PythonPackage, det_pylibdir\nfrom easybuild.tools.build_log import EasyBuildError\nfrom easybuild.tools.config import build_option\nfrom easybuild.tools.modules import get_software_version\nimport easybuild.tools.environment as env\n\n\nclass EB_torchvision(PythonPackage):\n    \"\"\"Support for building/installing TorchVison.\"\"\"\n\n    @staticmethod\n    def extra_options():\n        \"\"\"Change some defaults for easyconfig parameters.\"\"\"\n        extra_vars = PythonPackage.extra_options()\n        extra_vars['use_pip'][0] = True\n        extra_vars['download_dep_fail'][0] = True\n        extra_vars['sanity_pip_check'][0] = True\n        return extra_vars\n\n    def __init__(self, *args, **kwargs):\n        \"\"\"Initialize torchvision easyblock.\"\"\"\n        super(EB_torchvision, self).__init__(*args, **kwargs)\n\n        dep_names = set(dep['name'] for dep in self.cfg.dependencies())\n\n        # require that PyTorch is listed as dependency\n        if 'PyTorch' not in dep_names:\n            raise EasyBuildError('PyTorch not found as a dependency')\n\n        # enable building with GPU support if CUDA is included as dependency\n        if 'CUDA' in dep_names:\n            self.with_cuda = True\n        else:\n            self.with_cuda = False\n\n    def configure_step(self):\n        \"\"\"Set up torchvision config\"\"\"\n\n        # Note: Those can be overwritten by e.g. preinstallopts\n        env.setvar('BUILD_VERSION', self.version)\n        env.setvar('PYTORCH_VERSION', get_software_version('PyTorch'))\n\n        if self.with_cuda:\n            # make sure that torchvision is installed with CUDA support by setting $FORCE_CUDA\n            env.setvar('FORCE_CUDA', '1')\n            # specify CUDA compute capabilities via $TORCH_CUDA_ARCH_LIST\n            cuda_cc = self.cfg['cuda_compute_capabilities'] or build_option('cuda_compute_capabilities')\n            if cuda_cc:\n                env.setvar('TORCH_CUDA_ARCH_LIST', ';'.join(cuda_cc))\n\n        super(EB_torchvision, self).configure_step()\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for torchvision.\"\"\"\n        custom_commands = None\n        custom_paths = None\n\n        # check whether torchvision was indeed built with CUDA support,\n        # cfr. https://discuss.pytorch.org/t/notimplementederror-could-not-run-torchvision-nms-with-arguments-from-\\\n        #      the-cuda-backend-this-could-be-because-the-operator-doesnt-exist-for-this-backend/132352/4\n        if self.with_cuda:\n            custom_commands = []\n            python_code = '; '.join([\n                \"import torch, torchvision\",\n                \"boxes = torch.tensor([[0., 1., 2., 3.]]).to('cuda')\",\n                \"scores = torch.randn(1).to('cuda')\",\n                \"print(torchvision.ops.nms(boxes, scores, 0.5))\",\n            ])\n            custom_commands.append('python -c \"%s\"' % python_code)\n            custom_paths = {\n                'files': [],\n                'dirs': [det_pylibdir()],\n            }\n\n        return super(EB_torchvision, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)\n", "path": "easybuild/easyblocks/t/torchvision.py"}], "after_files": [{"content": "##\n# Copyright 2021-2023 Ghent University\n#\n# This file is part of EasyBuild,\n# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),\n# with support of Ghent University (http://ugent.be/hpc),\n# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),\n# Flemish Research Foundation (FWO) (http://www.fwo.be/en)\n# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).\n#\n# https://github.com/easybuilders/easybuild\n#\n# EasyBuild is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation v2.\n#\n# EasyBuild is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.\n##\n\"\"\"\nEasyBuild support for building and installing torchvision, implemented as an easyblock\n\n@author: Alexander Grund (TU Dresden)\n@author: Kenneth Hoste (HPC-UGent)\n\"\"\"\nfrom easybuild.easyblocks.generic.pythonpackage import PythonPackage, det_pylibdir\nfrom easybuild.tools.build_log import EasyBuildError\nfrom easybuild.tools.config import build_option\nfrom easybuild.tools.modules import get_software_version\nimport easybuild.tools.environment as env\n\n\nclass EB_torchvision(PythonPackage):\n    \"\"\"Support for building/installing TorchVison.\"\"\"\n\n    @staticmethod\n    def extra_options():\n        \"\"\"Change some defaults for easyconfig parameters.\"\"\"\n        extra_vars = PythonPackage.extra_options()\n        extra_vars['use_pip'][0] = True\n        extra_vars['download_dep_fail'][0] = True\n        extra_vars['sanity_pip_check'][0] = True\n        return extra_vars\n\n    def __init__(self, *args, **kwargs):\n        \"\"\"Initialize torchvision easyblock.\"\"\"\n        super(EB_torchvision, self).__init__(*args, **kwargs)\n\n        dep_names = set(dep['name'] for dep in self.cfg.dependencies())\n\n        # require that PyTorch is listed as dependency\n        if 'PyTorch' not in dep_names:\n            raise EasyBuildError('PyTorch not found as a dependency')\n\n        # enable building with GPU support if CUDA is included as dependency\n        if 'CUDA' in dep_names:\n            self.with_cuda = True\n        else:\n            self.with_cuda = False\n\n    def configure_step(self):\n        \"\"\"Set up torchvision config\"\"\"\n\n        # Note: Those can be overwritten by e.g. preinstallopts\n        env.setvar('BUILD_VERSION', self.version)\n        env.setvar('PYTORCH_VERSION', get_software_version('PyTorch'))\n\n        if self.with_cuda:\n            # make sure that torchvision is installed with CUDA support by setting $FORCE_CUDA\n            env.setvar('FORCE_CUDA', '1')\n            # specify CUDA compute capabilities via $TORCH_CUDA_ARCH_LIST\n            cuda_cc = self.cfg['cuda_compute_capabilities'] or build_option('cuda_compute_capabilities')\n            if cuda_cc:\n                env.setvar('TORCH_CUDA_ARCH_LIST', ';'.join(cuda_cc))\n\n        super(EB_torchvision, self).configure_step()\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for torchvision.\"\"\"\n        custom_commands = None\n        custom_paths = None\n\n        # check whether torchvision was indeed built with CUDA support,\n        # cfr. https://discuss.pytorch.org/t/notimplementederror-could-not-run-torchvision-nms-with-arguments-from-\\\n        #      the-cuda-backend-this-could-be-because-the-operator-doesnt-exist-for-this-backend/132352/4\n        if self.with_cuda:\n            custom_commands = []\n            python_code = '\\n'.join([\n                \"import torch, torchvision\",\n                \"if torch.cuda.device_count():\",\n                \"    boxes = torch.tensor([[0., 1., 2., 3.]]).to('cuda')\",\n                \"    scores = torch.randn(1).to('cuda')\",\n                \"    print(torchvision.ops.nms(boxes, scores, 0.5))\",\n            ])\n            custom_commands.append('python -c \"%s\"' % python_code)\n            custom_paths = {\n                'files': [],\n                'dirs': [det_pylibdir()],\n            }\n\n        return super(EB_torchvision, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)\n", "path": "easybuild/easyblocks/t/torchvision.py"}]}