Implementation:Huggingface Transformers Setup Py
| Knowledge Sources | |
|---|---|
| Domains | Build_System, Package_Management |
| Last Updated | 2026-02-13 20:00 GMT |
Overview
Concrete tool for building and installing the Transformers package, defining all dependencies, optional extras, and PyPI metadata.
Description
The setup.py file is the single source of truth for all package dependencies and installation configuration. It defines a complete dependency table (_deps) with approximately 90 packages and version constraints, then builds a lookup dictionary for easy reference. It configures numerous extras groups including torch, vision, audio, video, timm, quality, kernels, sentencepiece, tiktoken, sklearn, accelerate, deepspeed, testing, all, and dev. Some extras are conditionally included based on Python minor version. Hard install requirements are minimal: huggingface-hub, numpy, packaging, pyyaml, regex, tokenizers, typer-slim, safetensors, tqdm. Includes a DepsTableUpdateCommand that regenerates dependency_versions_table.py.
Usage
Used by pip, build tools, and CI pipelines to install the Transformers package with appropriate dependencies. End users invoke it indirectly via pip install transformers or pip install transformers[torch,vision].
Code Reference
Source Location
- Repository: Huggingface_Transformers
- File: setup.py
- Lines: 1-357
Signature
def deps_list(*deps: str) -> List[str]:
"""Return list of dependency strings from the _deps table."""
class DepsTableUpdateCommand(Command):
"""Custom setuptools command to update dependency_versions_table.py."""
setup(
name="transformers",
version="5.2.0.dev0",
python_requires=">=3.10.0",
install_requires=[
"huggingface-hub>=0.30.0,<1.0",
"numpy>=1.17",
"packaging>=20.0",
"pyyaml>=5.1",
"regex!=2019.12.17",
"tokenizers>=0.21,<0.22",
"safetensors>=0.5.2",
"tqdm>=4.27",
],
)
Import
pip install transformers
pip install transformers[torch,vision]
pip install -e ".[dev]"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| Python environment | Runtime | Yes | Python 3.10+ environment |
| extras specifier | str | No | Optional extras group (e.g., [torch], [all]) |
Outputs
| Name | Type | Description |
|---|---|---|
| Installed package | Python package | transformers package installed in environment |
| dependency_versions_table.py | Python file | Updated when DepsTableUpdateCommand is run |
Usage Examples
Standard Installation
# Install with PyTorch support
pip install transformers[torch]
# Install with all optional dependencies
pip install transformers[all]
# Install for development
pip install -e ".[dev]"