We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Docker build fails on pytorch master since Aug 15, 2019 with "AssertionError: Found no NVIDIA driver on your system"
Pytorch recently added a CUDA architecture check when building with torch.utils.cpp_extension. From the [commit notes](https://github.com/pytorch/pytorch/commit/cd207737017db8c81584763207df20bc6110ed75):

> The old behavior was to always use `sm_30`. The new behavior is:
> - For building via a setup.py, check if `'arch'` is in `extra_compile_args`.  If so, don't change anything.
> - If `TORCH_CUDA_ARCH_LIST` is set, respect that (can be 1 or more arches)
> - Otherwise, query device capability and use that.

Following this commit, when attempting to install apex via nvidia-docker, pytorch reverts to querying device capability and fails. The issue probably should be addressed in apex's setup.py, if not nvidia-docker/pytorch themselves. Currently, I work around the issue by setting the environment variable in the dockerfile, eg:

`ENV TORCH_CUDA_ARCH_LIST=Volta;Turing;Kepler+Tesla`
`RUN pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" apex/` 



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 import torch
2 from setuptools import setup, find_packages
3 import subprocess
4 
5 from pip._internal import main as pipmain
6 import sys
7 import warnings
8 
9 if not torch.cuda.is_available():
10     print("\nWarning: Torch did not find available GPUs on this system.\n",
11           "If your intention is to cross-compile, this is not an error.\n")
12 
13 print("torch.__version__  = ", torch.__version__)
14 TORCH_MAJOR = int(torch.__version__.split('.')[0])
15 TORCH_MINOR = int(torch.__version__.split('.')[1])
16 
17 if TORCH_MAJOR == 0 and TORCH_MINOR < 4:
18       raise RuntimeError("Apex requires Pytorch 0.4 or newer.\n" +
19                          "The latest stable release can be obtained from https://pytorch.org/")
20 
21 cmdclass = {}
22 ext_modules = []
23 
24 if "--pyprof" in sys.argv:
25     with open('requirements.txt') as f:
26         required_packages = f.read().splitlines()
27         pipmain(["install"] + required_packages)
28     try:
29         sys.argv.remove("--pyprof")
30     except:
31         pass
32 else:
33     warnings.warn("Option --pyprof not specified. Not installing PyProf dependencies!")
34 
35 if "--cpp_ext" in sys.argv or "--cuda_ext" in sys.argv:
36     if TORCH_MAJOR == 0:
37         raise RuntimeError("--cpp_ext requires Pytorch 1.0 or later, "
38                            "found torch.__version__ = {}".format(torch.__version__))
39     from torch.utils.cpp_extension import BuildExtension
40     cmdclass['build_ext'] = BuildExtension
41 
42 if "--cpp_ext" in sys.argv:
43     from torch.utils.cpp_extension import CppExtension
44     sys.argv.remove("--cpp_ext")
45     ext_modules.append(
46         CppExtension('apex_C',
47                      ['csrc/flatten_unflatten.cpp',]))
48 
49 def check_cuda_torch_binary_vs_bare_metal(cuda_dir):
50     raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], universal_newlines=True)
51     output = raw_output.split()
52     release_idx = output.index("release") + 1
53     release = output[release_idx].split(".")
54     bare_metal_major = release[0]
55     bare_metal_minor = release[1][0]
56     torch_binary_major = torch.version.cuda.split(".")[0]
57     torch_binary_minor = torch.version.cuda.split(".")[1]
58 
59     print("\nCompiling cuda extensions with")
60     print(raw_output + "from " + cuda_dir + "/bin\n")
61 
62     if (bare_metal_major != torch_binary_major) or (bare_metal_minor != torch_binary_minor):
63         raise RuntimeError("Cuda extensions are being compiled with a version of Cuda that does " +
64                            "not match the version used to compile Pytorch binaries.  " +
65                            "Pytorch binaries were compiled with Cuda {}.\n".format(torch.version.cuda) +
66                            "In some cases, a minor-version mismatch will not cause later errors:  " +
67                            "https://github.com/NVIDIA/apex/pull/323#discussion_r287021798.  "
68                            "You can try commenting out this check (at your own risk).")
69 
70 # Set up macros for forward/backward compatibility hack around
71 # https://github.com/pytorch/pytorch/commit/4404762d7dd955383acee92e6f06b48144a0742e
72 # and
73 # https://github.com/NVIDIA/apex/issues/456
74 # https://github.com/pytorch/pytorch/commit/eb7b39e02f7d75c26d8a795ea8c7fd911334da7e#diff-4632522f237f1e4e728cb824300403ac
75 version_ge_1_1 = []
76 if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 0):
77     version_ge_1_1 = ['-DVERSION_GE_1_1']
78 version_ge_1_3 = []
79 if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 2):
80     version_ge_1_3 = ['-DVERSION_GE_1_3']
81 version_dependent_macros = version_ge_1_1 + version_ge_1_3
82 
83 if "--cuda_ext" in sys.argv:
84     from torch.utils.cpp_extension import CUDAExtension
85     sys.argv.remove("--cuda_ext")
86 
87     if torch.utils.cpp_extension.CUDA_HOME is None:
88         raise RuntimeError("--cuda_ext was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.")
89     else:
90         check_cuda_torch_binary_vs_bare_metal(torch.utils.cpp_extension.CUDA_HOME)
91 
92         ext_modules.append(
93             CUDAExtension(name='amp_C',
94                           sources=['csrc/amp_C_frontend.cpp',
95                                    'csrc/multi_tensor_sgd_kernel.cu',
96                                    'csrc/multi_tensor_scale_kernel.cu',
97                                    'csrc/multi_tensor_axpby_kernel.cu',
98                                    'csrc/multi_tensor_l2norm_kernel.cu',
99                                    'csrc/multi_tensor_lamb_stage_1.cu',
100                                    'csrc/multi_tensor_lamb_stage_2.cu',
101                                    'csrc/multi_tensor_adam.cu',
102                                    'csrc/multi_tensor_novograd.cu',
103                                    'csrc/multi_tensor_lamb.cu'],
104                           extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,
105                                               'nvcc':['-lineinfo',
106                                                       '-O3',
107                                                       # '--resource-usage',
108                                                       '--use_fast_math'] + version_dependent_macros}))
109         ext_modules.append(
110             CUDAExtension(name='fused_adam_cuda',
111                           sources=['csrc/fused_adam_cuda.cpp',
112                                    'csrc/fused_adam_cuda_kernel.cu'],
113                           extra_compile_args={'cxx': ['-O3',] + version_dependent_macros,
114                                               'nvcc':['-O3',
115                                                       '--use_fast_math'] + version_dependent_macros}))
116         ext_modules.append(
117             CUDAExtension(name='syncbn',
118                           sources=['csrc/syncbn.cpp',
119                                    'csrc/welford.cu'],
120                           extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,
121                                               'nvcc':['-O3'] + version_dependent_macros}))
122 
123         ext_modules.append(
124             CUDAExtension(name='fused_layer_norm_cuda',
125                           sources=['csrc/layer_norm_cuda.cpp',
126                                    'csrc/layer_norm_cuda_kernel.cu'],
127                           extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,
128                                               'nvcc':['-maxrregcount=50',
129                                                       '-O3',
130                                                       '--use_fast_math'] + version_dependent_macros}))
131 
132 if "--bnp" in sys.argv:
133     from torch.utils.cpp_extension import CUDAExtension
134     sys.argv.remove("--bnp")
135 
136     from torch.utils.cpp_extension import BuildExtension
137     cmdclass['build_ext'] = BuildExtension
138 
139     if torch.utils.cpp_extension.CUDA_HOME is None:
140         raise RuntimeError("--bnp was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.")
141     else:
142         ext_modules.append(
143             CUDAExtension(name='bnp',
144                           sources=['apex/contrib/csrc/groupbn/batch_norm.cu',
145                                    'apex/contrib/csrc/groupbn/ipc.cu',
146                                    'apex/contrib/csrc/groupbn/interface.cpp',
147                                    'apex/contrib/csrc/groupbn/batch_norm_add_relu.cu'],
148                           include_dirs=['csrc'],
149                           extra_compile_args={'cxx': [] + version_dependent_macros,
150                                               'nvcc':['-DCUDA_HAS_FP16=1',
151                                                       '-D__CUDA_NO_HALF_OPERATORS__',
152                                                       '-D__CUDA_NO_HALF_CONVERSIONS__',
153                                                       '-D__CUDA_NO_HALF2_OPERATORS__',
154                                                       '-gencode',
155                                                       'arch=compute_70,code=sm_70'] + version_dependent_macros}))
156 
157 if "--xentropy" in sys.argv:
158     from torch.utils.cpp_extension import CUDAExtension
159     sys.argv.remove("--xentropy")
160 
161     from torch.utils.cpp_extension import BuildExtension
162     cmdclass['build_ext'] = BuildExtension
163 
164     if torch.utils.cpp_extension.CUDA_HOME is None:
165         raise RuntimeError("--xentropy was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.")
166     else:
167         ext_modules.append(
168             CUDAExtension(name='xentropy_cuda',
169                           sources=['apex/contrib/csrc/xentropy/interface.cpp',
170                                    'apex/contrib/csrc/xentropy/xentropy_kernel.cu'],
171                           include_dirs=['csrc'],
172                           extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,
173                                               'nvcc':['-O3'] + version_dependent_macros}))
174 
175 setup(
176     name='apex',
177     version='0.1',
178     packages=find_packages(exclude=('build',
179                                     'csrc',
180                                     'include',
181                                     'tests',
182                                     'dist',
183                                     'docs',
184                                     'tests',
185                                     'examples',
186                                     'apex.egg-info',)),
187     description='PyTorch Extensions written by NVIDIA',
188     ext_modules=ext_modules,
189     cmdclass=cmdclass,
190 )
191
```
--- 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/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -5,10 +5,20 @@
 from pip._internal import main as pipmain
 import sys
 import warnings
+import os
 
 if not torch.cuda.is_available():
-    print("\nWarning: Torch did not find available GPUs on this system.\n",
-          "If your intention is to cross-compile, this is not an error.\n")
+    # https://github.com/NVIDIA/apex/issues/486
+    # Extension builds after https://github.com/pytorch/pytorch/pull/23408 attempt to query torch.cuda.get_device_capability(),
+    # which will fail if you are compiling in an environment without visible GPUs (e.g. during an nvidia-docker build command).
+    print('\nWarning: Torch did not find available GPUs on this system.\n',
+          'If your intention is to cross-compile, this is not an error.\n'
+          'By default, Apex will cross-compile for Pascal (compute capabilities 6.0, 6.1, 6.2),\n'
+          'Volta (compute capability 7.0), and Turing (compute capability 7.5).\n'
+          'If you wish to cross-compile for a single specific architecture,\n'
+          'export TORCH_CUDA_ARCH_LIST="compute capability" before running setup.py.\n')
+    if os.environ.get("TORCH_CUDA_ARCH_LIST", None) is None:
+        os.environ["TORCH_CUDA_ARCH_LIST"] = "6.0;6.1;6.2;7.0;7.5"
 
 print("torch.__version__  = ", torch.__version__)
 TORCH_MAJOR = int(torch.__version__.split('.')[0])

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -5,10 +5,20 @@\n from pip._internal import main as pipmain\n import sys\n import warnings\n+import os\n \n if not torch.cuda.is_available():\n-    print(\"\\nWarning: Torch did not find available GPUs on this system.\\n\",\n-          \"If your intention is to cross-compile, this is not an error.\\n\")\n+    # https://github.com/NVIDIA/apex/issues/486\n+    # Extension builds after https://github.com/pytorch/pytorch/pull/23408 attempt to query torch.cuda.get_device_capability(),\n+    # which will fail if you are compiling in an environment without visible GPUs (e.g. during an nvidia-docker build command).\n+    print('\\nWarning: Torch did not find available GPUs on this system.\\n',\n+          'If your intention is to cross-compile, this is not an error.\\n'\n+          'By default, Apex will cross-compile for Pascal (compute capabilities 6.0, 6.1, 6.2),\\n'\n+          'Volta (compute capability 7.0), and Turing (compute capability 7.5).\\n'\n+          'If you wish to cross-compile for a single specific architecture,\\n'\n+          'export TORCH_CUDA_ARCH_LIST=\"compute capability\" before running setup.py.\\n')\n+    if os.environ.get(\"TORCH_CUDA_ARCH_LIST\", None) is None:\n+        os.environ[\"TORCH_CUDA_ARCH_LIST\"] = \"6.0;6.1;6.2;7.0;7.5\"\n \n print(\"torch.__version__  = \", torch.__version__)\n TORCH_MAJOR = int(torch.__version__.split('.')[0])\n", "issue": "Docker build fails on pytorch master since Aug 15, 2019 with \"AssertionError: Found no NVIDIA driver on your system\"\nPytorch recently added a CUDA architecture check when building with torch.utils.cpp_extension. From the [commit notes](https://github.com/pytorch/pytorch/commit/cd207737017db8c81584763207df20bc6110ed75):\r\n\r\n> The old behavior was to always use `sm_30`. The new behavior is:\r\n> - For building via a setup.py, check if `'arch'` is in `extra_compile_args`.  If so, don't change anything.\r\n> - If `TORCH_CUDA_ARCH_LIST` is set, respect that (can be 1 or more arches)\r\n> - Otherwise, query device capability and use that.\r\n\r\nFollowing this commit, when attempting to install apex via nvidia-docker, pytorch reverts to querying device capability and fails. The issue probably should be addressed in apex's setup.py, if not nvidia-docker/pytorch themselves. Currently, I work around the issue by setting the environment variable in the dockerfile, eg:\r\n\r\n`ENV TORCH_CUDA_ARCH_LIST=Volta;Turing;Kepler+Tesla`\r\n`RUN pip install -v --no-cache-dir --global-option=\"--cpp_ext\" --global-option=\"--cuda_ext\" apex/` \r\n\r\n\n", "before_files": [{"content": "import torch\nfrom setuptools import setup, find_packages\nimport subprocess\n\nfrom pip._internal import main as pipmain\nimport sys\nimport warnings\n\nif not torch.cuda.is_available():\n    print(\"\\nWarning: Torch did not find available GPUs on this system.\\n\",\n          \"If your intention is to cross-compile, this is not an error.\\n\")\n\nprint(\"torch.__version__  = \", torch.__version__)\nTORCH_MAJOR = int(torch.__version__.split('.')[0])\nTORCH_MINOR = int(torch.__version__.split('.')[1])\n\nif TORCH_MAJOR == 0 and TORCH_MINOR < 4:\n      raise RuntimeError(\"Apex requires Pytorch 0.4 or newer.\\n\" +\n                         \"The latest stable release can be obtained from https://pytorch.org/\")\n\ncmdclass = {}\next_modules = []\n\nif \"--pyprof\" in sys.argv:\n    with open('requirements.txt') as f:\n        required_packages = f.read().splitlines()\n        pipmain([\"install\"] + required_packages)\n    try:\n        sys.argv.remove(\"--pyprof\")\n    except:\n        pass\nelse:\n    warnings.warn(\"Option --pyprof not specified. Not installing PyProf dependencies!\")\n\nif \"--cpp_ext\" in sys.argv or \"--cuda_ext\" in sys.argv:\n    if TORCH_MAJOR == 0:\n        raise RuntimeError(\"--cpp_ext requires Pytorch 1.0 or later, \"\n                           \"found torch.__version__ = {}\".format(torch.__version__))\n    from torch.utils.cpp_extension import BuildExtension\n    cmdclass['build_ext'] = BuildExtension\n\nif \"--cpp_ext\" in sys.argv:\n    from torch.utils.cpp_extension import CppExtension\n    sys.argv.remove(\"--cpp_ext\")\n    ext_modules.append(\n        CppExtension('apex_C',\n                     ['csrc/flatten_unflatten.cpp',]))\n\ndef check_cuda_torch_binary_vs_bare_metal(cuda_dir):\n    raw_output = subprocess.check_output([cuda_dir + \"/bin/nvcc\", \"-V\"], universal_newlines=True)\n    output = raw_output.split()\n    release_idx = output.index(\"release\") + 1\n    release = output[release_idx].split(\".\")\n    bare_metal_major = release[0]\n    bare_metal_minor = release[1][0]\n    torch_binary_major = torch.version.cuda.split(\".\")[0]\n    torch_binary_minor = torch.version.cuda.split(\".\")[1]\n\n    print(\"\\nCompiling cuda extensions with\")\n    print(raw_output + \"from \" + cuda_dir + \"/bin\\n\")\n\n    if (bare_metal_major != torch_binary_major) or (bare_metal_minor != torch_binary_minor):\n        raise RuntimeError(\"Cuda extensions are being compiled with a version of Cuda that does \" +\n                           \"not match the version used to compile Pytorch binaries.  \" +\n                           \"Pytorch binaries were compiled with Cuda {}.\\n\".format(torch.version.cuda) +\n                           \"In some cases, a minor-version mismatch will not cause later errors:  \" +\n                           \"https://github.com/NVIDIA/apex/pull/323#discussion_r287021798.  \"\n                           \"You can try commenting out this check (at your own risk).\")\n\n# Set up macros for forward/backward compatibility hack around\n# https://github.com/pytorch/pytorch/commit/4404762d7dd955383acee92e6f06b48144a0742e\n# and\n# https://github.com/NVIDIA/apex/issues/456\n# https://github.com/pytorch/pytorch/commit/eb7b39e02f7d75c26d8a795ea8c7fd911334da7e#diff-4632522f237f1e4e728cb824300403ac\nversion_ge_1_1 = []\nif (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 0):\n    version_ge_1_1 = ['-DVERSION_GE_1_1']\nversion_ge_1_3 = []\nif (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 2):\n    version_ge_1_3 = ['-DVERSION_GE_1_3']\nversion_dependent_macros = version_ge_1_1 + version_ge_1_3\n\nif \"--cuda_ext\" in sys.argv:\n    from torch.utils.cpp_extension import CUDAExtension\n    sys.argv.remove(\"--cuda_ext\")\n\n    if torch.utils.cpp_extension.CUDA_HOME is None:\n        raise RuntimeError(\"--cuda_ext was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.\")\n    else:\n        check_cuda_torch_binary_vs_bare_metal(torch.utils.cpp_extension.CUDA_HOME)\n\n        ext_modules.append(\n            CUDAExtension(name='amp_C',\n                          sources=['csrc/amp_C_frontend.cpp',\n                                   'csrc/multi_tensor_sgd_kernel.cu',\n                                   'csrc/multi_tensor_scale_kernel.cu',\n                                   'csrc/multi_tensor_axpby_kernel.cu',\n                                   'csrc/multi_tensor_l2norm_kernel.cu',\n                                   'csrc/multi_tensor_lamb_stage_1.cu',\n                                   'csrc/multi_tensor_lamb_stage_2.cu',\n                                   'csrc/multi_tensor_adam.cu',\n                                   'csrc/multi_tensor_novograd.cu',\n                                   'csrc/multi_tensor_lamb.cu'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-lineinfo',\n                                                      '-O3',\n                                                      # '--resource-usage',\n                                                      '--use_fast_math'] + version_dependent_macros}))\n        ext_modules.append(\n            CUDAExtension(name='fused_adam_cuda',\n                          sources=['csrc/fused_adam_cuda.cpp',\n                                   'csrc/fused_adam_cuda_kernel.cu'],\n                          extra_compile_args={'cxx': ['-O3',] + version_dependent_macros,\n                                              'nvcc':['-O3',\n                                                      '--use_fast_math'] + version_dependent_macros}))\n        ext_modules.append(\n            CUDAExtension(name='syncbn',\n                          sources=['csrc/syncbn.cpp',\n                                   'csrc/welford.cu'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-O3'] + version_dependent_macros}))\n\n        ext_modules.append(\n            CUDAExtension(name='fused_layer_norm_cuda',\n                          sources=['csrc/layer_norm_cuda.cpp',\n                                   'csrc/layer_norm_cuda_kernel.cu'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-maxrregcount=50',\n                                                      '-O3',\n                                                      '--use_fast_math'] + version_dependent_macros}))\n\nif \"--bnp\" in sys.argv:\n    from torch.utils.cpp_extension import CUDAExtension\n    sys.argv.remove(\"--bnp\")\n\n    from torch.utils.cpp_extension import BuildExtension\n    cmdclass['build_ext'] = BuildExtension\n\n    if torch.utils.cpp_extension.CUDA_HOME is None:\n        raise RuntimeError(\"--bnp was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.\")\n    else:\n        ext_modules.append(\n            CUDAExtension(name='bnp',\n                          sources=['apex/contrib/csrc/groupbn/batch_norm.cu',\n                                   'apex/contrib/csrc/groupbn/ipc.cu',\n                                   'apex/contrib/csrc/groupbn/interface.cpp',\n                                   'apex/contrib/csrc/groupbn/batch_norm_add_relu.cu'],\n                          include_dirs=['csrc'],\n                          extra_compile_args={'cxx': [] + version_dependent_macros,\n                                              'nvcc':['-DCUDA_HAS_FP16=1',\n                                                      '-D__CUDA_NO_HALF_OPERATORS__',\n                                                      '-D__CUDA_NO_HALF_CONVERSIONS__',\n                                                      '-D__CUDA_NO_HALF2_OPERATORS__',\n                                                      '-gencode',\n                                                      'arch=compute_70,code=sm_70'] + version_dependent_macros}))\n\nif \"--xentropy\" in sys.argv:\n    from torch.utils.cpp_extension import CUDAExtension\n    sys.argv.remove(\"--xentropy\")\n\n    from torch.utils.cpp_extension import BuildExtension\n    cmdclass['build_ext'] = BuildExtension\n\n    if torch.utils.cpp_extension.CUDA_HOME is None:\n        raise RuntimeError(\"--xentropy was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.\")\n    else:\n        ext_modules.append(\n            CUDAExtension(name='xentropy_cuda',\n                          sources=['apex/contrib/csrc/xentropy/interface.cpp',\n                                   'apex/contrib/csrc/xentropy/xentropy_kernel.cu'],\n                          include_dirs=['csrc'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-O3'] + version_dependent_macros}))\n\nsetup(\n    name='apex',\n    version='0.1',\n    packages=find_packages(exclude=('build',\n                                    'csrc',\n                                    'include',\n                                    'tests',\n                                    'dist',\n                                    'docs',\n                                    'tests',\n                                    'examples',\n                                    'apex.egg-info',)),\n    description='PyTorch Extensions written by NVIDIA',\n    ext_modules=ext_modules,\n    cmdclass=cmdclass,\n)\n", "path": "setup.py"}], "after_files": [{"content": "import torch\nfrom setuptools import setup, find_packages\nimport subprocess\n\nfrom pip._internal import main as pipmain\nimport sys\nimport warnings\nimport os\n\nif not torch.cuda.is_available():\n    # https://github.com/NVIDIA/apex/issues/486\n    # Extension builds after https://github.com/pytorch/pytorch/pull/23408 attempt to query torch.cuda.get_device_capability(),\n    # which will fail if you are compiling in an environment without visible GPUs (e.g. during an nvidia-docker build command).\n    print('\\nWarning: Torch did not find available GPUs on this system.\\n',\n          'If your intention is to cross-compile, this is not an error.\\n'\n          'By default, Apex will cross-compile for Pascal (compute capabilities 6.0, 6.1, 6.2),\\n'\n          'Volta (compute capability 7.0), and Turing (compute capability 7.5).\\n'\n          'If you wish to cross-compile for a single specific architecture,\\n'\n          'export TORCH_CUDA_ARCH_LIST=\"compute capability\" before running setup.py.\\n')\n    if os.environ.get(\"TORCH_CUDA_ARCH_LIST\", None) is None:\n        os.environ[\"TORCH_CUDA_ARCH_LIST\"] = \"6.0;6.1;6.2;7.0;7.5\"\n\nprint(\"torch.__version__  = \", torch.__version__)\nTORCH_MAJOR = int(torch.__version__.split('.')[0])\nTORCH_MINOR = int(torch.__version__.split('.')[1])\n\nif TORCH_MAJOR == 0 and TORCH_MINOR < 4:\n      raise RuntimeError(\"Apex requires Pytorch 0.4 or newer.\\n\" +\n                         \"The latest stable release can be obtained from https://pytorch.org/\")\n\ncmdclass = {}\next_modules = []\n\nif \"--pyprof\" in sys.argv:\n    with open('requirements.txt') as f:\n        required_packages = f.read().splitlines()\n        pipmain([\"install\"] + required_packages)\n    try:\n        sys.argv.remove(\"--pyprof\")\n    except:\n        pass\nelse:\n    warnings.warn(\"Option --pyprof not specified. Not installing PyProf dependencies!\")\n\nif \"--cpp_ext\" in sys.argv or \"--cuda_ext\" in sys.argv:\n    if TORCH_MAJOR == 0:\n        raise RuntimeError(\"--cpp_ext requires Pytorch 1.0 or later, \"\n                           \"found torch.__version__ = {}\".format(torch.__version__))\n    from torch.utils.cpp_extension import BuildExtension\n    cmdclass['build_ext'] = BuildExtension\n\nif \"--cpp_ext\" in sys.argv:\n    from torch.utils.cpp_extension import CppExtension\n    sys.argv.remove(\"--cpp_ext\")\n    ext_modules.append(\n        CppExtension('apex_C',\n                     ['csrc/flatten_unflatten.cpp',]))\n\ndef check_cuda_torch_binary_vs_bare_metal(cuda_dir):\n    raw_output = subprocess.check_output([cuda_dir + \"/bin/nvcc\", \"-V\"], universal_newlines=True)\n    output = raw_output.split()\n    release_idx = output.index(\"release\") + 1\n    release = output[release_idx].split(\".\")\n    bare_metal_major = release[0]\n    bare_metal_minor = release[1][0]\n    torch_binary_major = torch.version.cuda.split(\".\")[0]\n    torch_binary_minor = torch.version.cuda.split(\".\")[1]\n\n    print(\"\\nCompiling cuda extensions with\")\n    print(raw_output + \"from \" + cuda_dir + \"/bin\\n\")\n\n    if (bare_metal_major != torch_binary_major) or (bare_metal_minor != torch_binary_minor):\n        raise RuntimeError(\"Cuda extensions are being compiled with a version of Cuda that does \" +\n                           \"not match the version used to compile Pytorch binaries.  \" +\n                           \"Pytorch binaries were compiled with Cuda {}.\\n\".format(torch.version.cuda) +\n                           \"In some cases, a minor-version mismatch will not cause later errors:  \" +\n                           \"https://github.com/NVIDIA/apex/pull/323#discussion_r287021798.  \"\n                           \"You can try commenting out this check (at your own risk).\")\n\n# Set up macros for forward/backward compatibility hack around\n# https://github.com/pytorch/pytorch/commit/4404762d7dd955383acee92e6f06b48144a0742e\n# and\n# https://github.com/NVIDIA/apex/issues/456\n# https://github.com/pytorch/pytorch/commit/eb7b39e02f7d75c26d8a795ea8c7fd911334da7e#diff-4632522f237f1e4e728cb824300403ac\nversion_ge_1_1 = []\nif (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 0):\n    version_ge_1_1 = ['-DVERSION_GE_1_1']\nversion_ge_1_3 = []\nif (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 2):\n    version_ge_1_3 = ['-DVERSION_GE_1_3']\nversion_dependent_macros = version_ge_1_1 + version_ge_1_3\n\nif \"--cuda_ext\" in sys.argv:\n    from torch.utils.cpp_extension import CUDAExtension\n    sys.argv.remove(\"--cuda_ext\")\n\n    if torch.utils.cpp_extension.CUDA_HOME is None:\n        raise RuntimeError(\"--cuda_ext was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.\")\n    else:\n        check_cuda_torch_binary_vs_bare_metal(torch.utils.cpp_extension.CUDA_HOME)\n\n        ext_modules.append(\n            CUDAExtension(name='amp_C',\n                          sources=['csrc/amp_C_frontend.cpp',\n                                   'csrc/multi_tensor_sgd_kernel.cu',\n                                   'csrc/multi_tensor_scale_kernel.cu',\n                                   'csrc/multi_tensor_axpby_kernel.cu',\n                                   'csrc/multi_tensor_l2norm_kernel.cu',\n                                   'csrc/multi_tensor_lamb_stage_1.cu',\n                                   'csrc/multi_tensor_lamb_stage_2.cu',\n                                   'csrc/multi_tensor_adam.cu',\n                                   'csrc/multi_tensor_novograd.cu',\n                                   'csrc/multi_tensor_lamb.cu'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-lineinfo',\n                                                      '-O3',\n                                                      # '--resource-usage',\n                                                      '--use_fast_math'] + version_dependent_macros}))\n        ext_modules.append(\n            CUDAExtension(name='fused_adam_cuda',\n                          sources=['csrc/fused_adam_cuda.cpp',\n                                   'csrc/fused_adam_cuda_kernel.cu'],\n                          extra_compile_args={'cxx': ['-O3',] + version_dependent_macros,\n                                              'nvcc':['-O3',\n                                                      '--use_fast_math'] + version_dependent_macros}))\n        ext_modules.append(\n            CUDAExtension(name='syncbn',\n                          sources=['csrc/syncbn.cpp',\n                                   'csrc/welford.cu'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-O3'] + version_dependent_macros}))\n\n        ext_modules.append(\n            CUDAExtension(name='fused_layer_norm_cuda',\n                          sources=['csrc/layer_norm_cuda.cpp',\n                                   'csrc/layer_norm_cuda_kernel.cu'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-maxrregcount=50',\n                                                      '-O3',\n                                                      '--use_fast_math'] + version_dependent_macros}))\n\nif \"--bnp\" in sys.argv:\n    from torch.utils.cpp_extension import CUDAExtension\n    sys.argv.remove(\"--bnp\")\n\n    from torch.utils.cpp_extension import BuildExtension\n    cmdclass['build_ext'] = BuildExtension\n\n    if torch.utils.cpp_extension.CUDA_HOME is None:\n        raise RuntimeError(\"--bnp was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.\")\n    else:\n        ext_modules.append(\n            CUDAExtension(name='bnp',\n                          sources=['apex/contrib/csrc/groupbn/batch_norm.cu',\n                                   'apex/contrib/csrc/groupbn/ipc.cu',\n                                   'apex/contrib/csrc/groupbn/interface.cpp',\n                                   'apex/contrib/csrc/groupbn/batch_norm_add_relu.cu'],\n                          include_dirs=['csrc'],\n                          extra_compile_args={'cxx': [] + version_dependent_macros,\n                                              'nvcc':['-DCUDA_HAS_FP16=1',\n                                                      '-D__CUDA_NO_HALF_OPERATORS__',\n                                                      '-D__CUDA_NO_HALF_CONVERSIONS__',\n                                                      '-D__CUDA_NO_HALF2_OPERATORS__',\n                                                      '-gencode',\n                                                      'arch=compute_70,code=sm_70'] + version_dependent_macros}))\n\nif \"--xentropy\" in sys.argv:\n    from torch.utils.cpp_extension import CUDAExtension\n    sys.argv.remove(\"--xentropy\")\n\n    from torch.utils.cpp_extension import BuildExtension\n    cmdclass['build_ext'] = BuildExtension\n\n    if torch.utils.cpp_extension.CUDA_HOME is None:\n        raise RuntimeError(\"--xentropy was requested, but nvcc was not found.  Are you sure your environment has nvcc available?  If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.\")\n    else:\n        ext_modules.append(\n            CUDAExtension(name='xentropy_cuda',\n                          sources=['apex/contrib/csrc/xentropy/interface.cpp',\n                                   'apex/contrib/csrc/xentropy/xentropy_kernel.cu'],\n                          include_dirs=['csrc'],\n                          extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,\n                                              'nvcc':['-O3'] + version_dependent_macros}))\n\nsetup(\n    name='apex',\n    version='0.1',\n    packages=find_packages(exclude=('build',\n                                    'csrc',\n                                    'include',\n                                    'tests',\n                                    'dist',\n                                    'docs',\n                                    'tests',\n                                    'examples',\n                                    'apex.egg-info',)),\n    description='PyTorch Extensions written by NVIDIA',\n    ext_modules=ext_modules,\n    cmdclass=cmdclass,\n)\n", "path": "setup.py"}]}