File tree 6 files changed +16
-1
lines changed
6 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
2
from pprint import pprint
3
-
3
+ import os
4
4
import hydra
5
5
import pandas as pd
6
6
import wandb
@@ -34,6 +34,9 @@ def main(cfg: MetricsConfig):
34
34
print (f"==== Using config ====\n { OmegaConf .to_yaml (cfg )} " )
35
35
36
36
if cfg .logger .use_wandb :
37
+ if cfg .logger .use_api_key :
38
+ with open (hydra .utils .to_absolute_path ("wandb_api_key.txt" ), "r" ) as f :
39
+ os .environ ["WANDB_API_KEY" ] = f .read ().strip ()
37
40
wandb .Table .MAX_ROWS = 50000
38
41
run : wandb .wandb_sdk .wandb_run .Run = wandb .init (
39
42
project = cfg .logger .project ,
Original file line number Diff line number Diff line change @@ -49,11 +49,13 @@ class WandbEvalConfig:
49
49
use_wandb: Whether W&B will be used for logging or not.
50
50
project: Name of project this run will appear in.
51
51
load_artifact: Whether model checkpoint should be loaded from W&B artifact or not.
52
+ use_api_key: True to read an API key from a local file (expected to be stored in `wandb_api_key.txt`).
52
53
"""
53
54
54
55
use_wandb : bool = True
55
56
project : str = "commit_message_completion"
56
57
load_artifact : bool = True
58
+ use_api_key : bool = False
57
59
artifact_config : ArtifactEvalConfig = field (default_factory = ArtifactEvalConfig )
58
60
59
61
Original file line number Diff line number Diff line change @@ -39,11 +39,13 @@ class WandbMetricConfig:
39
39
use_wandb: Whether W&B will be used for logging or not.
40
40
project: Name of project this run will appear in.
41
41
load_artifact: Whether model predictions should be loaded from W&B artifact or not.
42
+ use_api_key: True to read an API key from a local file (expected to be stored in `wandb_api_key.txt`).
42
43
"""
43
44
44
45
use_wandb : bool = True
45
46
project : str = "commit_message_completion"
46
47
load_artifact : bool = True
48
+ use_api_key : bool = False
47
49
artifact_config : ArtifactMetricConfig = field (default_factory = ArtifactMetricConfig )
48
50
49
51
Original file line number Diff line number Diff line change @@ -50,11 +50,13 @@ class WandbTrainConfig:
50
50
use_wandb: Whether W&B will be used for logging or not.
51
51
project: Name of a project this run will appear in.
52
52
save_artifact: True to load model checkpoints to W&B as artifacts, False otherwise.
53
+ use_api_key: True to read an API key from a local file (expected to be stored in `wandb_api_key.txt`).
53
54
"""
54
55
55
56
use_wandb : bool = True
56
57
project : str = "commit_message_completion"
57
58
save_artifact : bool = True
59
+ use_api_key : bool = False
58
60
59
61
60
62
@dataclass
Original file line number Diff line number Diff line change @@ -54,6 +54,9 @@ def main(cfg: EvalConfig) -> None:
54
54
)
55
55
56
56
if cfg .logger .use_wandb and cfg .logger .load_artifact :
57
+ if cfg .logger .use_api_key :
58
+ with open (hydra .utils .to_absolute_path ("wandb_api_key.txt" ), "r" ) as f :
59
+ os .environ ["WANDB_API_KEY" ] = f .read ().strip ()
57
60
artifact_name = f"{ cfg .logger .artifact_config .project } /{ run_name } :{ cfg .logger .artifact_config .version } "
58
61
artifact = trainer_logger .experiment .use_artifact (artifact_name )
59
62
if "tags" in artifact .metadata :
Original file line number Diff line number Diff line change @@ -95,6 +95,9 @@ def main(cfg: TrainConfig) -> None:
95
95
96
96
# logger
97
97
if cfg .logger .use_wandb :
98
+ if cfg .logger .use_api_key :
99
+ with open (hydra .utils .to_absolute_path ("wandb_api_key.txt" ), "r" ) as f :
100
+ os .environ ["WANDB_API_KEY" ] = f .read ().strip ()
98
101
trainer_logger = pl .loggers .WandbLogger (
99
102
name = run_name ,
100
103
project = cfg .logger .project ,
You can’t perform that action at this time.
0 commit comments