2017-09-25 20:17:43 +03:00
|
|
|
#!/usr/bin/env python3
|
2019-07-30 17:45:13 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2017-09-15 03:22:43 +03:00
|
|
|
#
|
2019-07-30 17:45:13 +03:00
|
|
|
# This source code is licensed under the MIT license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree.
|
2017-09-15 03:22:43 +03:00
|
|
|
|
2019-11-03 02:51:32 +03:00
|
|
|
import os
|
2017-09-15 03:22:43 +03:00
|
|
|
import sys
|
|
|
|
|
2020-10-19 04:13:29 +03:00
|
|
|
from setuptools import Extension, find_packages, setup
|
|
|
|
|
2017-09-15 03:22:43 +03:00
|
|
|
|
2019-12-17 06:46:03 +03:00
|
|
|
if sys.version_info < (3, 6):
|
2020-10-19 04:13:29 +03:00
|
|
|
sys.exit("Sorry, Python >= 3.6 is required for fairseq.")
|
2017-09-15 03:22:43 +03:00
|
|
|
|
2019-08-27 20:06:26 +03:00
|
|
|
|
2020-10-19 04:13:29 +03:00
|
|
|
with open("README.md") as f:
|
2017-09-15 03:22:43 +03:00
|
|
|
readme = f.read()
|
|
|
|
|
2019-08-27 20:06:26 +03:00
|
|
|
|
2020-10-19 04:13:29 +03:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
extra_compile_args = ["-stdlib=libc++", "-O3"]
|
2019-07-06 22:27:58 +03:00
|
|
|
else:
|
2020-10-19 04:13:29 +03:00
|
|
|
extra_compile_args = ["-std=c++11", "-O3"]
|
2017-09-15 03:22:43 +03:00
|
|
|
|
2019-08-27 17:10:35 +03:00
|
|
|
|
2019-09-01 02:52:03 +03:00
|
|
|
class NumpyExtension(Extension):
|
|
|
|
"""Source: https://stackoverflow.com/a/54128391"""
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
self.__include_dirs = []
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def include_dirs(self):
|
|
|
|
import numpy
|
2020-10-19 04:13:29 +03:00
|
|
|
|
2019-09-01 02:52:03 +03:00
|
|
|
return self.__include_dirs + [numpy.get_include()]
|
|
|
|
|
|
|
|
@include_dirs.setter
|
|
|
|
def include_dirs(self, dirs):
|
|
|
|
self.__include_dirs = dirs
|
|
|
|
|
|
|
|
|
2019-08-27 20:06:26 +03:00
|
|
|
extensions = [
|
|
|
|
Extension(
|
2020-10-19 04:13:29 +03:00
|
|
|
"fairseq.libbleu",
|
2019-08-27 20:06:26 +03:00
|
|
|
sources=[
|
2020-10-19 04:13:29 +03:00
|
|
|
"fairseq/clib/libbleu/libbleu.cpp",
|
|
|
|
"fairseq/clib/libbleu/module.cpp",
|
2019-08-27 20:06:26 +03:00
|
|
|
],
|
2019-08-27 17:10:35 +03:00
|
|
|
extra_compile_args=extra_compile_args,
|
2019-08-27 20:06:26 +03:00
|
|
|
),
|
2019-09-01 02:52:03 +03:00
|
|
|
NumpyExtension(
|
2020-10-19 04:13:29 +03:00
|
|
|
"fairseq.data.data_utils_fast",
|
|
|
|
sources=["fairseq/data/data_utils_fast.pyx"],
|
|
|
|
language="c++",
|
2019-08-27 17:10:35 +03:00
|
|
|
extra_compile_args=extra_compile_args,
|
2019-08-27 20:06:26 +03:00
|
|
|
),
|
2019-09-01 02:52:03 +03:00
|
|
|
NumpyExtension(
|
2020-10-19 04:13:29 +03:00
|
|
|
"fairseq.data.token_block_utils_fast",
|
|
|
|
sources=["fairseq/data/token_block_utils_fast.pyx"],
|
|
|
|
language="c++",
|
2019-08-27 20:06:26 +03:00
|
|
|
extra_compile_args=extra_compile_args,
|
|
|
|
),
|
|
|
|
]
|
2019-08-27 17:10:35 +03:00
|
|
|
|
|
|
|
|
2019-11-03 02:51:32 +03:00
|
|
|
cmdclass = {}
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
# torch is not available when generating docs
|
|
|
|
from torch.utils import cpp_extension
|
2019-12-21 13:43:47 +03:00
|
|
|
|
2020-10-19 04:13:29 +03:00
|
|
|
extensions.extend(
|
|
|
|
[
|
2019-12-21 13:43:47 +03:00
|
|
|
cpp_extension.CppExtension(
|
2020-10-19 04:13:29 +03:00
|
|
|
"fairseq.libnat",
|
2019-12-21 13:43:47 +03:00
|
|
|
sources=[
|
2020-10-19 04:13:29 +03:00
|
|
|
"fairseq/clib/libnat/edit_dist.cpp",
|
2019-12-21 13:43:47 +03:00
|
|
|
],
|
2020-10-19 04:13:29 +03:00
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
if "CUDA_HOME" in os.environ:
|
|
|
|
extensions.extend(
|
|
|
|
[
|
|
|
|
cpp_extension.CppExtension(
|
|
|
|
"fairseq.libnat_cuda",
|
|
|
|
sources=[
|
|
|
|
"fairseq/clib/libnat_cuda/edit_dist.cu",
|
|
|
|
"fairseq/clib/libnat_cuda/binding.cpp",
|
|
|
|
],
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
cmdclass["build_ext"] = cpp_extension.BuildExtension
|
2019-12-21 13:43:47 +03:00
|
|
|
|
2019-11-03 02:51:32 +03:00
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-10-19 04:13:29 +03:00
|
|
|
if "READTHEDOCS" in os.environ:
|
2019-11-03 02:51:32 +03:00
|
|
|
# don't build extensions when generating docs
|
|
|
|
extensions = []
|
2020-10-19 04:13:29 +03:00
|
|
|
if "build_ext" in cmdclass:
|
|
|
|
del cmdclass["build_ext"]
|
2019-11-03 02:51:32 +03:00
|
|
|
|
|
|
|
# use CPU build of PyTorch
|
|
|
|
dependency_links = [
|
2020-10-19 04:13:29 +03:00
|
|
|
"https://download.pytorch.org/whl/cpu/torch-1.3.0%2Bcpu-cp36-cp36m-linux_x86_64.whl"
|
2019-11-03 02:51:32 +03:00
|
|
|
]
|
|
|
|
else:
|
|
|
|
dependency_links = []
|
|
|
|
|
|
|
|
|
2020-10-19 04:13:29 +03:00
|
|
|
if "clean" in sys.argv[1:]:
|
2019-11-13 21:47:05 +03:00
|
|
|
# Source: https://bit.ly/2NLVsgE
|
|
|
|
print("deleting Cython files...")
|
|
|
|
import subprocess
|
2020-10-19 04:13:29 +03:00
|
|
|
|
|
|
|
subprocess.run(
|
|
|
|
["rm -f fairseq/*.so fairseq/**/*.so fairseq/*.pyd fairseq/**/*.pyd"],
|
|
|
|
shell=True,
|
|
|
|
)
|
2019-11-26 00:38:42 +03:00
|
|
|
|
|
|
|
|
2017-09-15 03:22:43 +03:00
|
|
|
setup(
|
2020-10-19 04:13:29 +03:00
|
|
|
name="fairseq",
|
|
|
|
version="0.9.0",
|
|
|
|
description="Facebook AI Research Sequence-to-Sequence Toolkit",
|
|
|
|
url="https://github.com/pytorch/fairseq",
|
2019-02-09 09:00:46 +03:00
|
|
|
classifiers=[
|
2020-10-19 04:13:29 +03:00
|
|
|
"Intended Audience :: Science/Research",
|
|
|
|
"License :: OSI Approved :: MIT License",
|
|
|
|
"Programming Language :: Python :: 3.6",
|
|
|
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
2019-02-09 09:00:46 +03:00
|
|
|
],
|
2017-09-15 03:22:43 +03:00
|
|
|
long_description=readme,
|
2020-10-19 04:13:29 +03:00
|
|
|
long_description_content_type="text/markdown",
|
2019-08-26 17:18:01 +03:00
|
|
|
setup_requires=[
|
2020-10-19 04:13:29 +03:00
|
|
|
"cython",
|
|
|
|
"numpy",
|
|
|
|
"setuptools>=18.0",
|
2019-08-26 17:18:01 +03:00
|
|
|
],
|
2019-02-09 09:00:46 +03:00
|
|
|
install_requires=[
|
2020-10-19 04:13:29 +03:00
|
|
|
"cffi",
|
|
|
|
"cython",
|
|
|
|
"dataclasses",
|
|
|
|
"editdistance",
|
|
|
|
"hydra-core",
|
|
|
|
"numpy",
|
|
|
|
"regex",
|
|
|
|
"sacrebleu>=1.4.12",
|
|
|
|
"torch",
|
|
|
|
"tqdm",
|
2019-02-09 09:00:46 +03:00
|
|
|
],
|
2019-11-03 02:51:32 +03:00
|
|
|
dependency_links=dependency_links,
|
2020-10-19 04:13:29 +03:00
|
|
|
packages=find_packages(exclude=["scripts", "tests"]),
|
2019-08-27 20:06:26 +03:00
|
|
|
ext_modules=extensions,
|
2020-10-19 04:13:29 +03:00
|
|
|
test_suite="tests",
|
2019-02-05 18:46:44 +03:00
|
|
|
entry_points={
|
2020-10-19 04:13:29 +03:00
|
|
|
"console_scripts": [
|
|
|
|
"fairseq-eval-lm = fairseq_cli.eval_lm:cli_main",
|
|
|
|
"fairseq-generate = fairseq_cli.generate:cli_main",
|
|
|
|
"fairseq-interactive = fairseq_cli.interactive:cli_main",
|
|
|
|
"fairseq-preprocess = fairseq_cli.preprocess:cli_main",
|
|
|
|
"fairseq-score = fairseq_cli.score:cli_main",
|
|
|
|
"fairseq-train = fairseq_cli.train:cli_main",
|
|
|
|
"fairseq-validate = fairseq_cli.validate:cli_main",
|
2019-02-05 18:46:44 +03:00
|
|
|
],
|
|
|
|
},
|
2019-11-03 02:51:32 +03:00
|
|
|
cmdclass=cmdclass,
|
2019-08-23 17:31:18 +03:00
|
|
|
zip_safe=False,
|
2017-09-15 03:22:43 +03:00
|
|
|
)
|