A unified tracking interface for logging experiment data to multiple backends. This class provides a centralized way to log experiment metrics, parameters, and artifacts to various tracking backends including WandB, MLflow, SwanLab, TensorBoard, and console. Attributes: support
| 27 | |
| 28 | |
| 29 | class Tracking: |
| 30 | """A unified tracking interface for logging experiment data to multiple backends. |
| 31 | |
| 32 | This class provides a centralized way to log experiment metrics, parameters, and artifacts |
| 33 | to various tracking backends including WandB, MLflow, SwanLab, TensorBoard, and console. |
| 34 | |
| 35 | Attributes: |
| 36 | supported_backend: List of supported tracking backends. |
| 37 | logger: Dictionary of initialized logger instances for each backend. |
| 38 | """ |
| 39 | |
| 40 | supported_backend = [ |
| 41 | "wandb", |
| 42 | "mlflow", |
| 43 | "swanlab", |
| 44 | "vemlp_wandb", |
| 45 | "tensorboard", |
| 46 | "console", |
| 47 | "clearml", |
| 48 | "trackio", |
| 49 | "file", |
| 50 | ] |
| 51 | |
| 52 | def __init__(self, project_name, experiment_name, default_backend: str | list[str] = "console", config=None): |
| 53 | if isinstance(default_backend, str): |
| 54 | default_backend = [default_backend] |
| 55 | for backend in default_backend: |
| 56 | if backend == "tracking": |
| 57 | import warnings |
| 58 | |
| 59 | warnings.warn("`tracking` logger is deprecated. use `wandb` instead.", DeprecationWarning, stacklevel=2) |
| 60 | else: |
| 61 | assert backend in self.supported_backend, f"{backend} is not supported" |
| 62 | |
| 63 | self.logger = {} |
| 64 | |
| 65 | if "tracking" in default_backend or "wandb" in default_backend: |
| 66 | import os |
| 67 | |
| 68 | import wandb |
| 69 | |
| 70 | settings = None |
| 71 | if config and config["trainer"].get("wandb_proxy", None): |
| 72 | settings = wandb.Settings(https_proxy=config["trainer"]["wandb_proxy"]) |
| 73 | entity = os.environ.get("WANDB_ENTITY", None) |
| 74 | wandb.init(project=project_name, name=experiment_name, entity=entity, config=config, settings=settings) |
| 75 | self.logger["wandb"] = wandb |
| 76 | |
| 77 | if "trackio" in default_backend: |
| 78 | import trackio |
| 79 | |
| 80 | trackio.init(project=project_name, name=experiment_name, config=config) |
| 81 | self.logger["trackio"] = trackio |
| 82 | |
| 83 | if "mlflow" in default_backend: |
| 84 | import os |
| 85 | |
| 86 | import mlflow |