From 35826de91b1059e49bc12992c7be327f6dd2bf36 Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Thu, 24 Jul 2025 15:44:07 +0200 Subject: [PATCH 1/4] update release.py --- utils/release.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/utils/release.py b/utils/release.py index e4e79cec1589..96e37246ab38 100644 --- a/utils/release.py +++ b/utils/release.py @@ -59,6 +59,8 @@ "examples": (re.compile(r'^check_min_version\("[^"]+"\)\s*$', re.MULTILINE), 'check_min_version("VERSION")\n'), "init": (re.compile(r'^__version__\s+=\s+"([^"]+)"\s*$', re.MULTILINE), '__version__ = "VERSION"\n'), "setup": (re.compile(r'^(\s*)version\s*=\s*"[^"]+",', re.MULTILINE), r'\1version="VERSION",'), + "uv_script_release": (re.compile(r'^# "transformers(\[.+\])?.*$', re.MULTILINE), r'# "transformers\g<1>==VERSION",'), + "uv_script_dev": (re.compile(r'^# "transformers(\[.+\])?.*$', re.MULTILINE), r'# "transformers\g<1> @ git+https://github.com/huggingface/transformers.git",'), } # This maps a type of file to its path in Transformers REPLACE_FILES = { @@ -66,6 +68,7 @@ "setup": "setup.py", } README_FILE = "README.md" +UV_SCRIPT_MARKER = "# /// script" def update_version_in_file(fname: str, version: str, file_type: str): @@ -86,12 +89,13 @@ def update_version_in_file(fname: str, version: str, file_type: str): f.write(code) -def update_version_in_examples(version: str): +def update_version_in_examples(version: str, patch: bool = False): """ Update the version in all examples files. Args: version (`str`): The new version to set in the examples. + patch (`bool`, *optional*, defaults to `False`): Whether or not this is a patch release. """ for folder, directories, fnames in os.walk(PATH_TO_EXAMPLES): # Removing some of the folders with non-actively maintained examples from the walk @@ -99,7 +103,13 @@ def update_version_in_examples(version: str): directories.remove("legacy") for fname in fnames: if fname.endswith(".py"): - update_version_in_file(os.path.join(folder, fname), version, file_type="examples") + if UV_SCRIPT_MARKER in Path(folder, fname).read_text(): + # Update the depdendencies in UV scripts + uv_script_file_type = "uv_script_dev" if ".dev" in version else "uv_script_release" + update_version_in_file(os.path.join(folder, fname), version, file_type=uv_script_file_type) + if not patch: + # We don't update the version in the examples for patch releases. + update_version_in_file(os.path.join(folder, fname), version, file_type="examples") def global_version_update(version: str, patch: bool = False): @@ -112,9 +122,7 @@ def global_version_update(version: str, patch: bool = False): """ for pattern, fname in REPLACE_FILES.items(): update_version_in_file(fname, version, pattern) - if not patch: - # We don't update the version in the examples for patch releases. - update_version_in_examples(version) + update_version_in_examples(version, patch=patch) def remove_conversion_scripts(): From 4e49c4cc66c78ef789f4502670e909892174f71a Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Thu, 24 Jul 2025 16:09:24 +0200 Subject: [PATCH 2/4] add uv headers in some pytorch examples --- .../pytorch/audio-classification/requirements.txt | 5 ++--- .../run_audio_classification.py | 9 +++++++++ .../pytorch/contrastive-image-text/run_clip.py | 10 ++++++++++ .../run_image_classification.py | 12 ++++++++++++ .../run_image_classification_no_trainer.py | 13 +++++++++++++ examples/pytorch/image-pretraining/run_mae.py | 9 +++++++++ examples/pytorch/image-pretraining/run_mim.py | 9 +++++++++ .../image-pretraining/run_mim_no_trainer.py | 9 +++++++++ .../run_instance_segmentation.py | 11 +++++++++++ .../run_instance_segmentation_no_trainer.py | 11 +++++++++++ examples/pytorch/language-modeling/run_clm.py | 15 +++++++++++++++ .../language-modeling/run_clm_no_trainer.py | 15 +++++++++++++++ examples/pytorch/language-modeling/run_fim.py | 15 +++++++++++++++ .../language-modeling/run_fim_no_trainer.py | 15 +++++++++++++++ examples/pytorch/language-modeling/run_mlm.py | 15 +++++++++++++++ .../language-modeling/run_mlm_no_trainer.py | 15 +++++++++++++++ examples/pytorch/language-modeling/run_plm.py | 15 +++++++++++++++ examples/pytorch/multiple-choice/run_swag.py | 12 ++++++++++++ .../multiple-choice/run_swag_no_trainer.py | 12 ++++++++++++ .../object-detection/run_object_detection.py | 11 +++++++++++ .../run_object_detection_no_trainer.py | 12 ++++++++++++ 21 files changed, 247 insertions(+), 3 deletions(-) diff --git a/examples/pytorch/audio-classification/requirements.txt b/examples/pytorch/audio-classification/requirements.txt index acf058d4cf46..1a2309342b4e 100644 --- a/examples/pytorch/audio-classification/requirements.txt +++ b/examples/pytorch/audio-classification/requirements.txt @@ -1,5 +1,4 @@ -datasets>=1.14.0 +datasets[audio]>=1.14.0 evaluate -librosa torchaudio -torch>=1.6 \ No newline at end of file +torch>=1.6 diff --git a/examples/pytorch/audio-classification/run_audio_classification.py b/examples/pytorch/audio-classification/run_audio_classification.py index a06f334bdc6e..0518fae2dc1e 100644 --- a/examples/pytorch/audio-classification/run_audio_classification.py +++ b/examples/pytorch/audio-classification/run_audio_classification.py @@ -13,6 +13,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "torch>=1.5.0", +# "torchvision>=0.6.0", +# "datasets>=1.8.0", +# ] +# /// + import logging import os import sys diff --git a/examples/pytorch/contrastive-image-text/run_clip.py b/examples/pytorch/contrastive-image-text/run_clip.py index 58dba1083cf4..229c97dd4f33 100644 --- a/examples/pytorch/contrastive-image-text/run_clip.py +++ b/examples/pytorch/contrastive-image-text/run_clip.py @@ -12,6 +12,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "torch>=1.5.0", +# "torchvision>=0.6.0", +# "datasets>=1.8.0", +# ] +# /// + """ Training a CLIP like dual encoder models using text and vision encoders in the library. diff --git a/examples/pytorch/image-classification/run_image_classification.py b/examples/pytorch/image-classification/run_image_classification.py index ff2e8873ba7b..baf8f15d92c9 100755 --- a/examples/pytorch/image-classification/run_image_classification.py +++ b/examples/pytorch/image-classification/run_image_classification.py @@ -12,6 +12,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate>=0.12.0", +# "torch>=1.5.0", +# "torchvision>=0.6.0", +# "datasets>=2.14.0", +# "evaluate", +# "scikit-learn", +# ] +# /// + import logging import os import sys diff --git a/examples/pytorch/image-classification/run_image_classification_no_trainer.py b/examples/pytorch/image-classification/run_image_classification_no_trainer.py index 49fa4bd0fdf8..30a65e6b6e6f 100644 --- a/examples/pytorch/image-classification/run_image_classification_no_trainer.py +++ b/examples/pytorch/image-classification/run_image_classification_no_trainer.py @@ -11,6 +11,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate>=0.12.0", +# "torch>=1.5.0", +# "torchvision>=0.6.0", +# "datasets>=2.14.0", +# "evaluate", +# "scikit-learn", +# ] +# /// + """Finetuning any 🤗 Transformers model for image classification leveraging 🤗 Accelerate.""" import argparse diff --git a/examples/pytorch/image-pretraining/run_mae.py b/examples/pytorch/image-pretraining/run_mae.py index 514a4314ad58..20ae2b531659 100644 --- a/examples/pytorch/image-pretraining/run_mae.py +++ b/examples/pytorch/image-pretraining/run_mae.py @@ -12,6 +12,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "torch>=1.5.0", +# "torchvision>=0.6.0", +# "datasets>=1.8.0", +# ] +# /// + import logging import os import sys diff --git a/examples/pytorch/image-pretraining/run_mim.py b/examples/pytorch/image-pretraining/run_mim.py index a45dc6b757e7..8d6b1ba6d5af 100644 --- a/examples/pytorch/image-pretraining/run_mim.py +++ b/examples/pytorch/image-pretraining/run_mim.py @@ -12,6 +12,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "torch>=1.5.0", +# "torchvision>=0.6.0", +# "datasets>=1.8.0", +# ] +# /// + import logging import os import sys diff --git a/examples/pytorch/image-pretraining/run_mim_no_trainer.py b/examples/pytorch/image-pretraining/run_mim_no_trainer.py index ff58130a0b9c..97b5e9577840 100644 --- a/examples/pytorch/image-pretraining/run_mim_no_trainer.py +++ b/examples/pytorch/image-pretraining/run_mim_no_trainer.py @@ -12,6 +12,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "torch>=1.5.0", +# "torchvision>=0.6.0", +# "datasets>=1.8.0", +# ] +# /// + import argparse import logging import math diff --git a/examples/pytorch/instance-segmentation/run_instance_segmentation.py b/examples/pytorch/instance-segmentation/run_instance_segmentation.py index 357a02082297..6c277e49caea 100644 --- a/examples/pytorch/instance-segmentation/run_instance_segmentation.py +++ b/examples/pytorch/instance-segmentation/run_instance_segmentation.py @@ -12,6 +12,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "timm", +# "datasets", +# "torchmetrics", +# "pycocotools", +# ] +# /// + """Finetuning 🤗 Transformers model for instance segmentation leveraging the Trainer API.""" import logging diff --git a/examples/pytorch/instance-segmentation/run_instance_segmentation_no_trainer.py b/examples/pytorch/instance-segmentation/run_instance_segmentation_no_trainer.py index 92a5a1537b91..38a712bf0c40 100644 --- a/examples/pytorch/instance-segmentation/run_instance_segmentation_no_trainer.py +++ b/examples/pytorch/instance-segmentation/run_instance_segmentation_no_trainer.py @@ -12,6 +12,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "timm", +# "datasets", +# "torchmetrics", +# "pycocotools", +# ] +# /// + """Finetuning 🤗 Transformers model for instance segmentation with Accelerate 🚀.""" import argparse diff --git a/examples/pytorch/language-modeling/run_clm.py b/examples/pytorch/language-modeling/run_clm.py index dbd0e6e0fa88..33f47ae868cf 100755 --- a/examples/pytorch/language-modeling/run_clm.py +++ b/examples/pytorch/language-modeling/run_clm.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "accelerate >= 0.12.0", +# "torch >= 1.3", +# "datasets >= 2.14.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "evaluate", +# "scikit-learn", +# ] +# /// + """ Fine-tuning the library models for causal language modeling (GPT, GPT-2, CTRL, ...) on a text file or a dataset. diff --git a/examples/pytorch/language-modeling/run_clm_no_trainer.py b/examples/pytorch/language-modeling/run_clm_no_trainer.py index 554174ab1bbf..f0ef6a6acb4d 100755 --- a/examples/pytorch/language-modeling/run_clm_no_trainer.py +++ b/examples/pytorch/language-modeling/run_clm_no_trainer.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "accelerate >= 0.12.0", +# "torch >= 1.3", +# "datasets >= 2.14.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "evaluate", +# "scikit-learn", +# ] +# /// + """ Fine-tuning the library models for causal language modeling (GPT, GPT-2, CTRL, ...) on a text file or a dataset without using HuggingFace Trainer. diff --git a/examples/pytorch/language-modeling/run_fim.py b/examples/pytorch/language-modeling/run_fim.py index b77922c15ae4..dd2b5ab6b88f 100644 --- a/examples/pytorch/language-modeling/run_fim.py +++ b/examples/pytorch/language-modeling/run_fim.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "accelerate >= 0.12.0", +# "torch >= 1.3", +# "datasets >= 2.14.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "evaluate", +# "scikit-learn", +# ] +# /// + """ Fine-tuning the library models for causal language modeling using Fill-in-the middle (FIM) objective on a text file or a dataset. diff --git a/examples/pytorch/language-modeling/run_fim_no_trainer.py b/examples/pytorch/language-modeling/run_fim_no_trainer.py index bb3ea1db2936..d63bbd04a7ec 100644 --- a/examples/pytorch/language-modeling/run_fim_no_trainer.py +++ b/examples/pytorch/language-modeling/run_fim_no_trainer.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "accelerate >= 0.12.0", +# "torch >= 1.3", +# "datasets >= 2.14.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "evaluate", +# "scikit-learn", +# ] +# /// + """ Fine-tuning the library models for causal language modeling using Fill-in-the middle (FIM) objective on a text file or a dataset without using HuggingFace Trainer. diff --git a/examples/pytorch/language-modeling/run_mlm.py b/examples/pytorch/language-modeling/run_mlm.py index 67a574f44dfa..57b2dbc7135b 100755 --- a/examples/pytorch/language-modeling/run_mlm.py +++ b/examples/pytorch/language-modeling/run_mlm.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "accelerate >= 0.12.0", +# "torch >= 1.3", +# "datasets >= 2.14.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "evaluate", +# "scikit-learn", +# ] +# /// + """ Fine-tuning the library models for masked language modeling (BERT, ALBERT, RoBERTa...) on a text file or a dataset. diff --git a/examples/pytorch/language-modeling/run_mlm_no_trainer.py b/examples/pytorch/language-modeling/run_mlm_no_trainer.py index 42384d9e1e20..5e64f27b6c2a 100755 --- a/examples/pytorch/language-modeling/run_mlm_no_trainer.py +++ b/examples/pytorch/language-modeling/run_mlm_no_trainer.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "accelerate >= 0.12.0", +# "torch >= 1.3", +# "datasets >= 2.14.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "evaluate", +# "scikit-learn", +# ] +# /// + """ Fine-tuning the library models for masked language modeling (BERT, ALBERT, RoBERTa...) on a text file or a dataset without using HuggingFace Trainer. diff --git a/examples/pytorch/language-modeling/run_plm.py b/examples/pytorch/language-modeling/run_plm.py index 1c35de8d030e..844350af1fbd 100755 --- a/examples/pytorch/language-modeling/run_plm.py +++ b/examples/pytorch/language-modeling/run_plm.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "accelerate >= 0.12.0", +# "torch >= 1.3", +# "datasets >= 2.14.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "evaluate", +# "scikit-learn", +# ] +# /// + """ Fine-tuning the library models for permutation language modeling. """ diff --git a/examples/pytorch/multiple-choice/run_swag.py b/examples/pytorch/multiple-choice/run_swag.py index 927d439335b6..b1487cdbe993 100755 --- a/examples/pytorch/multiple-choice/run_swag.py +++ b/examples/pytorch/multiple-choice/run_swag.py @@ -12,6 +12,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning the library models for multiple choice. """ diff --git a/examples/pytorch/multiple-choice/run_swag_no_trainer.py b/examples/pytorch/multiple-choice/run_swag_no_trainer.py index d0581c5b6c9c..fab10a263af7 100755 --- a/examples/pytorch/multiple-choice/run_swag_no_trainer.py +++ b/examples/pytorch/multiple-choice/run_swag_no_trainer.py @@ -12,6 +12,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning a 🤗 Transformers model on multiple choice relying on the accelerate library without using a Trainer. """ diff --git a/examples/pytorch/object-detection/run_object_detection.py b/examples/pytorch/object-detection/run_object_detection.py index f534d9a3236c..51f5d6ddca79 100644 --- a/examples/pytorch/object-detection/run_object_detection.py +++ b/examples/pytorch/object-detection/run_object_detection.py @@ -12,6 +12,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "timm", +# "datasets>=4.0", +# "torchmetrics", +# "pycocotools", +# ] +# /// + """Finetuning any 🤗 Transformers model supported by AutoModelForObjectDetection for object detection leveraging the Trainer API.""" import logging diff --git a/examples/pytorch/object-detection/run_object_detection_no_trainer.py b/examples/pytorch/object-detection/run_object_detection_no_trainer.py index 1133435d7be2..522b99dda159 100644 --- a/examples/pytorch/object-detection/run_object_detection_no_trainer.py +++ b/examples/pytorch/object-detection/run_object_detection_no_trainer.py @@ -11,6 +11,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "albumentations >= 1.4.16", +# "timm", +# "datasets>=4.0", +# "torchmetrics", +# "pycocotools", +# ] +# /// + """Finetuning 🤗 Transformers model for object detection with Accelerate.""" import argparse From b328f830635d19b57544138cd3c9a93dfdd95dda Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Thu, 24 Jul 2025 17:52:30 +0200 Subject: [PATCH 3/4] rest of pytorch examples --- .../audio-classification/requirements.txt | 1 + .../run_audio_classification.py | 8 +++++--- .../run_semantic_segmentation.py | 12 ++++++++++++ .../run_semantic_segmentation_no_trainer.py | 13 +++++++++++++ .../pytorch/speech-pretraining/requirements.txt | 2 +- .../run_wav2vec2_pretraining_no_trainer.py | 11 +++++++++++ .../pytorch/speech-recognition/requirements.txt | 2 +- .../run_speech_recognition_ctc.py | 12 ++++++++++++ .../run_speech_recognition_ctc_adapter.py | 12 ++++++++++++ .../run_speech_recognition_seq2seq.py | 13 +++++++++++++ .../pytorch/summarization/run_summarization.py | 16 ++++++++++++++++ .../run_summarization_no_trainer.py | 16 ++++++++++++++++ .../text-classification/run_classification.py | 15 +++++++++++++++ examples/pytorch/text-classification/run_glue.py | 15 +++++++++++++++ .../text-classification/run_glue_no_trainer.py | 15 +++++++++++++++ examples/pytorch/text-classification/run_xnli.py | 15 +++++++++++++++ .../pytorch/text-generation/run_generation.py | 11 +++++++++++ .../run_generation_contrastive_search.py | 11 +++++++++++ examples/pytorch/token-classification/run_ner.py | 12 ++++++++++++ .../token-classification/run_ner_no_trainer.py | 12 ++++++++++++ examples/pytorch/translation/run_translation.py | 15 +++++++++++++++ .../translation/run_translation_no_trainer.py | 15 +++++++++++++++ 22 files changed, 249 insertions(+), 5 deletions(-) diff --git a/examples/pytorch/audio-classification/requirements.txt b/examples/pytorch/audio-classification/requirements.txt index 1a2309342b4e..d23b9b86f190 100644 --- a/examples/pytorch/audio-classification/requirements.txt +++ b/examples/pytorch/audio-classification/requirements.txt @@ -1,4 +1,5 @@ datasets[audio]>=1.14.0 evaluate +librosa torchaudio torch>=1.6 diff --git a/examples/pytorch/audio-classification/run_audio_classification.py b/examples/pytorch/audio-classification/run_audio_classification.py index 0518fae2dc1e..bb5651ab25f7 100644 --- a/examples/pytorch/audio-classification/run_audio_classification.py +++ b/examples/pytorch/audio-classification/run_audio_classification.py @@ -16,9 +16,11 @@ # /// script # dependencies = [ # "transformers @ git+https://github.com/huggingface/transformers.git", -# "torch>=1.5.0", -# "torchvision>=0.6.0", -# "datasets>=1.8.0", +# "datasets[audio]>=1.14.0", +# "evaluate", +# "librosa", +# "torchaudio", +# "torch>=1.6", # ] # /// diff --git a/examples/pytorch/semantic-segmentation/run_semantic_segmentation.py b/examples/pytorch/semantic-segmentation/run_semantic_segmentation.py index 3e43383ca45c..cf38403ca886 100644 --- a/examples/pytorch/semantic-segmentation/run_semantic_segmentation.py +++ b/examples/pytorch/semantic-segmentation/run_semantic_segmentation.py @@ -12,6 +12,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "datasets >= 2.0.0", +# "torch >= 1.3", +# "accelerate", +# "evaluate"" +# "Pillow", +# "albumentations >= 1.4.16", +# ] +# /// + import json import logging import os diff --git a/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py b/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py index a35cc411aac4..bcf39c45d57c 100644 --- a/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py +++ b/examples/pytorch/semantic-segmentation/run_semantic_segmentation_no_trainer.py @@ -11,6 +11,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "datasets >= 2.0.0", +# "torch >= 1.3", +# "accelerate", +# "evaluate"" +# "Pillow", +# "albumentations >= 1.4.16", +# ] +# /// + """Finetuning any 🤗 Transformers model supported by AutoModelForSemanticSegmentation for semantic segmentation.""" import argparse diff --git a/examples/pytorch/speech-pretraining/requirements.txt b/examples/pytorch/speech-pretraining/requirements.txt index c270b3a565fa..57851d2a09d1 100644 --- a/examples/pytorch/speech-pretraining/requirements.txt +++ b/examples/pytorch/speech-pretraining/requirements.txt @@ -1,4 +1,4 @@ -datasets >= 1.12.0 +datasets[audio] >= 1.12.0 torch >= 1.5 torchaudio accelerate >= 0.12.0 diff --git a/examples/pytorch/speech-pretraining/run_wav2vec2_pretraining_no_trainer.py b/examples/pytorch/speech-pretraining/run_wav2vec2_pretraining_no_trainer.py index 111706412a39..f30fd1676a3a 100755 --- a/examples/pytorch/speech-pretraining/run_wav2vec2_pretraining_no_trainer.py +++ b/examples/pytorch/speech-pretraining/run_wav2vec2_pretraining_no_trainer.py @@ -12,6 +12,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "datasets[audio] >= 1.12.0", +# "torch >= 1.5", +# "torchaudio", +# "accelerate >= 0.12.0", +# "librosa", +# ] +# /// + """Pre-Training a 🤗 Wav2Vec2 model on unlabeled audio data""" import argparse diff --git a/examples/pytorch/speech-recognition/requirements.txt b/examples/pytorch/speech-recognition/requirements.txt index a16697b038c6..4137ea02ad76 100644 --- a/examples/pytorch/speech-recognition/requirements.txt +++ b/examples/pytorch/speech-recognition/requirements.txt @@ -1,4 +1,4 @@ -datasets >= 1.18.0 +datasets[audio] >= 1.18.0 torch >= 1.5 torchaudio librosa diff --git a/examples/pytorch/speech-recognition/run_speech_recognition_ctc.py b/examples/pytorch/speech-recognition/run_speech_recognition_ctc.py index 879f3320c1e9..e4cf9385618a 100755 --- a/examples/pytorch/speech-recognition/run_speech_recognition_ctc.py +++ b/examples/pytorch/speech-recognition/run_speech_recognition_ctc.py @@ -13,6 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "datasets[audio] >= 1.18.0", +# "torch >= 1.5", +# "torchaudio", +# "librosa", +# "jiwer", +# "evaluate", +# ] +# /// + """Fine-tuning a 🤗 Transformers CTC model for automatic speech recognition""" import functools diff --git a/examples/pytorch/speech-recognition/run_speech_recognition_ctc_adapter.py b/examples/pytorch/speech-recognition/run_speech_recognition_ctc_adapter.py index 8f3b61ea4309..c7b5df009ac9 100755 --- a/examples/pytorch/speech-recognition/run_speech_recognition_ctc_adapter.py +++ b/examples/pytorch/speech-recognition/run_speech_recognition_ctc_adapter.py @@ -13,6 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "datasets[audio] >= 1.18.0", +# "torch >= 1.5", +# "torchaudio", +# "librosa", +# "jiwer", +# "evaluate", +# ] +# /// + """Fine-tuning a 🤗 Transformers CTC adapter model for automatic speech recognition""" import functools diff --git a/examples/pytorch/speech-recognition/run_speech_recognition_seq2seq.py b/examples/pytorch/speech-recognition/run_speech_recognition_seq2seq.py index 76e832554889..d68f97d280ab 100755 --- a/examples/pytorch/speech-recognition/run_speech_recognition_seq2seq.py +++ b/examples/pytorch/speech-recognition/run_speech_recognition_seq2seq.py @@ -12,6 +12,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "datasets[audio] >= 1.18.0", +# "torch >= 1.5", +# "torchaudio", +# "librosa", +# "jiwer", +# "evaluate", +# ] +# /// + """ Fine-tuning the library models for sequence to sequence speech recognition. """ diff --git a/examples/pytorch/summarization/run_summarization.py b/examples/pytorch/summarization/run_summarization.py index d22d01479d62..bca7ef6dc8e8 100755 --- a/examples/pytorch/summarization/run_summarization.py +++ b/examples/pytorch/summarization/run_summarization.py @@ -12,6 +12,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "rouge-score", +# "nltk", +# "py7zr", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning the library models for sequence to sequence. """ diff --git a/examples/pytorch/summarization/run_summarization_no_trainer.py b/examples/pytorch/summarization/run_summarization_no_trainer.py index e769017eb10f..31b18308f61c 100644 --- a/examples/pytorch/summarization/run_summarization_no_trainer.py +++ b/examples/pytorch/summarization/run_summarization_no_trainer.py @@ -12,6 +12,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "rouge-score", +# "nltk", +# "py7zr", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning a 🤗 Transformers model on summarization. """ diff --git a/examples/pytorch/text-classification/run_classification.py b/examples/pytorch/text-classification/run_classification.py index 8de9e117cac2..9e5344d69a79 100755 --- a/examples/pytorch/text-classification/run_classification.py +++ b/examples/pytorch/text-classification/run_classification.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "scipy", +# "scikit-learn", +# "protobuf", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """Finetuning the library models for text classification.""" # You can also adapt this script on your own text classification task. Pointers for this are left as comments. diff --git a/examples/pytorch/text-classification/run_glue.py b/examples/pytorch/text-classification/run_glue.py index 76f4e30ce878..6072433b588f 100755 --- a/examples/pytorch/text-classification/run_glue.py +++ b/examples/pytorch/text-classification/run_glue.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "scipy", +# "scikit-learn", +# "protobuf", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """Finetuning the library models for sequence classification on GLUE.""" # You can also adapt this script on your own text classification task. Pointers for this are left as comments. diff --git a/examples/pytorch/text-classification/run_glue_no_trainer.py b/examples/pytorch/text-classification/run_glue_no_trainer.py index 5bab946d38e3..88ffc3034a23 100644 --- a/examples/pytorch/text-classification/run_glue_no_trainer.py +++ b/examples/pytorch/text-classification/run_glue_no_trainer.py @@ -11,6 +11,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "scipy", +# "scikit-learn", +# "protobuf", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """Finetuning a 🤗 Transformers model for sequence classification on GLUE.""" import argparse diff --git a/examples/pytorch/text-classification/run_xnli.py b/examples/pytorch/text-classification/run_xnli.py index f2f7088ac4d6..f62b0ee248b8 100755 --- a/examples/pytorch/text-classification/run_xnli.py +++ b/examples/pytorch/text-classification/run_xnli.py @@ -13,6 +13,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "scipy", +# "scikit-learn", +# "protobuf", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """Finetuning multi-lingual models on XNLI (e.g. Bert, DistilBERT, XLM). Adapted from `examples/text-classification/run_glue.py`""" diff --git a/examples/pytorch/text-generation/run_generation.py b/examples/pytorch/text-generation/run_generation.py index 4b50fbd07f63..cea4c881ea62 100755 --- a/examples/pytorch/text-generation/run_generation.py +++ b/examples/pytorch/text-generation/run_generation.py @@ -13,6 +13,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.21.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "torch >= 1.3", +# ] +# /// + """Conditional text generation with the auto-regressive models of the library (GPT/GPT-2/CTRL/Transformer-XL/XLNet)""" import argparse diff --git a/examples/pytorch/text-generation/run_generation_contrastive_search.py b/examples/pytorch/text-generation/run_generation_contrastive_search.py index 5610dfb7f5de..879229c062e3 100755 --- a/examples/pytorch/text-generation/run_generation_contrastive_search.py +++ b/examples/pytorch/text-generation/run_generation_contrastive_search.py @@ -12,6 +12,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.21.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "torch >= 1.3", +# ] +# /// + """The examples of running contrastive search on the auto-APIs; Running this example: diff --git a/examples/pytorch/token-classification/run_ner.py b/examples/pytorch/token-classification/run_ner.py index ce89fcef5d38..751595c17dcb 100755 --- a/examples/pytorch/token-classification/run_ner.py +++ b/examples/pytorch/token-classification/run_ner.py @@ -12,6 +12,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "seqeval", +# "datasets >= 1.8.0", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning the library models for token classification. """ diff --git a/examples/pytorch/token-classification/run_ner_no_trainer.py b/examples/pytorch/token-classification/run_ner_no_trainer.py index b2eb75c28766..8155ab58d26c 100755 --- a/examples/pytorch/token-classification/run_ner_no_trainer.py +++ b/examples/pytorch/token-classification/run_ner_no_trainer.py @@ -12,6 +12,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "seqeval", +# "datasets >= 1.8.0", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning a 🤗 Transformers model on token classification tasks (NER, POS, CHUNKS) relying on the accelerate library without using a Trainer. diff --git a/examples/pytorch/translation/run_translation.py b/examples/pytorch/translation/run_translation.py index eba71deb64d0..671cda334049 100755 --- a/examples/pytorch/translation/run_translation.py +++ b/examples/pytorch/translation/run_translation.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "sacrebleu >= 1.4.12", +# "py7zr", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning the library models for sequence to sequence. """ diff --git a/examples/pytorch/translation/run_translation_no_trainer.py b/examples/pytorch/translation/run_translation_no_trainer.py index 64fed716ffad..2788624e173a 100644 --- a/examples/pytorch/translation/run_translation_no_trainer.py +++ b/examples/pytorch/translation/run_translation_no_trainer.py @@ -12,6 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +# /// script +# dependencies = [ +# "transformers @ git+https://github.com/huggingface/transformers.git", +# "accelerate >= 0.12.0", +# "datasets >= 1.8.0", +# "sentencepiece != 0.1.92", +# "protobuf", +# "sacrebleu >= 1.4.12", +# "py7zr", +# "torch >= 1.3", +# "evaluate", +# ] +# /// + """ Fine-tuning a 🤗 Transformers model on text translation. """ From 238b55adb04f22329336261a75979a4273f4cdb8 Mon Sep 17 00:00:00 2001 From: Quentin Lhoest Date: Thu, 24 Jul 2025 17:52:43 +0200 Subject: [PATCH 4/4] style --- utils/release.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/release.py b/utils/release.py index 96e37246ab38..d8fee77733e7 100644 --- a/utils/release.py +++ b/utils/release.py @@ -59,8 +59,14 @@ "examples": (re.compile(r'^check_min_version\("[^"]+"\)\s*$', re.MULTILINE), 'check_min_version("VERSION")\n'), "init": (re.compile(r'^__version__\s+=\s+"([^"]+)"\s*$', re.MULTILINE), '__version__ = "VERSION"\n'), "setup": (re.compile(r'^(\s*)version\s*=\s*"[^"]+",', re.MULTILINE), r'\1version="VERSION",'), - "uv_script_release": (re.compile(r'^# "transformers(\[.+\])?.*$', re.MULTILINE), r'# "transformers\g<1>==VERSION",'), - "uv_script_dev": (re.compile(r'^# "transformers(\[.+\])?.*$', re.MULTILINE), r'# "transformers\g<1> @ git+https://github.com/huggingface/transformers.git",'), + "uv_script_release": ( + re.compile(r'^# "transformers(\[.+\])?.*$', re.MULTILINE), + r'# "transformers\g<1>==VERSION",', + ), + "uv_script_dev": ( + re.compile(r'^# "transformers(\[.+\])?.*$', re.MULTILINE), + r'# "transformers\g<1> @ git+https://github.com/huggingface/transformers.git",', + ), } # This maps a type of file to its path in Transformers REPLACE_FILES = {