almog2441 commited on
Commit
576f115
Β·
verified Β·
1 Parent(s): 3ece03f

Update Transformers/readme.md

Browse files
Files changed (1) hide show
  1. README.md +180 -3
README.md CHANGED
@@ -1,3 +1,180 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ ![image.png](https://cdn-uploads.huggingface.co/production/uploads/68205a944ab07873c714ab38/JaZj4EZaOlQyoUlkhXO9o.png)
5
+ ⚑ Hugging Face Accelerate – Effortless Multi-GPU & Distributed Training
6
+ ---
7
+ Welcome to **πŸ€— Accelerate**, your lightweight, zero-boilerplate training tool for **PyTorch** and **Transformers**. Whether you're working on a single laptop, multi-GPU setup, or a large-scale cloud cluster, Accelerate abstracts away the complexity of hardware and distributed systems β€” so you can focus on building great models.
8
+
9
+ ---
10
+
11
+ ## ✨ Why Use Accelerate?
12
+
13
+ - **Single-to-Multi GPU/TPU** in *one line*.
14
+ - **No code refactor** – use the same script everywhere.
15
+ - **Launch-ready**: Easily scale training jobs from dev to prod.
16
+ - **Supports DeepSpeed, FSDP, TPU, Multi-node**.
17
+ - **Compatible with πŸ€— Transformers, Datasets, PEFT**, and more.
18
+ - **Built-in CLI** for quick configuration and debugging.
19
+
20
+ > Accelerate is perfect for DevOps, MLOps, and Full Stack AI teams looking to scale training workloads without managing deep infrastructure internals.
21
+
22
+ ---
23
+
24
+ ## βš™οΈ Installation
25
+
26
+ ```bash
27
+ pip install accelerate
28
+ ```
29
+
30
+ Optional: For DeepSpeed, TPU, FSDP, and other accelerators:
31
+
32
+ ```bash
33
+ pip install "accelerate[deepspeed]"
34
+ pip install "accelerate[torch_xla]"
35
+ pip install "accelerate[fsdp]"
36
+ ```
37
+
38
+ ---
39
+
40
+ ## πŸš€ Quick Start
41
+
42
+ ### Step 1: Configure
43
+
44
+ ```bash
45
+ accelerate config
46
+ ```
47
+
48
+ You'll be guided through an interactive setup (or use `accelerate config default` to auto-generate).
49
+
50
+ ### Step 2: Launch your script
51
+
52
+ ```bash
53
+ accelerate launch train.py
54
+ ```
55
+
56
+ Accelerate automatically applies device mapping, DDP/FSDP strategy, gradient accumulation, and more β€” based on your config.
57
+
58
+ ---
59
+
60
+ ## πŸ§ͺ Example: Training a Transformer at Scale
61
+
62
+ **train.py**
63
+
64
+ ```python
65
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
66
+ from datasets import load_dataset
67
+ from accelerate import Accelerator
68
+
69
+ accelerator = Accelerator()
70
+ dataset = load_dataset("imdb")
71
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
72
+
73
+ def tokenize(batch):
74
+ return tokenizer(batch["text"], padding=True, truncation=True)
75
+
76
+ tokenized = dataset.map(tokenize, batched=True)
77
+ model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")
78
+
79
+ training_args = TrainingArguments(
80
+ output_dir="output",
81
+ per_device_train_batch_size=8,
82
+ evaluation_strategy="epoch",
83
+ num_train_epochs=1,
84
+ )
85
+
86
+ trainer = Trainer(
87
+ model=model,
88
+ args=training_args,
89
+ train_dataset=tokenized["train"].shuffle(seed=42).select(range(2000)),
90
+ eval_dataset=tokenized["test"].select(range(500)),
91
+ )
92
+
93
+ trainer.train()
94
+ ```
95
+
96
+ Then just run:
97
+
98
+ ```bash
99
+ accelerate launch train.py
100
+ ```
101
+
102
+ ---
103
+
104
+ ## βš™οΈ Advanced Use Cases
105
+
106
+ Accelerate supports:
107
+
108
+ - **DeepSpeed**: ZeRO offloading, memory savings
109
+ - **FSDP**: Fine-grained model sharding
110
+ - **TPUs**: Train on TPU cores seamlessly
111
+ - **Multi-node/multi-GPU**: via SLURM or CLI
112
+
113
+ Configure all options interactively or manually edit the `~/.cache/huggingface/accelerate/default_config.yaml`.
114
+
115
+ ---
116
+
117
+ ## 🧰 API Highlights
118
+
119
+ - `Accelerator()`: Auto-handles devices, mixed precision, gradient clipping, logging.
120
+ - `.prepare()`: Wraps model, dataloader, optimizer for distributed training.
121
+ - `.print()`: Replace all `print()` calls for synchronized logging.
122
+ - `.wait_for_everyone()`: Barrier sync in multi-process setups.
123
+
124
+ Example:
125
+
126
+ ```python
127
+ accelerator = Accelerator()
128
+ model, optimizer, dataloader = accelerator.prepare(model, optimizer, dataloader)
129
+ ```
130
+
131
+ ---
132
+
133
+ ## 🧠 DevOps / MLOps Friendly
134
+
135
+ - **CI/CD ready**: Use CLI and scripting without touching training code.
136
+ - **Built-in logging**: Compatible with πŸ€— Hub, WandB, TensorBoard.
137
+ - **Cloud scaling**: Easily used with SageMaker, Vertex AI, GCP, Azure.
138
+ - **Kubernetes compatible**: Launch jobs with config-driven strategy.
139
+
140
+ ---
141
+
142
+ ## 🧩 Integrates With
143
+
144
+ - πŸ€— Transformers
145
+ - πŸ€— Datasets
146
+ - πŸ€— PEFT (for LoRA / adapters)
147
+ - πŸ€— Diffusers
148
+ - DeepSpeed / FSDP / Torch XLA
149
+ - PyTorch Lightning (via wrapper)
150
+
151
+ ---
152
+
153
+ ## πŸ“š Learn More
154
+
155
+ - **Docs**: [https://huggingface.co/docs/accelerate](https://huggingface.co/docs/accelerate)
156
+ - **Course**: [Chapter 8 – Distributed Training](https://huggingface.co/course/chapter8)
157
+ - **Blog**: [How to Train BERT with Accelerate](https://huggingface.co/blog)
158
+
159
+ ---
160
+
161
+ ## 🀝 Contribute
162
+
163
+ ```bash
164
+ git clone https://github.com/huggingface/accelerate
165
+ cd accelerate
166
+ pip install -e ".[dev]"
167
+ ```
168
+
169
+ Check issues, help improve features, or share examples for TPU/FSx setups!
170
+
171
+
172
+ ## License
173
+
174
+ Accelerate is released under the Apache 2.0 License.
175
+
176
+ > *Accelerate bridges the gap between single-device experimentation and full-scale model training β€” with zero boilerplate and maximum flexibility.*
177
+
178
+ ---
179
+
180
+ Made with love by [Hugging Face](https://huggingface.co) and the open-source community.