setup.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. # Copyright 2021 The HuggingFace Team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. Simple check list from AllenNLP repo: https://github.com/allenai/allennlp/blob/main/setup.py
  16. To create the package for pypi.
  17. 1. Run `make pre-release` (or `make pre-patch` for a patch release) then run `make fix-copies` to fix the index of the
  18. documentation.
  19. If releasing on a special branch, copy the updated README.md on the main branch for your the commit you will make
  20. for the post-release and run `make fix-copies` on the main branch as well.
  21. 2. Run Tests for Amazon Sagemaker. The documentation is located in `./tests/sagemaker/README.md`, otherwise @philschmid.
  22. 3. Unpin specific versions from setup.py that use a git install.
  23. 4. Checkout the release branch (v<RELEASE>-release, for example v4.19-release), and commit these changes with the
  24. message: "Release: <VERSION>" and push.
  25. 5. Wait for the tests on main to be completed and be green (otherwise revert and fix bugs)
  26. 6. Add a tag in git to mark the release: "git tag v<VERSION> -m 'Adds tag v<VERSION> for pypi' "
  27. Push the tag to git: git push --tags origin v<RELEASE>-release
  28. 7. Build both the sources and the wheel. Do not change anything in setup.py between
  29. creating the wheel and the source distribution (obviously).
  30. Run `make build-release`. This will build the release and do some sanity checks for you. If this ends with an error
  31. message, you need to fix things before going further.
  32. You should now have a /dist directory with both .whl and .tar.gz source versions.
  33. 8. Check that everything looks correct by uploading the package to the pypi test server:
  34. twine upload dist/* -r testpypi
  35. (pypi suggest using twine as other methods upload files via plaintext.)
  36. You may have to specify the repository url, use the following command then:
  37. twine upload dist/* -r testpypi --repository-url=https://test.pypi.org/legacy/
  38. Check that you can install it in a virtualenv by running:
  39. pip install -i https://testpypi.python.org/pypi transformers
  40. Check you can run the following commands:
  41. python -c "from transformers import pipeline; classifier = pipeline('text-classification'); print(classifier('What a nice release'))"
  42. python -c "from transformers import *"
  43. python utils/check_build.py --check_lib
  44. If making a patch release, double check the bug you are patching is indeed resolved.
  45. 9. Upload the final version to actual pypi:
  46. twine upload dist/* -r pypi
  47. 10. Copy the release notes from RELEASE.md to the tag in github once everything is looking hunky-dory.
  48. 11. Run `make post-release` then run `make fix-copies`. If you were on a branch for the release,
  49. you need to go back to main before executing this.
  50. """
  51. import os
  52. import re
  53. import shutil
  54. from pathlib import Path
  55. from setuptools import Command, find_packages, setup
  56. # Remove stale transformers.egg-info directory to avoid https://github.com/pypa/pip/issues/5466
  57. stale_egg_info = Path(__file__).parent / "transformers.egg-info"
  58. if stale_egg_info.exists():
  59. print(
  60. (
  61. "Warning: {} exists.\n\n"
  62. "If you recently updated transformers to 3.0 or later, this is expected,\n"
  63. "but it may prevent transformers from installing in editable mode.\n\n"
  64. "This directory is automatically generated by Python's packaging tools.\n"
  65. "I will remove it now.\n\n"
  66. "See https://github.com/pypa/pip/issues/5466 for details.\n"
  67. ).format(stale_egg_info)
  68. )
  69. shutil.rmtree(stale_egg_info)
  70. # IMPORTANT:
  71. # 1. all dependencies should be listed here with their version requirements if any
  72. # 2. once modified, run: `make deps_table_update` to update src/transformers/dependency_versions_table.py
  73. _deps = [
  74. "Pillow",
  75. "accelerate>=0.19.0",
  76. "av==9.2.0", # Latest version of PyAV (10.0.0) has issues with audio stream.
  77. "beautifulsoup4",
  78. "black~=23.1",
  79. "codecarbon==1.2.0",
  80. "cookiecutter==1.7.3",
  81. "dataclasses",
  82. "datasets!=2.5.0",
  83. "decord==0.6.0",
  84. "deepspeed>=0.8.3",
  85. "diffusers",
  86. "dill<0.3.5",
  87. "evaluate>=0.2.0",
  88. "fairscale>0.3",
  89. "faiss-cpu",
  90. "fastapi",
  91. "filelock",
  92. "flax>=0.4.1,<=0.6.9",
  93. "ftfy",
  94. "fugashi>=1.0",
  95. "GitPython<3.1.19",
  96. "hf-doc-builder>=0.3.0",
  97. "huggingface-hub>=0.14.1,<1.0",
  98. "importlib_metadata",
  99. "ipadic>=1.0.0,<2.0",
  100. "isort>=5.5.4",
  101. "jax>=0.2.8,!=0.3.2,<=0.3.6",
  102. "jaxlib>=0.1.65,<=0.3.6",
  103. "jieba",
  104. "kenlm",
  105. "keras-nlp>=0.3.1",
  106. "librosa",
  107. "nltk",
  108. "natten>=0.14.6",
  109. "numpy>=1.17",
  110. "onnxconverter-common",
  111. "onnxruntime-tools>=1.4.2",
  112. "onnxruntime>=1.4.0",
  113. "opencv-python",
  114. "optuna",
  115. "optax>=0.0.8,<=0.1.4",
  116. "packaging>=20.0",
  117. "parameterized",
  118. "phonemizer",
  119. "protobuf<=3.20.3",
  120. "psutil",
  121. "pyyaml>=5.1",
  122. "pydantic",
  123. "pytest>=7.2.0",
  124. "pytest-timeout",
  125. "pytest-xdist",
  126. "python>=3.7.0",
  127. "ray[tune]",
  128. "regex!=2019.12.17",
  129. "requests",
  130. "rhoknp>=1.1.0,<1.3.1",
  131. "rjieba",
  132. "rouge-score!=0.0.7,!=0.0.8,!=0.1,!=0.1.1",
  133. "ruff>=0.0.241,<=0.0.259",
  134. "sacrebleu>=1.4.12,<2.0.0",
  135. "sacremoses",
  136. "safetensors>=0.3.1",
  137. "sagemaker>=2.31.0",
  138. "scikit-learn",
  139. "sentencepiece>=0.1.91,!=0.1.92",
  140. "sigopt",
  141. "starlette",
  142. "sudachipy>=0.6.6",
  143. "sudachidict_core>=20220729",
  144. # TensorFlow pin. When changing this value, update examples/tensorflow/_tests_requirements.txt accordingly
  145. "tensorflow-cpu>=2.4,<2.13",
  146. "tensorflow>=2.4,<2.13",
  147. "tensorflow-text<2.13",
  148. "tf2onnx",
  149. "timeout-decorator",
  150. "timm",
  151. "tokenizers>=0.11.1,!=0.11.3,<0.14",
  152. "torch>=1.9,!=1.12.0",
  153. "torchaudio",
  154. "torchvision",
  155. "pyctcdecode>=0.4.0",
  156. "tqdm>=4.27",
  157. "unidic>=1.0.2",
  158. "unidic_lite>=1.0.7",
  159. "urllib3<2.0.0",
  160. "uvicorn",
  161. ]
  162. # this is a lookup table with items like:
  163. #
  164. # tokenizers: "tokenizers==0.9.4"
  165. # packaging: "packaging"
  166. #
  167. # some of the values are versioned whereas others aren't.
  168. deps = {b: a for a, b in (re.findall(r"^(([^!=<>~ ]+)(?:[!=<>~ ].*)?$)", x)[0] for x in _deps)}
  169. # since we save this data in src/transformers/dependency_versions_table.py it can be easily accessed from
  170. # anywhere. If you need to quickly access the data from this table in a shell, you can do so easily with:
  171. #
  172. # python -c 'import sys; from transformers.dependency_versions_table import deps; \
  173. # print(" ".join([ deps[x] for x in sys.argv[1:]]))' tokenizers datasets
  174. #
  175. # Just pass the desired package names to that script as it's shown with 2 packages above.
  176. #
  177. # If transformers is not yet installed and the work is done from the cloned repo remember to add `PYTHONPATH=src` to the script above
  178. #
  179. # You can then feed this for example to `pip`:
  180. #
  181. # pip install -U $(python -c 'import sys; from transformers.dependency_versions_table import deps; \
  182. # print(" ".join([deps[x] for x in sys.argv[1:]]))' tokenizers datasets)
  183. #
  184. def deps_list(*pkgs):
  185. return [deps[pkg] for pkg in pkgs]
  186. class DepsTableUpdateCommand(Command):
  187. """
  188. A custom distutils command that updates the dependency table.
  189. usage: python setup.py deps_table_update
  190. """
  191. description = "build runtime dependency table"
  192. user_options = [
  193. # format: (long option, short option, description).
  194. ("dep-table-update", None, "updates src/transformers/dependency_versions_table.py"),
  195. ]
  196. def initialize_options(self):
  197. pass
  198. def finalize_options(self):
  199. pass
  200. def run(self):
  201. entries = "\n".join([f' "{k}": "{v}",' for k, v in deps.items()])
  202. content = [
  203. "# THIS FILE HAS BEEN AUTOGENERATED. To update:",
  204. "# 1. modify the `_deps` dict in setup.py",
  205. "# 2. run `make deps_table_update``",
  206. "deps = {",
  207. entries,
  208. "}",
  209. "",
  210. ]
  211. target = "src/transformers/dependency_versions_table.py"
  212. print(f"updating {target}")
  213. with open(target, "w", encoding="utf-8", newline="\n") as f:
  214. f.write("\n".join(content))
  215. extras = {}
  216. extras["ja"] = deps_list("fugashi", "ipadic", "unidic_lite", "unidic", "sudachipy", "sudachidict_core", "rhoknp")
  217. extras["sklearn"] = deps_list("scikit-learn")
  218. extras["tf"] = deps_list("tensorflow", "onnxconverter-common", "tf2onnx", "tensorflow-text", "keras-nlp")
  219. extras["tf-cpu"] = deps_list("tensorflow-cpu", "onnxconverter-common", "tf2onnx", "tensorflow-text", "keras-nlp")
  220. extras["torch"] = deps_list("torch", "accelerate")
  221. extras["accelerate"] = deps_list("accelerate")
  222. if os.name == "nt": # windows
  223. extras["retrieval"] = deps_list("datasets") # faiss is not supported on windows
  224. extras["flax"] = [] # jax is not supported on windows
  225. else:
  226. extras["retrieval"] = deps_list("faiss-cpu", "datasets")
  227. extras["flax"] = deps_list("jax", "jaxlib", "flax", "optax")
  228. extras["tokenizers"] = deps_list("tokenizers")
  229. extras["ftfy"] = deps_list("ftfy")
  230. extras["onnxruntime"] = deps_list("onnxruntime", "onnxruntime-tools")
  231. extras["onnx"] = deps_list("onnxconverter-common", "tf2onnx") + extras["onnxruntime"]
  232. extras["modelcreation"] = deps_list("cookiecutter")
  233. extras["sagemaker"] = deps_list("sagemaker")
  234. extras["deepspeed"] = deps_list("deepspeed") + extras["accelerate"]
  235. extras["fairscale"] = deps_list("fairscale")
  236. extras["optuna"] = deps_list("optuna")
  237. extras["ray"] = deps_list("ray[tune]")
  238. extras["sigopt"] = deps_list("sigopt")
  239. extras["integrations"] = extras["optuna"] + extras["ray"] + extras["sigopt"]
  240. extras["serving"] = deps_list("pydantic", "uvicorn", "fastapi", "starlette")
  241. extras["audio"] = deps_list("librosa", "pyctcdecode", "phonemizer", "kenlm")
  242. # `pip install ".[speech]"` is deprecated and `pip install ".[torch-speech]"` should be used instead
  243. extras["speech"] = deps_list("torchaudio") + extras["audio"]
  244. extras["torch-speech"] = deps_list("torchaudio") + extras["audio"]
  245. extras["tf-speech"] = extras["audio"]
  246. extras["flax-speech"] = extras["audio"]
  247. extras["vision"] = deps_list("Pillow")
  248. extras["timm"] = deps_list("timm")
  249. extras["torch-vision"] = deps_list("torchvision") + extras["vision"]
  250. extras["natten"] = deps_list("natten")
  251. extras["codecarbon"] = deps_list("codecarbon")
  252. extras["video"] = deps_list("decord", "av")
  253. extras["sentencepiece"] = deps_list("sentencepiece", "protobuf")
  254. extras["testing"] = (
  255. deps_list(
  256. "pytest",
  257. "pytest-xdist",
  258. "timeout-decorator",
  259. "parameterized",
  260. "psutil",
  261. "datasets",
  262. "dill",
  263. "evaluate",
  264. "pytest-timeout",
  265. "black",
  266. "sacrebleu",
  267. "rouge-score",
  268. "nltk",
  269. "GitPython",
  270. "hf-doc-builder",
  271. "protobuf", # Can be removed once we can unpin protobuf
  272. "sacremoses",
  273. "rjieba",
  274. "beautifulsoup4",
  275. )
  276. + extras["retrieval"]
  277. + extras["modelcreation"]
  278. )
  279. extras["deepspeed-testing"] = extras["deepspeed"] + extras["testing"] + extras["optuna"] + extras["sentencepiece"]
  280. extras["quality"] = deps_list("black", "datasets", "isort", "ruff", "GitPython", "hf-doc-builder", "urllib3")
  281. extras["all"] = (
  282. extras["tf"]
  283. + extras["torch"]
  284. + extras["flax"]
  285. + extras["sentencepiece"]
  286. + extras["tokenizers"]
  287. + extras["torch-speech"]
  288. + extras["vision"]
  289. + extras["integrations"]
  290. + extras["timm"]
  291. + extras["torch-vision"]
  292. + extras["codecarbon"]
  293. + extras["accelerate"]
  294. + extras["video"]
  295. )
  296. # Might need to add doc-builder and some specific deps in the future
  297. extras["docs_specific"] = ["hf-doc-builder"]
  298. # "docs" needs "all" to resolve all the references
  299. extras["docs"] = extras["all"] + extras["docs_specific"]
  300. extras["dev-torch"] = (
  301. extras["testing"]
  302. + extras["torch"]
  303. + extras["sentencepiece"]
  304. + extras["tokenizers"]
  305. + extras["torch-speech"]
  306. + extras["vision"]
  307. + extras["integrations"]
  308. + extras["timm"]
  309. + extras["torch-vision"]
  310. + extras["codecarbon"]
  311. + extras["quality"]
  312. + extras["ja"]
  313. + extras["docs_specific"]
  314. + extras["sklearn"]
  315. + extras["modelcreation"]
  316. + extras["onnxruntime"]
  317. )
  318. extras["dev-tensorflow"] = (
  319. extras["testing"]
  320. + extras["tf"]
  321. + extras["sentencepiece"]
  322. + extras["tokenizers"]
  323. + extras["vision"]
  324. + extras["quality"]
  325. + extras["docs_specific"]
  326. + extras["sklearn"]
  327. + extras["modelcreation"]
  328. + extras["onnx"]
  329. + extras["tf-speech"]
  330. )
  331. extras["dev"] = (
  332. extras["all"]
  333. + extras["testing"]
  334. + extras["quality"]
  335. + extras["ja"]
  336. + extras["docs_specific"]
  337. + extras["sklearn"]
  338. + extras["modelcreation"]
  339. )
  340. extras["torchhub"] = deps_list(
  341. "filelock",
  342. "huggingface-hub",
  343. "importlib_metadata",
  344. "numpy",
  345. "packaging",
  346. "protobuf",
  347. "regex",
  348. "requests",
  349. "sentencepiece",
  350. "torch",
  351. "tokenizers",
  352. "tqdm",
  353. )
  354. extras["agents"] = deps_list(
  355. "diffusers", "accelerate", "datasets", "torch", "sentencepiece", "opencv-python", "Pillow"
  356. )
  357. # when modifying the following list, make sure to update src/transformers/dependency_versions_check.py
  358. install_requires = [
  359. deps["importlib_metadata"] + ";python_version<'3.8'", # importlib_metadata for Python versions that don't have it
  360. deps["filelock"], # filesystem locks, e.g., to prevent parallel downloads
  361. deps["huggingface-hub"],
  362. deps["numpy"],
  363. deps["packaging"], # utilities from PyPA to e.g., compare versions
  364. deps["pyyaml"], # used for the model cards metadata
  365. deps["regex"], # for OpenAI GPT
  366. deps["requests"], # for downloading models over HTTPS
  367. deps["tokenizers"],
  368. deps["safetensors"],
  369. deps["tqdm"], # progress bars in model download and training scripts
  370. ]
  371. setup(
  372. name="transformers",
  373. version="4.30.0.dev0", # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots)
  374. author="The Hugging Face team (past and future) with the help of all our contributors (https://github.com/huggingface/transformers/graphs/contributors)",
  375. author_email="transformers@huggingface.co",
  376. description="State-of-the-art Machine Learning for JAX, PyTorch and TensorFlow",
  377. long_description=open("README.md", "r", encoding="utf-8").read(),
  378. long_description_content_type="text/markdown",
  379. keywords="NLP vision speech deep learning transformer pytorch tensorflow jax BERT GPT-2 Wav2Vec2 ViT",
  380. license="Apache 2.0 License",
  381. url="https://github.com/huggingface/transformers",
  382. package_dir={"": "src"},
  383. packages=find_packages("src"),
  384. include_package_data=True,
  385. package_data={"": ["**/*.cu", "**/*.cpp", "**/*.cuh", "**/*.h", "**/*.pyx"]},
  386. zip_safe=False,
  387. extras_require=extras,
  388. entry_points={"console_scripts": ["transformers-cli=transformers.commands.transformers_cli:main"]},
  389. python_requires=">=3.7.0",
  390. install_requires=install_requires,
  391. classifiers=[
  392. "Development Status :: 5 - Production/Stable",
  393. "Intended Audience :: Developers",
  394. "Intended Audience :: Education",
  395. "Intended Audience :: Science/Research",
  396. "License :: OSI Approved :: Apache Software License",
  397. "Operating System :: OS Independent",
  398. "Programming Language :: Python :: 3",
  399. "Programming Language :: Python :: 3.7",
  400. "Programming Language :: Python :: 3.8",
  401. "Programming Language :: Python :: 3.9",
  402. "Programming Language :: Python :: 3.10",
  403. "Topic :: Scientific/Engineering :: Artificial Intelligence",
  404. ],
  405. cmdclass={"deps_table_update": DepsTableUpdateCommand},
  406. )