Commit 3269db84

Boris Dayma <boris.dayma@gmail.com>
2022-03-29 06:43:55
feat(wandb): sanitize name (#77)
* feat(wandb): sanitize name * feat(wandb): ensure results are present
1 parent 02e4008
Changed files (1)
openai/wandb_logger.py
@@ -10,6 +10,7 @@ if WANDB_AVAILABLE:
     import datetime
     import io
     import json
+    import re
     from pathlib import Path
 
     import numpy as np
@@ -108,6 +109,15 @@ class WandbLogger:
                 )
             return
 
+        # check results are present
+        try:
+            results_id = fine_tune["result_files"][0]["id"]
+            results = File.download(id=results_id).decode("utf-8")
+        except:
+            if show_individual_warnings:
+                print(f"Fine-tune {fine_tune_id} has no results and will not be logged")
+            return
+
         # check run has not been logged already
         run_path = f"{project}/{fine_tune_id}"
         if entity is not None:
@@ -135,10 +145,6 @@ class WandbLogger:
             if wandb_status == "succeeded" and not force:
                 return
 
-        # retrieve results
-        results_id = fine_tune["result_files"][0]["id"]
-        results = File.download(id=results_id).decode("utf-8")
-
         # start a wandb run
         wandb.init(
             job_type="fine-tune",
@@ -251,6 +257,8 @@ class WandbLogger:
 
         # get input artifact
         artifact_name = f"{prefix}-{filename}"
+        # sanitize name to valid wandb artifact name
+        artifact_name = re.sub(r"[^a-zA-Z0-9_\-.]", "_", artifact_name)
         artifact_alias = file_id
         artifact_path = f"{project}/{artifact_name}:{artifact_alias}"
         if entity is not None: