-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hugging face trainer callback integration (#33)
Co-authored-by: Jae-Won Chung <jwnchung@umich.edu>
- Loading branch information
1 parent
8bcf4f7
commit 5c41ab4
Showing
8 changed files
with
947 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ dist/ | |
*.json | ||
**/.DS_Store | ||
.cache/ | ||
env/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Integrating Zeus with HuggingFace π€ | ||
|
||
This example will demonstrate how to integrate Zeus with `HuggingFace π€ Trainer` using `HFGlobalPowerLimitOptimizer`. | ||
|
||
[`run_clm.py`](run_clm.py) was adapted from [HuggingFace π€'s example training code for fine-tuning language models](https://github.com/huggingface/transformers/tree/f3aa7db439a2a3942f76c115197fe953984ac334/examples/pytorch/language-modeling). | ||
|
||
## Dependencies | ||
|
||
Use the included requirements.txt file to include all extra dependencies: | ||
```sh | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## `ZeusMonitor` and `HFGlobalPowerLimitOptimizer` | ||
|
||
- [`ZeusMonitor`](http://ml.energy/zeus/reference/monitor/#zeus.monitor.ZeusMonitor): Measures the GPU time and energy consumption of arbitrary code blocks. | ||
- [`HFGlobalPowerLimitOptimizer`](https://ml.energy/zeus/reference/optimizer/power_limit/#zeus.optimizer.power_limit.HFGlobalPowerLimitOptimizer): Online-profiles each power limit with `ZeusMonitor` and finds the cost-optimal power limit. Calls GlobalPowerLimitOptimizer under the hood. | ||
|
||
## Integration with HuggingFace π€ Trainer | ||
For easy use with [HuggingFace π€ Transformers](https://huggingface.co/docs/transformers/en/index), [`HFGlobalPowerLimitOptimizer`](https://ml.energy/zeus/reference/optimizer/power_limit/#zeus.optimizer.power_limit.HFGlobalPowerLimitOptimizer) is a drop-in compatible [HuggingFace π€ Trainer Callback](https://huggingface.co/docs/transformers/en/main_classes/callback). When initializing a [HuggingFace π€ Trainer](https://huggingface.co/docs/transformers/main_classes/trainer), initialize and pass in [`HFGlobalPowerLimitOptimizer`](https://ml.energy/zeus/reference/optimizer/power_limit/#zeus.optimizer.power_limit.HFGlobalPowerLimitOptimizer) as shown below: | ||
|
||
```python | ||
monitor = ZeusMonitor() | ||
optimizer = HFGlobalPowerLimitOptimizer(monitor) | ||
|
||
# Initialize HuggingFace π€ Trainer | ||
trainer = Trainer( | ||
..., | ||
callbacks=[optimizer], # Add the `HFGlobalPowerLimitOptimizer` callback | ||
) | ||
``` | ||
|
||
## Running the Example | ||
|
||
By default, `Trainer` will make use of all available GPUs. If you would like to use only a subset of the GPUs, specify the `CUDA_VISIBLE_DEVICES` environment variable, which Zeus will also automatically respect. | ||
|
||
```bash | ||
python run_clm.py \ | ||
--model_name_or_path gpt2 \ | ||
--dataset_name wikitext \ | ||
--dataset_config_name wikitext-2-raw-v1 \ | ||
--per_device_train_batch_size 8 \ | ||
--per_device_eval_batch_size 8 \ | ||
--do_train \ | ||
--do_eval \ | ||
--output_dir /tmp/test-clm | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
accelerate >= 0.12.0 | ||
torch >= 1.3 | ||
datasets >= 1.8.0 | ||
sentencepiece != 0.1.92 | ||
protobuf | ||
evaluate | ||
scikit-learn | ||
transformers>=4.37.2 |
Oops, something went wrong.