File size: 1,604 Bytes
d4a00b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Destinos de logging (TensorBoard, Weights & Biases) para o train.py.

Variáveis opcionais para rastrear o dataset no mesmo run W&B (ver train.py):
DATASET_VERSION, DATASET_MANIFEST_HASH, DATASET_MANIFEST_PATH.
"""

from __future__ import annotations

import os

DEFAULT_WANDB_PROJECT = "bequick"
DEFAULT_WANDB_ENTITY = "amaro-neto-amaro"


def wandb_credentials_or_offline() -> bool:
    """True se houver API key ou modo offline (wandb local sem upload)."""
    key = (os.environ.get("WANDB_API_KEY") or "").strip()
    offline = (os.environ.get("WANDB_MODE") or "").strip().lower() == "offline"
    return bool(key) or offline


def wandb_reporting_requested() -> bool:
    if (os.environ.get("WANDB_DISABLED") or "").strip().lower() in ("1", "true", "yes"):
        return False
    return wandb_credentials_or_offline()


def apply_wandb_defaults() -> None:
    os.environ.setdefault("WANDB_PROJECT", DEFAULT_WANDB_PROJECT)
    os.environ.setdefault("WANDB_ENTITY", DEFAULT_WANDB_ENTITY)


def wandb_package_available() -> bool:
    try:
        import wandb  # noqa: F401
    except ImportError:
        return False
    return True


def build_report_backends() -> list[str]:
    backends: list[str] = ["tensorboard"]
    if not wandb_reporting_requested():
        return backends
    if not wandb_package_available():
        print(
            "AVISO: wandb configurado (WANDB_API_KEY ou WANDB_MODE=offline) "
            "mas pacote nao instalado. Instala com: pip install wandb"
        )
        return backends
    apply_wandb_defaults()
    backends.append("wandb")
    return backends