MCPcopy
hub / github.com/Simple-Efficient/RL-Factory / __init__

Method __init__

verl/utils/tracking.py:28–112  ·  view source on GitHub ↗
(self, project_name, experiment_name, default_backend: Union[str, List[str]] = "console", config=None)

Source from the content-addressed store, hash-verified

26 supported_backend = ["wandb", "mlflow", "swanlab", "vemlp_wandb", "tensorboard", "console"]
27
28 def __init__(self, project_name, experiment_name, default_backend: Union[str, List[str]] = "console", config=None):
29 if isinstance(default_backend, str):
30 default_backend = [default_backend]
31 for backend in default_backend:
32 if backend == "tracking":
33 import warnings
34
35 warnings.warn("`tracking` logger is deprecated. use `wandb` instead.", DeprecationWarning, stacklevel=2)
36 else:
37 assert backend in self.supported_backend, f"{backend} is not supported"
38
39 self.logger = {}
40
41 if "tracking" in default_backend or "wandb" in default_backend:
42 import wandb
43
44 wandb.init(project=project_name, name=experiment_name, config=config)
45 self.logger["wandb"] = wandb
46
47 if "mlflow" in default_backend:
48 import os
49
50 import mlflow
51
52 MLFLOW_TRACKING_URI = os.environ.get("MLFLOW_TRACKING_URI", None)
53 if MLFLOW_TRACKING_URI:
54 mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)
55
56 # Project_name is actually experiment_name in MLFlow
57 # If experiment does not exist, will create a new experiment
58 experiment = mlflow.set_experiment(project_name)
59 mlflow.start_run(experiment_id=experiment.experiment_id, run_name=experiment_name)
60 mlflow.log_params(_compute_mlflow_params_from_objects(config))
61 self.logger["mlflow"] = _MlflowLoggingAdapter()
62
63 if "swanlab" in default_backend:
64 import os
65
66 import swanlab
67
68 SWANLAB_API_KEY = os.environ.get("SWANLAB_API_KEY", None)
69 SWANLAB_LOG_DIR = os.environ.get("SWANLAB_LOG_DIR", "swanlog")
70 SWANLAB_MODE = os.environ.get("SWANLAB_MODE", "cloud")
71 if SWANLAB_API_KEY:
72 swanlab.login(SWANLAB_API_KEY) # NOTE: previous login information will be overwritten
73
74 if config is None:
75 config = {} # make sure config is not None, otherwise **config will raise error
76 swanlab.init(
77 project=project_name,
78 experiment_name=experiment_name,
79 config={"FRAMEWORK": "verl", **config},
80 logdir=SWANLAB_LOG_DIR,
81 mode=SWANLAB_MODE,
82 )
83 self.logger["swanlab"] = swanlab
84
85 if "vemlp_wandb" in default_backend:

Callers

nothing calls this directly

Calls 6

LocalLoggerClass · 0.90
_TensorboardAdapterClass · 0.85
initMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected