Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8004ac
debugging issue 36758
Zephyr271828 Mar 17, 2025
e00de08
debugging issue 36758
Zephyr271828 Mar 17, 2025
e2d659d
debugging issue 36758
Zephyr271828 Mar 17, 2025
aa095f5
updated attn_mask type specification in _flash_attention_forward
Zephyr271828 Mar 31, 2025
2bf8832
Merge branch 'Yufeng-Xu' of github.com:Zephyr271828/transformers into…
Zephyr271828 Mar 31, 2025
fb45c3e
removed pdb
Zephyr271828 Mar 31, 2025
c53ddbb
added a blank line
Zephyr271828 Mar 31, 2025
f7d8fc8
removed indentation
Zephyr271828 Mar 31, 2025
f609a13
Merge branch 'time-strategy' of github.com:Zephyr271828/transformers …
Zephyr271828 Apr 9, 2025
ccd68db
update constants
Zephyr271828 Apr 10, 2025
e4bec10
remove unnecessary files
Zephyr271828 Apr 10, 2025
f4e6049
Merge branch 'main' of github.com:Zephyr271828/transformers into inst…
Zephyr271828 Apr 14, 2025
c6ac065
created installation script, modified README
Zephyr271828 Apr 15, 2025
c6db4e7
modified requirements and install.sh
Zephyr271828 Apr 20, 2025
bef9789
Merge branch 'huggingface:main' into installation
Zephyr271828 Apr 20, 2025
6be14e8
undo irrelevant changes
Zephyr271828 Apr 20, 2025
f6797c8
Merge branch 'installation' of github.com:Zephyr271828/transformers i…
Zephyr271828 Apr 20, 2025
a58730a
removed blank line
Zephyr271828 Apr 20, 2025
7a10e7a
fixing installation guide
Zephyr271828 Apr 21, 2025
3195f5d
modified README, python requirements, and install script
Zephyr271828 May 6, 2025
baa3876
merged conflicts in setup.py
Zephyr271828 May 6, 2025
664c5c3
removed tests_otuput
Zephyr271828 May 6, 2025
e2d9e7a
modified README
Zephyr271828 May 6, 2025
e7321e0
discarded installation script and python<3.13 requirement
Zephyr271828 May 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+.

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.

Copy link
Contributor Author

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.

Great suggestion! Will do that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Python 3.9 to 3.12 or Python 3.9 - 3.12

Note the space in the second, which will distinguish from potentially oddball versions (i.e., there is no version with the literal expression 3.9-3.12).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Python 3.9 to 3.12 or Python 3.9 - 3.12

Note the space in the second, which will distinguish from potentially oddball versions (i.e., there is no version with the literal expression 3.9-3.12).

Thanks, will modify this!


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.
Expand Down
45 changes: 45 additions & 0 deletions requirements/install.sh
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these pip instructions different than the files listed inside the requirements.txt file? And why are the versions repeated all over the place? They're listed like 5 times, a quintuplication of information.

Is there a way to reference the requirements.txt file from the script?

Like xargs pip install < requirements.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these pip instructions different than the files listed inside the requirements.txt file? And why are the versions repeated all over the place? They're listed like 5 times, a quintuplication of information.

Is there a way to reference the requirements.txt file from the script?

Like xargs pip install < requirements.txt?

Referring to requirements.txt sounds more reasonable and I will do that, but I need to think about what to put in requirements.txt a bit more. Will ping you again if my revision is completed!

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!"
10 changes: 10 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
filelock

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall having to install most of these on my system. Did you spin up a base Arch (or Debian) image with a bare minimum install and see what's required to run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall having to install most of these on my system. Did you spin up a base Arch (or Debian) image with a bare minimum install and see what's required to run?

Dear @DarkTyger, thank you so much for your detailed suggestions! I will try my best and keep polishing my PR until it can be merged.
As for requirements.txt, I was referring to setup.py and I believe the packages listed here are the prerequisites for installing the transformer packages. So I guess they should be included in the requirements.txt?

Copy link
Contributor Author

@Zephyr271828 Zephyr271828 Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear @DarkTyger, after some further investigation of the issue, I think I may need some clarifications on what the fix should be like. Considering your suggestions in the issue:

  1. fix python version requirements;
  2. a requirements.txt file that people can download;
  3. a shell script that can install and validate the requisite versions;
  4. explicitly list all instructions that'll work for most people.

The first one is very reasonable and I will submit a fix soon.
However, I'm not quite sure if adding requirements.txt, installation script, or explicitly listing the instructions is necessary? I'm asking this question for 2 reasons:

  • setup.py may be sufficient for installation, and adding requirements.txt or installation script can be repetitive. I don't know what you mean by "work for most people"? It turns out using pip install "transformers[all]" or pip install .[all] installs all the required packages and the quickstart examples can be used immediately after running one of these 2 commands. Therefore, adding requirements.txt or installation script can be repetitive, violating the DRY principle you mentioned earlier.
  • In the examples folder, requirements files are provided for different use cases, but they are quite different from task to task so it's hard to determine what are the core packages to include. Moreover, the examples and their requirements are not maintained frequently. Maybe the repo is not designed to use requirements.txt for installation.

As for the packages you mentioned (torch, tensorflow, flax, accelerate, and transformers), I believe pip install transformers[all] is the command you want to try. You may refer to here.
Please correct me if I made anything wrong.

Copy link

@DarkTyger DarkTyger Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how else to put this; the documentation is incorrect.

  1. Create a new virtual OS (or container) with latest Python.
  2. Visit https://pypi.org/project/transformers
  3. Follow the instructions as shown.

Expected

Instructions work.

Actual

pip install transformers fails (for a few reasons, including Python version and missing [all]).

Whether a script, a requirements.txt file, or an update to the documentation is the solution, wasn't really my point. My points are:

  • when drafting instructions, avoid repeating information that is likely to change; and
  • ensure the instructions are tested in a clean environment on supported platforms.

If following the instructions verbatim (and that's key) fails, then the instructions are wrong.

Aside, written instructions in README.md are hard to test automatically, which is why I recommended writing a script. If the instructions become "1. download script; 2. run script" then that can be tested within containerized environments. When problems are encountered, the script gets the fixes, and the automated test guards against regressions. This means the README.md needn't change to put in a fix because the requirements are captured programmatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DarkTyger sorry for the late reply. I just made a new version of the PR, and would be grateful if you could check if this version looks good to you.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked over the changes briefly. They look much better!

Copy link
Contributor Author

@Zephyr271828 Zephyr271828 May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad to hear that! Thank you for your suggestions!
@Rocketknight1 @ArthurZucker Could you please help check if this PR looks ok and consistent with the style of the repo?

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
Empty file added tests_output.txt
Empty file.