Skip to content

Commit

Permalink
fixed some style, removed broken links in example/huggingface/README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
parthraut committed Feb 16, 2024
1 parent f2a0f91 commit 01db75e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 28 deletions.
3 changes: 2 additions & 1 deletion examples/huggingface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Use the included requirements.txt file to include all extra dependencies:
- [`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`](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`](zeus.optimizer.power_limit.HFGlobalPowerLimitOptimizer) as shown below:
For easy use with [HuggingFace 🤗 Transformers](https://huggingface.co/docs/transformers/en/index), `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` as shown below:

```python
monitor = ZeusMonitor()
Expand All @@ -44,3 +44,4 @@ python run_clm.py \
--do_train \
--do_eval \
--output_dir /tmp/test-clm
```
26 changes: 2 additions & 24 deletions examples/huggingface/run_clm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import evaluate
import torch
from datasets import load_dataset

import transformers
from transformers import (
CONFIG_MAPPING,
Expand Down Expand Up @@ -290,20 +289,6 @@ def __post_init__(self):
], "`validation_file` should be a csv, a json or a txt file."


@dataclass
class ZeusTrainingArguments:
"""
Arguments pertaining to the zeus training.
"""

gpu_indices: Optional[str] = field(
default=None,
metadata={
"help": 'The indices of the gpus to use for training (ex. "0,1,2"). If none, all gpus will be used.'
},
)


def main():
# See all possible arguments in src/transformers/training_args.py
# or by passing the --help flag to this script.
Expand All @@ -314,21 +299,19 @@ def main():
ModelArguments,
DataTrainingArguments,
TrainingArguments,
ZeusTrainingArguments,
)
)
if len(sys.argv) == 2 and sys.argv[1].endswith(".json"):
# If we pass only one argument to the script and it's the path to a json file,
# let's parse it to get our arguments.
model_args, data_args, training_args, zeus_args = parser.parse_json_file(
model_args, data_args, training_args = parser.parse_json_file(
json_file=os.path.abspath(sys.argv[1])
)
else:
(
model_args,
data_args,
training_args,
zeus_args,
) = parser.parse_args_into_dataclasses()

if model_args.use_auth_token is not None:
Expand Down Expand Up @@ -689,13 +672,8 @@ def compute_metrics(eval_preds):
preds = preds[:, :-1].reshape(-1)
return metric.compute(predictions=preds, references=labels)

# See if gpu_indices is set, and pass it to the monitor
gpu_indices = None
if zeus_args.gpu_indices is not None:
gpu_indices = [int(i) for i in zeus_args.gpu_indices.split(",")]

# Initialize our ZeusMonitor and HFGlobalPowerLimitOptimizer
monitor = ZeusMonitor(gpu_indices=gpu_indices)
monitor = ZeusMonitor()
optimizer = HFGlobalPowerLimitOptimizer(monitor)

# Initialize our Trainer
Expand Down
5 changes: 2 additions & 3 deletions tests/optimizer/test_power_limit_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import annotations

import inspect
import os
import typing
from typing import Generator, Iterable
Expand All @@ -38,8 +39,6 @@
from pathlib import Path
from pytest_mock import MockerFixture

import inspect


PROFILE_DATA_DIR = "tests/profile_data/"

Expand Down Expand Up @@ -279,4 +278,4 @@ def test_HFGPLO_signature_equivalence() -> None:
gplo_signature = inspect.signature(GlobalPowerLimitOptimizer.__init__)
hfgplo_signature = inspect.signature(HFGlobalPowerLimitOptimizer.__init__)

assert gplo_signature == hfgplo_signature, "GlobalPowerLimitOptimizer and HFGlobalPowerLimitOptimizer signatures do not match."
assert gplo_signature == hfgplo_signature, "GlobalPowerLimitOptimizer and HFGlobalPowerLimitOptimizer signatures do not match."

0 comments on commit 01db75e

Please sign in to comment.