Skip to content

Commit 989f5f5

Browse files
authored
adds wandb loging of metrics (#676)
1 parent 69931df commit 989f5f5

File tree

7 files changed

+75
-0
lines changed

7 files changed

+75
-0
lines changed

docs/source/saving-and-reading-results.mdx

+14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ This will create a Tensorboard dashboard in a HF org set with the `--results-org
3131
option.
3232

3333

34+
## Pushing results to WandB
35+
36+
You can push the results to WandB by setting `--wandb`. This will init a WandB
37+
run and log the results.
38+
39+
Wandb args need to be set in your env variables.
40+
41+
```
42+
export WANDB_PROJECT="lighteval"
43+
```
44+
45+
You can find a list of variable in the [wandb documentation](https://docs.wandb.ai/guides/track/environment-variables/).
46+
47+
3448
## How to load and investigate details
3549

3650
### Load from local detail files

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ multilingual = [
110110
"pyvi", # for vietnamese tokenizer
111111
]
112112
math = ["latex2sympy2_extended==1.0.6"]
113+
wandb = ["wandb"]
113114

114115
[project.urls]
115116
Homepage = "https://github.com/huggingface/lighteval"

src/lighteval/logging/evaluation_tracker.py

+28
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def __init__(
126126
tensorboard_metric_prefix: str = "eval",
127127
public: bool = False,
128128
nanotron_run_info: "GeneralArgs" = None,
129+
wandb: bool = False,
129130
) -> None:
130131
"""Creates all the necessary loggers for evaluation tracking."""
131132
self.details_logger = DetailsLogger()
@@ -145,6 +146,7 @@ def __init__(
145146

146147
self.should_push_to_hub = push_to_hub
147148
self.should_save_details = save_details
149+
self.wandb = wandb
148150

149151
self.should_push_results_to_tensorboard = push_to_tensorboard
150152
self.tensorboard_repo = f"{hub_results_org}/tensorboard_logs"
@@ -153,6 +155,20 @@ def __init__(
153155

154156
self.public = public
155157

158+
if wandb is True:
159+
import wandb
160+
161+
self.wandb_project = os.environ.get("WANDB_PROJECT", None)
162+
163+
if self.wandb_project is None:
164+
raise ValueError("You need to specify the project name in wandb_args")
165+
166+
wandb.login()
167+
self.wandb_run = wandb.init(
168+
project=self.wandb_project,
169+
resume="allow",
170+
)
171+
156172
@property
157173
def results(self):
158174
config_general = asdict(self.general_config_logger)
@@ -222,11 +238,23 @@ def save(self) -> None:
222238
results_dict=results_dict,
223239
)
224240

241+
if self.wandb is True:
242+
self.push_to_wandb(
243+
results_dict=results_dict,
244+
details_datasets=details_datasets,
245+
)
246+
225247
if self.should_push_results_to_tensorboard:
226248
self.push_to_tensorboard(
227249
results=self.metrics_logger.metric_aggregated, details=self.details_logger.compiled_details
228250
)
229251

252+
def push_to_wandb(self, results_dict: dict, details_datasets: dict) -> None:
253+
self.wandb_run.log(
254+
{**results_dict["results"]},
255+
)
256+
self.wandb_run.finish()
257+
230258
def save_results(self, date_id: str, results_dict: dict):
231259
output_dir_results = Path(self.output_dir) / "results" / self.general_config_logger.model_name
232260
self.fs.mkdirs(output_dir_results, exist_ok=True)

src/lighteval/main_accelerate.py

+8
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ def accelerate( # noqa C901
8585
save_details: Annotated[
8686
bool, Option(help="Save detailed, sample per sample, results.", rich_help_panel=HELP_PANEL_NAME_2)
8787
] = False,
88+
wandb: Annotated[
89+
bool,
90+
Option(
91+
help="Push results to wandb. This will only work if you have wandb installed and logged in. We use env variable to configure wandb. see here: https://docs.wandb.ai/guides/track/environment-variables/",
92+
rich_help_panel=HELP_PANEL_NAME_2,
93+
),
94+
] = False,
8895
# === debug ===
8996
max_samples: Annotated[
9097
Optional[int], Option(help="Maximum number of samples to evaluate on.", rich_help_panel=HELP_PANEL_NAME_3)
@@ -112,6 +119,7 @@ def accelerate( # noqa C901
112119
push_to_tensorboard=push_to_tensorboard,
113120
public=public_run,
114121
hub_results_org=results_org,
122+
wandb=wandb,
115123
)
116124
pipeline_params = PipelineParameters(
117125
launcher_type=ParallelismManager.ACCELERATE,

src/lighteval/main_endpoint.py

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ def inference_endpoint(
8787
save_details: Annotated[
8888
bool, Option(help="Save detailed, sample per sample, results.", rich_help_panel=HELP_PANEL_NAME_2)
8989
] = False,
90+
wandb: Annotated[
91+
bool,
92+
Option(
93+
help="Push results to wandb. This will only work if you have wandb installed and logged in. We use env variable to configure wandb. see here: https://docs.wandb.ai/guides/track/environment-variables/",
94+
rich_help_panel=HELP_PANEL_NAME_2,
95+
),
96+
] = False,
9097
# === debug ===
9198
max_samples: Annotated[
9299
Optional[int], Option(help="Maximum number of samples to evaluate on.", rich_help_panel=HELP_PANEL_NAME_3)
@@ -109,6 +116,7 @@ def inference_endpoint(
109116
push_to_tensorboard=push_to_tensorboard,
110117
public=public_run,
111118
hub_results_org=results_org,
119+
wandb=wandb,
112120
)
113121

114122
parallelism_manager = ParallelismManager.NONE # since we're using inference endpoints in remote

src/lighteval/main_sglang.py

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def sglang(
7878
save_details: Annotated[
7979
bool, Option(help="Save detailed, sample per sample, results.", rich_help_panel=HELP_PANEL_NAME_2)
8080
] = False,
81+
wandb: Annotated[
82+
bool,
83+
Option(
84+
help="Push results to wandb. This will only work if you have wandb installed and logged in. We use env variable to configure wandb. see here: https://docs.wandb.ai/guides/track/environment-variables/",
85+
rich_help_panel=HELP_PANEL_NAME_2,
86+
),
87+
] = False,
8188
# === debug ===
8289
max_samples: Annotated[
8390
Optional[int], Option(help="Maximum number of samples to evaluate on.", rich_help_panel=HELP_PANEL_NAME_3)
@@ -102,6 +109,7 @@ def sglang(
102109
push_to_tensorboard=push_to_tensorboard,
103110
public=public_run,
104111
hub_results_org=results_org,
112+
wandb=wandb,
105113
)
106114

107115
pipeline_params = PipelineParameters(

src/lighteval/main_vllm.py

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def vllm(
8181
save_details: Annotated[
8282
bool, Option(help="Save detailed, sample per sample, results.", rich_help_panel=HELP_PANEL_NAME_2)
8383
] = False,
84+
wandb: Annotated[
85+
bool,
86+
Option(
87+
help="Push results to wandb. This will only work if you have wandb installed and logged in. We use env variable to configure wandb. see here: https://docs.wandb.ai/guides/track/environment-variables/",
88+
rich_help_panel=HELP_PANEL_NAME_2,
89+
),
90+
] = False,
8491
# === debug ===
8592
max_samples: Annotated[
8693
Optional[int], Option(help="Maximum number of samples to evaluate on.", rich_help_panel=HELP_PANEL_NAME_3)
@@ -105,6 +112,7 @@ def vllm(
105112
push_to_tensorboard=push_to_tensorboard,
106113
public=public_run,
107114
hub_results_org=results_org,
115+
wandb=wandb,
108116
)
109117

110118
pipeline_params = PipelineParameters(

0 commit comments

Comments
 (0)