Make pytorch examples UV-compatible (#39635)

* update release.py

* add uv headers in some pytorch examples

* rest of pytorch examples

* style
This commit is contained in:
Quentin Lhoest
2025-07-25 10:46:22 +02:00
committed by GitHub
parent c46c17db57
commit 91f591f7bc
42 changed files with 511 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
datasets>=1.14.0
datasets[audio]>=1.14.0
evaluate
librosa
torchaudio
torch>=1.6
torch>=1.6

View File

@@ -13,6 +13,17 @@
# 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.14.0",
# "evaluate",
# "librosa",
# "torchaudio",
# "torch>=1.6",
# ]
# ///
import logging
import os
import sys

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.
"""

View File

@@ -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.
"""

View File

@@ -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.
"""

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
datasets >= 1.12.0
datasets[audio] >= 1.12.0
torch >= 1.5
torchaudio
accelerate >= 0.12.0

View File

@@ -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

View File

@@ -1,4 +1,4 @@
datasets >= 1.18.0
datasets[audio] >= 1.18.0
torch >= 1.5
torchaudio
librosa

View File

@@ -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

View File

@@ -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

View File

@@ -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.
"""

View File

@@ -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.
"""

View File

@@ -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.
"""

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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`"""

View File

@@ -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

View File

@@ -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:

View File

@@ -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.
"""

View File

@@ -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.

View File

@@ -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.
"""

View File

@@ -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.
"""