-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Fix incorrect installation instructions (for issue #37476) #37640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
b8004ac
e00de08
e2d659d
aa095f5
2bf8832
fb45c3e
c53ddbb
f7d8fc8
f609a13
ccd68db
e4bec10
f4e6049
c6ac065
c6db4e7
bef9789
6be14e8
f6797c8
a58730a
7a10e7a
3195f5d
baa3876
664c5c3
e2d9e7a
e7321e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,18 +70,31 @@ Explore the [Hub](https://huggingface.com/) today to find a model and use Transf | |
|
|
||
| ## Installation | ||
|
|
||
| Transformers works with Python 3.9+ [PyTorch](https://pytorch.org/get-started/locally/) 2.1+, [TensorFlow](https://www.tensorflow.org/install/pip) 2.6+, and [Flax](https://flax.readthedocs.io/en/latest/) 0.4.1+. | ||
| Transformers works with Python 3.9-3.12 [PyTorch](https://pytorch.org/get-started/locally/) 2.1+, [TensorFlow](https://www.tensorflow.org/install/pip) 2.6+, and [Flax](https://flax.readthedocs.io/en/latest/) 0.4.1+. | ||
|
||
|
|
||
| Create and activate a virtual environment with [venv](https://docs.python.org/3/library/venv.html) or [uv](https://docs.astral.sh/uv/), a fast Rust-based Python package and project manager. | ||
|
|
||
| ```py | ||
| # venv | ||
| python -m venv .my-env | ||
| source .my-env/bin/activate | ||
|
|
||
| pip install "jax>=0.4.1,<=0.4.13" | ||
| pip install "optax>=0.0.8,<=0.1.4" | ||
| pip install "orbax-checkpoint==0.2.3" | ||
| pip install "torch>=2.1" | ||
| pip install "tensorflow>2.9,<2.16" | ||
| pip install "flax>=0.4.1,<=0.7.0" | ||
| pip install "accelerate>=0.26.0" | ||
| # uv | ||
| uv venv .my-env | ||
| source .my-env/bin/activate | ||
| uv pip install "jax>=0.4.1,<=0.4.13" | ||
| uv pip install "optax>=0.0.8,<=0.1.4" | ||
| uv pip install "orbax-checkpoint==0.2.3" | ||
| uv pip install "torch>=2.1" | ||
| uv pip install "tensorflow>2.9,<2.16" | ||
| uv pip install "flax>=0.4.1,<=0.7.0" | ||
| uv pip install "accelerate>=0.26.0" | ||
| ``` | ||
|
|
||
| Install Transformers in your virtual environment. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env bash | ||
| set -e # exit on error | ||
| set -u # error on undefined vars | ||
| set -o pipefail | ||
|
|
||
| # === Config === | ||
| PYTHON_VERSION_REQUIRED=">=3.9,<3.13" | ||
| VENV_DIR=".my-env" | ||
| REQUIREMENTS_URL="https://raw.githubusercontent.com/huggingface/transformers/main/examples/pytorch/_tests_requirements.txt" | ||
|
|
||
| # === Validate Python Version === | ||
| echo "Checking Python version..." | ||
| PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:3])))') | ||
| if ! python3 -c 'import sys; assert (3, 9) <= sys.version_info[:2] < (3, 13), "Python >=3.9 and <3.13 required."' ; then | ||
| echo "Unsupported Python version: $(python3 --version)" | ||
| exit 1 | ||
| else | ||
| echo "✅ Python $PYTHON_VERSION is OK." | ||
| fi | ||
|
|
||
| # === Create Virtual Env === | ||
| echo "Creating virtual environment at $VENV_DIR" | ||
| python3 -m venv "$VENV_DIR" | ||
| source "$VENV_DIR/bin/activate" | ||
|
|
||
| # === Upgrade pip === | ||
| pip install --upgrade pip setuptools | ||
|
|
||
| # === Install Required Packages === | ||
| echo "Installing required packages..." | ||
| pip install "jax>=0.4.1,<=0.4.13" | ||
|
||
| pip install "optax>=0.0.8,<=0.1.4" | ||
| pip install "orbax-checkpoint==0.2.3" | ||
| pip install "torch>=2.1" | ||
| pip install "tensorflow>2.9,<2.16" | ||
| pip install "flax>=0.4.1,<=0.7.0" | ||
| pip install "accelerate>=0.26.0" | ||
| pip install "transformers" | ||
| pip install -r <(curl -s "$REQUIREMENTS_URL") # optional extras for tests/examples | ||
|
|
||
| # === Validate Install === | ||
| echo "Validating installation..." | ||
| python -c 'from transformers import pipeline; pipeline = pipeline(task="text-generation", model="Qwen/Qwen2.5-1.5B"); print(pipeline("the secret to baking a really good cake is "))' | ||
|
|
||
| echo "Installation complete!" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| filelock | ||
|
||
| huggingface-hub>=0.30.0,<1.0 | ||
| numpy>=1.17 | ||
| packaging>=20.0 | ||
| pyyaml>=5.1 | ||
| regex!=2019.12.17 | ||
| requests | ||
| tokenizers>=0.21,<0.22 | ||
| safetensors>=0.4.3 | ||
| tqdm>=4.27 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The meaning behind the DRY principle is a bit deeper than "don't repeat yourself." Rather, DRY is a principle of software development aimed at reducing repetition of information likely to change. By documenting the versions in two places (README.md, requirements.txt file) the information has been repeated, which will inevitably lead to one or the other going stale.
Instead, keep the requirements inside of requirements.txt file and direct the reader to read that file, because it captures the same information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion! Will do that.