Implementation:Huggingface Transformers Deprecate Models
| Knowledge Sources | |
|---|---|
| Domains | Repository_Maintenance, Model_Lifecycle |
| Last Updated | 2026-02-13 20:00 GMT |
Overview
Concrete tool for automating the full deprecation workflow for one or more Transformers models.
Description
The deprecate_models.py utility performs all the file moves, reference updates, and documentation changes needed to mark models as deprecated. For each model specified via --models, the script: (1) adds a deprecation tip to the model documentation page, (2) removes # Copied from statements from model files, (3) moves model source files from src/transformers/models/{model} to src/transformers/models/deprecated/{model} using git mv and updates relative imports, (4) deletes the model test directory, (5) updates the main __init__.py to point to the deprecated path, (6) removes model references from auxiliary files, (7) removes config classes from check_config_attributes.py, and (8) adds the model to the DEPRECATED_MODELS list in configuration_auto.py. It queries PyPI for the last stable release version for deprecation messages.
Usage
Run this script when deprecating models that have been identified by models_to_deprecate.py or by manual analysis.
Code Reference
Source Location
- Repository: Huggingface_Transformers
- File: utils/deprecate_models.py
- Lines: 1-377
Signature
def insert_tip_to_model_doc(model_name: str, version: str) -> None:
"""Add a deprecation warning tip to the model's doc page."""
def move_model_files_to_deprecated(model_name: str) -> None:
"""Move model source files to the deprecated directory via git mv."""
def update_relative_imports(model_name: str) -> None:
"""Update import paths after moving model files."""
def remove_copied_from_statements(model_name: str) -> None:
"""Remove '# Copied from' annotations from model files."""
Import
python utils/deprecate_models.py --models old_model_1 old_model_2
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| --models | List[str] | Yes | Model names to deprecate |
Outputs
| Name | Type | Description |
|---|---|---|
| Moved files | Git operations | Model files moved to deprecated/ via git mv |
| Updated files | Multiple | Modified __init__.py, configuration_auto.py, docs, and utility files |
| Deleted test dirs | Directories | Removed test directories for deprecated models |
Usage Examples
Deprecating Models
# Deprecate specific models
python utils/deprecate_models.py --models transfo_xl xlnet
# The script will:
# 1. Add deprecation tips to documentation
# 2. Move source files to deprecated/
# 3. Delete test directories
# 4. Update all references