From 0c5615af6625ab2c3a5f07bc93ee738044346822 Mon Sep 17 00:00:00 2001 From: Lysandre Debut Date: Thu, 3 Dec 2020 14:28:49 -0500 Subject: [PATCH] Put Transformers on Conda (#8918) * conda * Guide * correct tag * Update README.md Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Update docs/source/installation.md Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Sylvain's comments Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> --- .github/conda/build.sh | 1 + .github/conda/meta.yaml | 48 +++++++++++++++++++++++++++++ .github/workflows/release-conda.yml | 43 ++++++++++++++++++++++++++ README.md | 18 +++++++++-- docs/source/installation.md | 26 ++++++++++++++-- 5 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 .github/conda/build.sh create mode 100644 .github/conda/meta.yaml create mode 100644 .github/workflows/release-conda.yml diff --git a/.github/conda/build.sh b/.github/conda/build.sh new file mode 100644 index 0000000000..a40f1097a8 --- /dev/null +++ b/.github/conda/build.sh @@ -0,0 +1 @@ +$PYTHON setup.py install # Python command to install the script. diff --git a/.github/conda/meta.yaml b/.github/conda/meta.yaml new file mode 100644 index 0000000000..da27594bd6 --- /dev/null +++ b/.github/conda/meta.yaml @@ -0,0 +1,48 @@ +{% set name = "transformers" %} + +package: + name: "{{ name|lower }}" + version: "{{ TRANSFORMERS_VERSION }}" + +source: + path: ../../ + +build: + noarch: python + +requirements: + host: + - python + - pip + - numpy + - dataclasses + - packaging + - filelock + - requests + - tqdm >=4.27 + - sacremoses + - regex !=2019.12.17 + - protobuf + - tokenizers ==0.9.4 + run: + - python + - numpy + - dataclasses + - packaging + - filelock + - requests + - tqdm >=4.27 + - sacremoses + - regex !=2019.12.17 + - protobuf + - tokenizers ==0.9.4 + +test: + imports: + - transformers + +about: + home: https://huggingface.co + license: Apache License 2.0 + license_file: LICENSE + summary: "🤗Transformers: State-of-the-art Natural Language Processing for Pytorch and TensorFlow 2.0." diff --git a/.github/workflows/release-conda.yml b/.github/workflows/release-conda.yml new file mode 100644 index 0000000000..74cc6aa068 --- /dev/null +++ b/.github/workflows/release-conda.yml @@ -0,0 +1,43 @@ +name: Release - Conda + +on: + push: + tags: + - v* + +env: + ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} + +jobs: + build_and_package: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + + steps: + - name: Checkout repository + uses: actions/checkout@v1 + + - name: Install miniconda + uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + auto-activate-base: false + activate-environment: "build-transformers" + channels: huggingface + + - name: Setup conda env + run: | + conda install -c defaults anaconda-client conda-build + + - name: Extract version + run: echo "TRANSFORMERS_VERSION=`python setup.py --version`" >> $GITHUB_ENV + + - name: Build conda packages + run: | + conda info + conda build .github/conda + + - name: Upload to Anaconda + run: anaconda upload `conda build .github/conda --output` --force \ No newline at end of file diff --git a/README.md b/README.md index 1a1b5b50ec..8bb2b5bbfc 100644 --- a/README.md +++ b/README.md @@ -137,14 +137,16 @@ The model itself is a regular [Pytorch `nn.Module`](https://pytorch.org/docs/sta ## Installation +### With pip + This repository is tested on Python 3.6+, PyTorch 1.0.0+ (PyTorch 1.3.1+ for [examples](https://github.com/huggingface/transformers/tree/master/examples)) and TensorFlow 2.0. You should install 🤗 Transformers in a [virtual environment](https://docs.python.org/3/library/venv.html). If you're unfamiliar with Python virtual environments, check out the [user guide](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/). First, create a virtual environment with the version of Python you're going to use and activate it. -Then, you will need to install one of, or both, TensorFlow 2.0 and PyTorch. -Please refer to [TensorFlow installation page](https://www.tensorflow.org/install/pip#tensorflow-2.0-rc-is-available) and/or [PyTorch installation page](https://pytorch.org/get-started/locally/#start-locally) regarding the specific install command for your platform. +Then, you will need to install at least one of TensorFlow 2.0, PyTorch or Flax. +Please refer to [TensorFlow installation page](https://www.tensorflow.org/install/pip#tensorflow-2.0-rc-is-available), [PyTorch installation page](https://pytorch.org/get-started/locally/#start-locally) regarding the specific install command for your platform and/or [Flax installation page](https://github.com/google/flax#quick-install). When TensorFlow 2.0 and/or PyTorch has been installed, 🤗 Transformers can be installed using pip as follows: @@ -154,6 +156,18 @@ pip install transformers If you'd like to play with the examples, you must [install the library from source](https://huggingface.co/transformers/installation.html#installing-from-source). +### With conda + +Since Transformers version v4.0.0, we now have a conda channel: `huggingface`. + +🤗 Transformers can be installed using conda as follows: + +```shell script +conda install -c huggingface transformers +``` + +Follow the installation pages of TensorFlow, PyTorch or Flax to see how to install them with conda. + ## Models architectures **[All the model checkpoints](https://huggingface.co/models)** provided by 🤗 Transformers are seamlessly integrated from the huggingface.co [model hub](https://huggingface.co) where they are uploaded directly by [users](https://huggingface.co/users) and [organizations](https://huggingface.co/organizations). diff --git a/docs/source/installation.md b/docs/source/installation.md index 4f657ca8b6..6262082899 100644 --- a/docs/source/installation.md +++ b/docs/source/installation.md @@ -12,9 +12,10 @@ must install it from source. ## Installation with pip First you need to install one of, or both, TensorFlow 2.0 and PyTorch. -Please refer to [TensorFlow installation page](https://www.tensorflow.org/install/pip#tensorflow-2.0-rc-is-available) -and/or [PyTorch installation page](https://pytorch.org/get-started/locally/#start-locally) regarding the specific -install command for your platform. +Please refer to [TensorFlow installation page](https://www.tensorflow.org/install/pip#tensorflow-2.0-rc-is-available), +[PyTorch installation page](https://pytorch.org/get-started/locally/#start-locally) and/or +[Flax installation page](https://github.com/google/flax#quick-install) +regarding the specific install command for your platform. When TensorFlow 2.0 and/or PyTorch has been installed, 🤗 Transformers can be installed using pip as follows: @@ -34,6 +35,12 @@ or 🤗 Transformers and TensorFlow 2.0 in one line with: pip install transformers[tf-cpu] ``` +or 🤗 Transformers and Flax in one line with: + +```bash +pip install transformers[flax] +``` + To check 🤗 Transformers is properly installed, run the following command: ```bash @@ -66,6 +73,19 @@ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis to check 🤗 Transformers is properly installed. + +## With conda + +Since Transformers version v4.0.0, we now have a conda channel: `huggingface`. + +🤗 Transformers can be installed using conda as follows: + +``` +conda install -c huggingface transformers +``` + +Follow the installation pages of TensorFlow, PyTorch or Flax to see how to install them with conda. + ## Caching models This library provides pretrained models that will be downloaded and cached locally. Unless you specify a location with