Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3269db8

Browse files
authored
feat(wandb): sanitize name (openai#77)
* feat(wandb): sanitize name * feat(wandb): ensure results are present
1 parent 02e4008 commit 3269db8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

openai/wandb_logger.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import datetime
1111
import io
1212
import json
13+
import re
1314
from pathlib import Path
1415

1516
import numpy as np
@@ -108,6 +109,15 @@ def _log_fine_tune(
108109
)
109110
return
110111

112+
# check results are present
113+
try:
114+
results_id = fine_tune["result_files"][0]["id"]
115+
results = File.download(id=results_id).decode("utf-8")
116+
except:
117+
if show_individual_warnings:
118+
print(f"Fine-tune {fine_tune_id} has no results and will not be logged")
119+
return
120+
111121
# check run has not been logged already
112122
run_path = f"{project}/{fine_tune_id}"
113123
if entity is not None:
@@ -135,10 +145,6 @@ def _log_fine_tune(
135145
if wandb_status == "succeeded" and not force:
136146
return
137147

138-
# retrieve results
139-
results_id = fine_tune["result_files"][0]["id"]
140-
results = File.download(id=results_id).decode("utf-8")
141-
142148
# start a wandb run
143149
wandb.init(
144150
job_type="fine-tune",
@@ -251,6 +257,8 @@ def _log_artifact_inputs(cls, file, prefix, artifact_type, project, entity):
251257

252258
# get input artifact
253259
artifact_name = f"{prefix}-{filename}"
260+
# sanitize name to valid wandb artifact name
261+
artifact_name = re.sub(r"[^a-zA-Z0-9_\-.]", "_", artifact_name)
254262
artifact_alias = file_id
255263
artifact_path = f"{project}/{artifact_name}:{artifact_alias}"
256264
if entity is not None:

0 commit comments

Comments
 (0)