forked from openvinotoolkit/nncf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
188 lines (163 loc) · 7.05 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""
Copyright (c) 2022 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# *WARNING*: Do not run this file directly by `python setup.py install`
# or with any other parameter - this is an outdated and error-prone way
# to install Python packages and causes particular problems with namespace
# packages such as `protobuf`.
# Refer to the table below for well-known and supported alternatives with
# the same behaviour:
# +-------------------------------------------------------------------------------+
# | Old command | New command |
# +---------------------------------+---------------------------------------------+
# | python setup.py install | pip install . |
# | python setup.py develop | pip install -e . |
# | python setup.py develop --*arg* | pip install --install-option="*arg*" -e . |
# | python setup.py sdist | python -m build -s | <-- using the "build" package
# | python setup.py bdist_wheel | python -m build -w | <-- https://pypi.org/project/build/
# +---------------------------------+---------------------------------------------+
#
# PyPA in general recommends to move away from setup.py and use pyproject.toml
# instead. This doesn't fit us as we currently want to do custom stuff during
# installation such as setting version based on the commit SHA for repo-based
# installs.
import glob
import stat
import sys
import sysconfig
import codecs
import os
import re
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
BKC_SETUPTOOLS_VERSION = '59.5.0'
import setuptools
from pkg_resources import parse_version
setuptools_version = parse_version(setuptools.__version__).base_version
if setuptools_version < '43.0.0':
raise RuntimeError(
"To properly install NNCF, please install setuptools>=43.0.0, "
f"while current setuptools version is {setuptools.__version__}. "
f"Recommended version is {BKC_SETUPTOOLS_VERSION}."
)
python_version = sys.version_info
if python_version < (3, 7, 0):
print("Only Python >= 3.7.0 is supported")
sys.exit(0)
version_string = "{}{}".format(sys.version_info[0], sys.version_info[1])
is_installing_editable = "develop" in sys.argv
is_building_release = not is_installing_editable and "--release" in sys.argv
if "--release" in sys.argv:
sys.argv.remove("--release")
def read(*parts):
with codecs.open(os.path.join(here, *parts), 'r') as fp:
return fp.read()
def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if not version_match:
raise RuntimeError("Unable to find version string.")
version_value = version_match.group(1)
if not is_building_release:
if is_installing_editable:
return version_value + ".dev0+editable"
import subprocess # nosec
dev_version_id = "unknown_version"
try:
repo_root = os.path.dirname(os.path.realpath(__file__))
dev_version_id = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], # nosec
cwd=repo_root).strip().decode()
except subprocess.CalledProcessError:
pass
return version_value + f".dev0+{dev_version_id}"
return version_value
INSTALL_REQUIRES = ["ninja>=1.10.0.post2, <1.11",
"addict>=2.4.0",
"texttable>=1.6.3",
"scipy>=1.3.2, <=1.9.1",
"matplotlib>=3.3.4, <3.6",
"networkx>=2.6, <=2.8.2", # see ticket 94048 or https://github.com/networkx/networkx/issues/5962
"numpy>=1.19.1, <1.24",
"pillow>=9.0.0",
# The recent pyparsing major version update seems to break
# integration with networkx - the graphs parsed from current .dot
# reference files no longer match against the graphs produced in tests.
# Using 2.x versions of pyparsing seems to fix the issue.
# Ticket: 69520
"pyparsing<3.0",
"pymoo==0.5.0",
"jsonschema==3.2.0",
"pydot>=1.4.1",
"jstyleson>=0.0.2",
"tqdm>=4.54.1",
"natsort>=7.1.0",
"pandas>=1.1.5,<1.4.0rc0",
"scikit-learn>=0.24.0",
"wheel>=0.36.1",
"openvino-telemetry"]
EXTRAS_REQUIRE = {
"tests": ["pytest"],
"docs": [],
"tf": [
"tensorflow~=2.8.4",
],
"torch": [
"torch==1.12.1",
],
"onnx": [
"onnx==1.12.0",
"onnxruntime-openvino==1.13.1"
],
"openvino": [
"openvino-dev"
]
}
EXTRAS_REQUIRE["all"] = [
EXTRAS_REQUIRE["tf"],
EXTRAS_REQUIRE["torch"],
EXTRAS_REQUIRE["onnx"],
EXTRAS_REQUIRE["openvino"],
]
with open("{}/README.md".format(here), "r", encoding="utf8") as fh:
long_description = fh.read()
setup(
name="nncf",
version=find_version(os.path.join(here, "nncf/version.py")),
author="Intel",
author_email="alexander.kozlov@intel.com",
description="Neural Networks Compression Framework",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/openvinotoolkit/nncf",
packages=find_packages(exclude=["tests", "tests.*",
"examples", "examples.*",
"tools", "tools.*"]),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRE,
keywords=["compression", "quantization", "sparsity", "mixed-precision-training",
"quantization-aware-training", "hawq", "classification",
"pruning", "object-detection", "semantic-segmentation", "nas", "nlp",
"bert", "transformers", "mmdetection"],
include_package_data=True
)
path_to_ninja = glob.glob(str(sysconfig.get_paths()["purelib"]+"/ninja*/ninja/data/bin/"))
if path_to_ninja:
path_to_ninja = str(path_to_ninja[0]+"ninja")
if not os.access(path_to_ninja, os.X_OK):
st = os.stat(path_to_ninja)
os.chmod(path_to_ninja, st.st_mode | stat.S_IEXEC)