Update transformers skill metadata and dependencies; remove uv.lock file

This commit is contained in:
Timothy Kassis committed 2026-06-13 07:30:28 -07:00
1 parent 9c12fcc25e
commit 2b4cce7d87
6 files changed
+50 -2212

No files matched your search

+3 -1
View File
@@ -16,4 +16,6 @@ research/
.agents/
AGENTS.md
skills-lock.json
skills-lock.json
uv.lock
+14 -7
View File
@@ -1,9 +1,12 @@
---
name: transformers
description: Hugging Face Transformers for loading Hub models, running pipeline inference, text generation, and Trainer fine-tuning on NLP, vision, audio, and multimodal tasks. Use when working with AutoModel, pipelines, tokenizers, or TrainingArguments—not for general ML outside the Transformers library.
allowed-tools: Read Write Edit Bash
license: Apache-2.0 license
compatibility: Requires Python 3.10+, PyTorch 2.4+, and transformers 5.x. Gated or private Hub models need an HF token (hf auth login or HF_TOKEN).
metadata: {"version": "1.1", "skill-author": "K-Dense Inc."}
compatibility: Requires Python 3.10+, PyTorch 2.4+, and transformers 5.x. Gated or private Hub models need an HF token (`hf auth login` or `HF_TOKEN`).
metadata:
version: "1.2"
skill-author: "K-Dense Inc."
---
# Transformers
@@ -14,24 +17,26 @@ The Hugging Face Transformers library provides access to thousands of pre-traine
## Installation
Tested against **transformers 5.9.x** (stable; May 2026). Requires **Python 3.10+** and **PyTorch 2.4+**.
Tested against **transformers 5.12.0** (current PyPI release; June 2026). Requires **Python 3.10+**; the `torch` extra currently requires **PyTorch 2.4+**.
```bash
uv pip install "transformers[torch]>=5.9" huggingface_hub datasets evaluate accelerate
uv pip install "transformers[torch]==5.12.0" huggingface_hub==1.19.0 datasets==5.0.0 evaluate==0.4.6 accelerate==1.14.0
```
For vision tasks, add:
```bash
uv pip install timm pillow
uv pip install timm==1.0.27 pillow==12.2.0
```
For audio tasks, add:
```bash
uv pip install librosa soundfile
uv pip install librosa==0.11.0 soundfile==0.14.0
```
These pins are for reproducible examples. For exploratory work, loosen them only after checking the Transformers and Hub release notes for API changes.
Check your version:
```python
@@ -66,13 +71,15 @@ Get tokens at: https://huggingface.co/settings/tokens
**Security:** Never paste tokens into notebooks, repos, or shared configs. Prefer `hf auth login` over exporting tokens in `.bashrc` or `.zshrc`.
Use the narrowest token scope that works: `read` for private or gated model downloads, `write` only for uploads. If a long-running environment should not send the stored token on every Hub request, set `HF_HUB_DISABLE_IMPLICIT_TOKEN=1` and pass a token only where authentication is required.
## Transformers v5
Transformers v5 is **PyTorch-only** (TensorFlow and JAX backends were removed). For upgrades from v4, see the [v5 migration guide](https://github.com/huggingface/transformers/blob/main/MIGRATION_GUIDE_V5.md). New projects should pair **transformers 5.x** with **huggingface_hub 1.x**.
**Gated or custom architectures:** accept the model license on the Hub, then load with `trust_remote_code=True` only when the model card requires custom code you have reviewed.
**Cache location:** set `HF_HOME` for a writable cache root (Hub files default under `$HF_HOME/hub`).
**Cache location:** set `HF_HOME` for all Hugging Face caches, or `HF_HUB_CACHE` just for Hub files. Use `HF_HUB_OFFLINE=1` only after required model snapshots are already cached.
## Quick Start
+8 -4
View File
@@ -303,11 +303,15 @@ messages = [
{"role": "user", "content": "What is the capital of France?"}
]
input_text = tokenizer.apply_chat_template(messages, tokenize=False)
inputs = tokenizer(input_text, return_tensors="pt")
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=100)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
outputs = model.generate(inputs, max_new_tokens=100)
response = tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True)
```
### Encoder-Decoder Models
+16 -6
View File
@@ -150,22 +150,28 @@ model = AutoModelForCausalLM.from_pretrained(
)
```
**load_in_8bit**: 8-bit quantization (requires optional `bitsandbytes`; `uv pip install bitsandbytes`)
**BitsAndBytesConfig**: 8-bit and 4-bit quantization (requires optional `bitsandbytes`; `uv pip install bitsandbytes==0.49.2`)
```python
from transformers import BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
model = AutoModelForCausalLM.from_pretrained(
"model-id",
load_in_8bit=True,
device_map="auto"
device_map="auto",
quantization_config=quantization_config
)
```
**load_in_4bit**: 4-bit quantization
**4-bit QLoRA-style loading**: use `BitsAndBytesConfig` instead of direct `load_in_4bit` arguments
```python
import torch
from transformers import BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4"
)
model = AutoModelForCausalLM.from_pretrained(
@@ -336,11 +342,15 @@ export(
**CUDA out of memory:**
```python
import torch
from transformers import BitsAndBytesConfig
# Use smaller precision
model = AutoModel.from_pretrained("model-id", dtype=torch.float16)
# Or use quantization
model = AutoModel.from_pretrained("model-id", load_in_8bit=True)
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
model = AutoModel.from_pretrained("model-id", quantization_config=quantization_config)
# Or use CPU
model = AutoModel.from_pretrained("model-id", device_map="cpu")
+9 -4
View File
@@ -323,12 +323,17 @@ messages = [
{"role": "user", "content": "How are you?"}
]
# Apply chat template
text = tokenizer.apply_chat_template(messages, tokenize=False)
# Format for display or preprocessing
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
print(text)
# Tokenize directly
inputs = tokenizer.apply_chat_template(messages, tokenize=True, return_tensors="pt")
# Tokenize directly for generation
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt"
)
```
## Common Patterns
Generated
-2190
View File
File diff suppressed because it is too large. Load diff