eda_trainning_lora / reporting.py
Ademir
Initial clean commit: scripts and config without logs
d4a00b2
"""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