Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ColossalAI
Commits
9942fd5b
Unverified
Commit
9942fd5b
authored
Nov 15, 2021
by
ver217
Committed by
GitHub
Nov 15, 2021
Browse files
remove redundancy func in setup (#19) (#20)
parent
0aa07e60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
69 deletions
+29
-69
setup.py
setup.py
+29
-69
No files found.
setup.py
View file @
9942fd5b
import
os
import
subprocess
import
sys
import
warnings
import
torch
from
setuptools
import
setup
,
find_packages
...
...
@@ -23,13 +22,36 @@ def get_cuda_bare_metal_version(cuda_dir):
return
raw_output
,
bare_metal_major
,
bare_metal_minor
def
check_cuda_torch_binary_vs_bare_metal
(
cuda_dir
):
raw_output
,
bare_metal_major
,
bare_metal_minor
=
get_cuda_bare_metal_version
(
cuda_dir
)
torch_binary_major
=
torch
.
version
.
cuda
.
split
(
"."
)[
0
]
torch_binary_minor
=
torch
.
version
.
cuda
.
split
(
"."
)[
1
]
print
(
"
\n
Compiling cuda extensions with"
)
print
(
raw_output
+
"from "
+
cuda_dir
+
"/bin
\n
"
)
if
(
bare_metal_major
!=
torch_binary_major
)
or
(
bare_metal_minor
!=
torch_binary_minor
):
raise
RuntimeError
(
"Cuda extensions are being compiled with a version of Cuda that does "
+
"not match the version used to compile Pytorch binaries. "
+
"Pytorch binaries were compiled with Cuda {}.
\n
"
.
format
(
torch
.
version
.
cuda
)
+
"In some cases, a minor-version mismatch will not cause later errors: "
+
"https://github.com/NVIDIA/apex/pull/323#discussion_r287021798. "
"You can try commenting out this check (at your own risk)."
)
def
fetch_requirements
(
path
):
with
open
(
path
,
'r'
)
as
fd
:
return
[
r
.
strip
()
for
r
in
fd
.
readlines
()]
if
not
torch
.
cuda
.
is_available
():
# 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
(
'
\n
Warning: 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
'
'By default,
Colossal-AI
will cross-compile for Pascal (compute capabilities 6.0, 6.1, 6.2),
\n
'
'Volta (compute capability 7.0), Turing (compute capability 7.5),
\n
'
'and, if the CUDA version is >= 11.0, Ampere (compute capability 8.0).
\n
'
'If you wish to cross-compile for a single specific architecture,
\n
'
...
...
@@ -46,66 +68,12 @@ TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR
=
int
(
torch
.
__version__
.
split
(
'.'
)[
1
])
if
TORCH_MAJOR
==
0
and
TORCH_MINOR
<
4
:
raise
RuntimeError
(
"
Apex
requires Pytorch 0.4 or newer.
\n
"
+
raise
RuntimeError
(
"
Colossal-AI
requires Pytorch 0.4 or newer.
\n
"
+
"The latest stable release can be obtained from https://pytorch.org/"
)
cmdclass
=
{}
ext_modules
=
[]
extras
=
{}
if
"--pyprof"
in
sys
.
argv
:
string
=
"
\n\n
Pyprof has been moved to its own dedicated repository and will "
+
\
"soon be removed from Apex. Please visit
\n
"
+
\
"https://github.com/NVIDIA/PyProf
\n
"
+
\
"for the latest version."
warnings
.
warn
(
string
,
DeprecationWarning
)
with
open
(
'requirements.txt'
)
as
f
:
required_packages
=
f
.
read
().
splitlines
()
extras
[
'pyprof'
]
=
required_packages
try
:
sys
.
argv
.
remove
(
"--pyprof"
)
except
:
pass
else
:
warnings
.
warn
(
"Option --pyprof not specified. Not installing PyProf dependencies!"
)
if
"--cuda_ext"
in
sys
.
argv
:
if
TORCH_MAJOR
==
0
:
raise
RuntimeError
(
"--cuda_ext requires Pytorch 1.0 or later, "
"found torch.__version__ = {}"
.
format
(
torch
.
__version__
))
def
get_cuda_bare_metal_version
(
cuda_dir
):
raw_output
=
subprocess
.
check_output
(
[
cuda_dir
+
"/bin/nvcc"
,
"-V"
],
universal_newlines
=
True
)
output
=
raw_output
.
split
()
release_idx
=
output
.
index
(
"release"
)
+
1
release
=
output
[
release_idx
].
split
(
"."
)
bare_metal_major
=
release
[
0
]
bare_metal_minor
=
release
[
1
][
0
]
return
raw_output
,
bare_metal_major
,
bare_metal_minor
def
check_cuda_torch_binary_vs_bare_metal
(
cuda_dir
):
raw_output
,
bare_metal_major
,
bare_metal_minor
=
get_cuda_bare_metal_version
(
cuda_dir
)
torch_binary_major
=
torch
.
version
.
cuda
.
split
(
"."
)[
0
]
torch_binary_minor
=
torch
.
version
.
cuda
.
split
(
"."
)[
1
]
print
(
"
\n
Compiling cuda extensions with"
)
print
(
raw_output
+
"from "
+
cuda_dir
+
"/bin
\n
"
)
if
(
bare_metal_major
!=
torch_binary_major
)
or
(
bare_metal_minor
!=
torch_binary_minor
):
raise
RuntimeError
(
"Cuda extensions are being compiled with a version of Cuda that does "
+
"not match the version used to compile Pytorch binaries. "
+
"Pytorch binaries were compiled with Cuda {}.
\n
"
.
format
(
torch
.
version
.
cuda
)
+
"In some cases, a minor-version mismatch will not cause later errors: "
+
"https://github.com/NVIDIA/apex/pull/323#discussion_r287021798. "
"You can try commenting out this check (at your own risk)."
)
# Set up macros for forward/backward compatibility hack around
# https://github.com/pytorch/pytorch/commit/4404762d7dd955383acee92e6f06b48144a0742e
# and
...
...
@@ -123,6 +91,10 @@ if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 4):
version_dependent_macros
=
version_ge_1_1
+
version_ge_1_3
+
version_ge_1_5
if
"--cuda_ext"
in
sys
.
argv
:
if
TORCH_MAJOR
==
0
:
raise
RuntimeError
(
"--cuda_ext requires Pytorch 1.0 or later, "
"found torch.__version__ = {}"
.
format
(
torch
.
__version__
))
sys
.
argv
.
remove
(
"--cuda_ext"
)
if
CUDA_HOME
is
None
:
...
...
@@ -145,17 +117,6 @@ if "--cuda_ext" in sys.argv:
# '--resource-usage',
'--use_fast_math'
]
+
version_dependent_macros
}))
# Check, if ATen/CUDAGenerator.h is found, otherwise use the new ATen/CUDAGeneratorImpl.h, due to breaking change in https://github.com/pytorch/pytorch/pull/36026
generator_flag
=
[]
torch_dir
=
torch
.
__path__
[
0
]
if
os
.
path
.
exists
(
os
.
path
.
join
(
torch_dir
,
'include'
,
'ATen'
,
'CUDAGenerator.h'
)):
generator_flag
=
[
'-DOLD_GENERATOR'
]
def
fetch_requirements
(
path
):
with
open
(
path
,
'r'
)
as
fd
:
return
[
r
.
strip
()
for
r
in
fd
.
readlines
()]
install_requires
=
fetch_requirements
(
'requirements/requirements.txt'
)
...
...
@@ -170,6 +131,5 @@ setup(
description
=
'An integrated large-scale model training system with efficient parallelization techniques'
,
ext_modules
=
ext_modules
,
cmdclass
=
{
'build_ext'
:
BuildExtension
}
if
ext_modules
else
{},
extras_require
=
extras
,
install_requires
=
install_requires
,
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment