Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .ai/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
- `make style`: runs formatters and linters (ruff), necessary to pass code style checks
- `make typing`: runs the ty type checker and model structure rules
- `make fix-repo`: auto-fixes copies, modular conversions, doc TOCs, docstrings in addition to the `make style` fixes
- `make check-repo` — CI-style consistency checks (includes `make typing`)
- `make check-repo` — runs `make typing` and consistency checks.
- Many tests are marked as 'slow' and skipped by default in the CI. To run them, use: `RUN_SLOW=1 pytest ...`

`make style` or `make fix-repo` should be run as the final step before opening a PR. The CI will run `make check-repo` and fail if any issues are found.
`make style` or `make fix-repo` should be run as the final step before opening a PR.

## Local agent setup

Expand Down
28 changes: 3 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ jobs:
command: pip freeze | tee installed.txt
- store_artifacts:
path: ~/transformers/installed.txt
- run: ruff check examples tests src utils scripts benchmark benchmark_v2 setup.py conftest.py
- run: ruff format --check examples tests src utils scripts benchmark benchmark_v2 setup.py conftest.py
- run: ty check src/transformers/utils/*.py --force-exclude --exclude '**/*_pb2*.py'
- run: python utils/custom_init_isort.py --check_only
- run: python utils/sort_auto_mappings.py --check_only
- run: make check-code-quality

check_repository_consistency:
working_directory: ~/transformers
Expand All @@ -171,32 +167,14 @@ jobs:
parallelism: 1
steps:
- checkout
- run: apt-get update && apt-get install -y make
- run: uv pip install -e ".[quality]"
- run:
name: Show installed libraries and their versions
command: pip freeze | tee installed.txt
- store_artifacts:
path: ~/transformers/installed.txt
- run: python -c "from transformers import *" || (echo '🚨 import failed, this means you introduced unprotected imports! 🚨'; exit 1)
- run: python utils/check_copies.py
- run: python utils/check_modular_conversion.py
- run: python utils/check_doc_toc.py
- run: python utils/check_docstrings.py
- run: python utils/check_dummies.py
- run: python utils/check_repo.py
- run: python -m utils.mlinter
- run: python utils/check_inits.py
- run: python utils/check_pipeline_typing.py
- run: python utils/check_config_docstrings.py
- run: python utils/check_config_attributes.py
- run: python utils/check_doctest_list.py
- run: python utils/update_metadata.py --check-only
- run: python utils/add_dates.py --check-only
- run: >
md5sum src/transformers/dependency_versions_table.py > md5sum.saved;
python setup.py deps_table_update;
md5sum -c --quiet md5sum.saved || (printf "Error: the version dependency table is outdated.\nPlease run 'make fix-repo' and commit the changes.\n" && exit 1);
rm md5sum.saved
- run: make check-repository-consistency

workflows:
version: 2
Expand Down
144 changes: 83 additions & 61 deletions Makefile

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

trust you on the details of this :-)

Original file line number Diff line number Diff line change
@@ -1,74 +1,96 @@
# make sure to test the local checkout in scripts and not the pre-installed one (don't use quotes!)
export PYTHONPATH = src

.PHONY: style typing check-repo fix-repo test test-examples benchmark codex claude clean-ai
.PHONY: style typing check-code-quality check-repository-consistency check-repo fix-repo test test-examples benchmark codex claude clean-ai

check_dirs := examples tests src utils scripts benchmark benchmark_v2
exclude_folders := ""

# Directories to type-check with ty
ty_check_dirs := src/transformers/_typing.py src/transformers/utils src/transformers/generation src/transformers/quantizers


# this runs all linting/formatting scripts, most notably ruff
# Runs all linting/formatting scripts, most notably ruff
style:
ruff check $(check_dirs) setup.py conftest.py --fix --exclude $(exclude_folders)
ruff format $(check_dirs) setup.py conftest.py --exclude $(exclude_folders)
python utils/custom_init_isort.py
python utils/sort_auto_mappings.py

# Run ty type checker and model structure rules
@python utils/checkers.py \
ruff_check,\
ruff_format,\
init_isort,\
auto_mappings \
--fix

# Runs ty type checker and model structure rules
typing:
python utils/check_types.py $(ty_check_dirs)
python -m utils.mlinter

# Check that the repo is in a good state (both style and consistency CI checks)
# Note: each line is run in its own shell, and doing `-` before the command ignores the errors if any, continuing with next command
@python utils/checkers.py \
types,\
modeling_structure

# Runs typing, ruff linting/formatting, import-order checks and auto-mappings
check-code-quality:
@python utils/checkers.py \
types,\
modeling_structure,\
ruff_check,\
ruff_format,\
init_isort,\
auto_mappings

# Runs a full repository consistency check.
check-repository-consistency:
@python utils/checkers.py \
imports,\
copies,\
modular_conversion,\
doc_toc,\
docstrings,\
dummies,\
repo,\
inits,\
pipeline_typing,\
config_docstrings,\
config_attributes,\
doctest_list,\
update_metadata,\
add_dates,\
deps_table

# Runs typing and formatting checks + repository consistency check (ignores errors)
check-repo:
ruff check $(check_dirs) setup.py conftest.py
ruff format --check $(check_dirs) setup.py conftest.py
python utils/check_types.py $(ty_check_dirs)
python -m utils.mlinter
-python utils/custom_init_isort.py --check_only
-python utils/sort_auto_mappings.py --check_only
-python -c "from transformers import *" || (echo '🚨 import failed, this means you introduced unprotected imports! 🚨'; exit 1)
-python utils/check_copies.py
-python utils/check_modular_conversion.py
-python utils/check_doc_toc.py
-python utils/check_docstrings.py
-python utils/check_dummies.py
-python utils/check_repo.py
-python utils/check_inits.py
-python utils/check_pipeline_typing.py
-python utils/check_config_docstrings.py
-python utils/check_config_attributes.py
-python utils/check_doctest_list.py
-python utils/update_metadata.py --check-only
-python utils/add_dates.py --check-only
-@{ \
md5sum src/transformers/dependency_versions_table.py > md5sum.saved; \
python setup.py deps_table_update; \
md5sum -c --quiet md5sum.saved || (printf "Error: the version dependency table is outdated.\nPlease run 'make fix-repo' and commit the changes. This requires Python 3.10.\n" && exit 1); \
rm md5sum.saved; \
}




@python utils/checkers.py \
ruff_check,\
ruff_format,\
types,\
modeling_structure,\
init_isort,\
auto_mappings,\
imports,\
copies,\
modular_conversion,\
doc_toc,\
docstrings,\
dummies,\
repo,\
inits,\
pipeline_typing,\
config_docstrings,\
config_attributes,\
doctest_list,\
update_metadata,\
add_dates,\
deps_table \
--keep-going

# Run all repo checks for which there is an automatic fix, most notably modular conversions
# Note: each line is run in its own shell, and doing `-` before the command ignores the errors if any, continuing with next command
fix-repo: style
-python setup.py deps_table_update
-python utils/check_doc_toc.py --fix_and_overwrite
-python utils/check_copies.py --fix_and_overwrite
-python utils/check_modular_conversion.py --fix_and_overwrite
-python utils/check_dummies.py --fix_and_overwrite
-python utils/check_pipeline_typing.py --fix_and_overwrite
-python utils/check_doctest_list.py --fix_and_overwrite
-python utils/check_docstrings.py --fix_and_overwrite
-python utils/add_dates.py

fix-repo:
@python utils/checkers.py \
ruff_check,\
ruff_format,\
init_isort,\
auto_mappings,\
doc_toc,\
copies,\
modular_conversion,\
dummies,\
pipeline_typing,\
doctest_list,\
docstrings,\
add_dates,\
deps_table \
--fix --keep-going

# Run tests for the library, requires pytest-random-order
test:
Expand Down
2 changes: 1 addition & 1 deletion docker/quality.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:3.10-slim
ENV PYTHONDONTWRITEBYTECODE=1
ARG REF=main
USER root
RUN apt-get update && apt-get install -y time git
RUN apt-get update && apt-get install -y time git make
ENV UV_PYTHON=/usr/local/bin/python
RUN pip install uv
RUN uv pip install --no-cache-dir -U pip setuptools GitPython "git+https://github.com/huggingface/transformers.git@${REF}#egg=transformers[quality]" urllib3
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"sudachidict_core>=20220729",
"tensorboard",
"timeout-decorator",
"tomli",
"tiktoken",
"timm>=1.0.23",
"tokenizers>=0.22.0,<=0.23.0",
Expand Down Expand Up @@ -181,7 +182,7 @@ def deps_list(*pkgs):
extras["audio"] += deps_list("kenlm")
extras["video"] = deps_list("av")
extras["timm"] = deps_list("timm")
extras["quality"] = deps_list("datasets", "ruff", "GitPython", "urllib3", "libcst", "rich", "ty")
extras["quality"] = deps_list("datasets", "ruff", "GitPython", "urllib3", "libcst", "rich", "ty", "tomli")
extras["kernels"] = deps_list("kernels")
extras["sentencepiece"] = deps_list("sentencepiece", "protobuf")
extras["tiktoken"] = deps_list("tiktoken", "blobfile")
Expand Down
1 change: 1 addition & 0 deletions src/transformers/dependency_versions_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"sudachidict_core": "sudachidict_core>=20220729",
"tensorboard": "tensorboard",
"timeout-decorator": "timeout-decorator",
"tomli": "tomli",
"tiktoken": "tiktoken",
"timm": "timm>=1.0.23",
"tokenizers": "tokenizers>=0.22.0,<=0.23.0",
Expand Down
Loading
Loading