forked from pytorch/torchrec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
145 lines (123 loc) · 4.24 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
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
import argparse
import os
import random
import re
import sys
from datetime import date
from typing import List
from setuptools import find_packages, setup
def get_version():
# get version string from version.py
# TODO: ideally the version.py should be generated when setup is run
version_file = os.path.join(os.path.dirname(__file__), "version.py")
version_regex = r"__version__ = ['\"]([^'\"]*)['\"]"
with open(version_file, "r") as f:
version = re.search(version_regex, f.read(), re.M).group(1)
return version
def get_nightly_version():
today = date.today()
return f"{today.year}.{today.month}.{today.day}"
def get_channel():
# Channel typically takes on the following values:
# - NIGHTLY: for nightly published binaries
# - TEST: for binaries build from release candidate branches
return os.getenv("CHANNEL")
def parse_args(argv: List[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser(description="torchrec setup")
parser.add_argument(
"--package_name",
type=str,
default="torchrec",
help="the name of this output wheel",
)
parser.add_argument(
"--version",
type=str,
default=None,
help="override version",
)
parser.add_argument(
"--cpu-only",
type=bool,
default=False,
help="True will install CPU only version of fbgemm-gpu",
)
return parser.parse_known_args(argv)
def main(argv: List[str]) -> None:
args, unknown = parse_args(argv)
# Set up package name and version
channel = get_channel()
name = args.package_name
with open(
os.path.join(os.path.dirname(__file__), "README.MD"), encoding="utf8"
) as f:
readme = f.read()
with open(
os.path.join(os.path.dirname(__file__), "install-requirements.txt"),
encoding="utf8",
) as f:
reqs = f.read()
install_requires = reqs.strip().split("\n")
version = args.version
if version is None:
version = get_nightly_version() if channel == "nightly" else get_version()
if channel != "nightly":
if "fbgemm-gpu-nightly" in install_requires:
install_requires.remove("fbgemm-gpu-nightly")
install_requires.append("fbgemm-gpu")
cpu_only = args.cpu_only
if cpu_only:
if "fbgemm-gpu-nightly" in install_requires:
install_requires.remove("fbgemm-gpu-nightly")
install_requires.append("fbgemm-gpu-nightly-cpu")
if "fbgemm-gpu" in install_requires:
install_requires.remove("fbgemm-gpu")
install_requires.append("fbgemm-gpu-cpu")
print(f"-- {name} building version: {version} CPU only: {cpu_only}")
packages = find_packages(
exclude=(
"*tests",
"*test",
"examples",
"*examples.*",
"*benchmarks",
"*build",
"*rfc",
)
)
sys.argv = [sys.argv[0]] + unknown
setup(
# Metadata
name=name,
version=version,
author="TorchRec Team",
author_email="[email protected]",
description="Pytorch domain library for recommendation systems",
long_description=readme,
long_description_content_type="text/markdown",
url="https://github.com/pytorch/torchrec",
license="BSD-3",
keywords=["pytorch", "recommendation systems", "sharding"],
python_requires=">=3.7",
install_requires=install_requires,
packages=packages,
zip_safe=False,
# PyPI package information.
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
)
if __name__ == "__main__":
main(sys.argv[1:])