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