Weights & Biases Low-Code MLOps
Weights Biases W&B wandb MLOps Experiment Tracking Sweeps Hyperparameter Reports Artifacts Model Registry Low Code No Code
| Feature | Code Required | What It Does | Use Case |
|---|---|---|---|
| Experiment Tracking | 2-3 บรรทัด | Track Metrics Loss Accuracy | ทุก ML Training |
| Sweeps | Config YAML + 2 บรรทัด | Auto Hyperparameter Tuning | หา Best Hyperparameters |
| Artifacts | 2 บรรทัด | Version Dataset Model | Data Model Management |
| Reports | No Code (UI) | Interactive Report Dashboard | Share Results กับทีม |
| Model Registry | No Code (UI) | Model Version Stage | Model Lifecycle Management |
Experiment Tracking
# === W&B Experiment Tracking ===
# pip install wandb
# wandb login # paste API key from wandb.ai/authorize
# Basic Usage (3 lines added to any training script)
# import wandb
#
# # Initialize run
# wandb.init(
# project="image-classification",
# config={
# "learning_rate": 0.001,
# "batch_size": 32,
# "epochs": 100,
# "model": "resnet50",
# "optimizer": "adam",
# "dropout": 0.3,
# }
# )
#
# # Training loop
# for epoch in range(config.epochs):
# train_loss, train_acc = train_one_epoch(model, train_loader)
# val_loss, val_acc = evaluate(model, val_loader)
#
# # Log metrics (1 line)
# wandb.log({
# "train/loss": train_loss,
# "train/accuracy": train_acc,
# "val/loss": val_loss,
# "val/accuracy": val_acc,
# "epoch": epoch,
# })
#
# # Log final model
# wandb.save("model_best.pth")
# wandb.finish()
# PyTorch Lightning (1 line integration)
# from pytorch_lightning.loggers import WandbLogger
# wandb_logger = WandbLogger(project="my-project")
# trainer = Trainer(logger=wandb_logger)
# Hugging Face (1 config change)
# TrainingArguments(report_to="wandb", ...)
from dataclasses import dataclass
@dataclass
class Integration:
framework: str
code_lines: int
method: str
auto_tracked: str
integrations = [
Integration("PyTorch (Manual)",
3,
"wandb.init() + wandb.log() + wandb.finish()",
"Metrics Config System Info GPU"),
Integration("PyTorch Lightning",
1,
"WandbLogger(project='name')",
"Loss Metrics LR Schedule Gradients Model Graph"),
Integration("Hugging Face",
1,
"report_to='wandb' ใน TrainingArguments",
"Loss Eval Metrics Config Model Card"),
Integration("Keras/TensorFlow",
1,
"WandbCallback() ใน model.fit(callbacks=[...])",
"Loss Metrics Layer Weights Gradients"),
Integration("Scikit-learn",
3,
"wandb.init() + wandb.sklearn.plot_*() + wandb.finish()",
"Confusion Matrix ROC Feature Importance"),
Integration("XGBoost/LightGBM",
2,
"wandb.xgboost.wandb_callback() หรือ lightgbm",
"Training Metrics Feature Importance Tree"),
]
print("=== Framework Integrations ===")
for i in integrations:
print(f" [{i.framework}] Code Lines: {i.code_lines}")
print(f" Method: {i.method}")
print(f" Auto-tracked: {i.auto_tracked}")
Sweeps (Hyperparameter Tuning)
# === W&B Sweeps Configuration ===
# sweep_config.yaml
# method: bayes
# metric:
# name: val/loss
# goal: minimize
# parameters:
# learning_rate:
# min: 0.0001
# max: 0.01
# batch_size:
# values: [16, 32, 64, 128]
# optimizer:
# values: ["adam", "sgd", "adamw"]
# dropout:
# min: 0.1
# max: 0.5
# weight_decay:
# min: 0.0001
# max: 0.01
# early_terminate:
# type: hyperband
# min_iter: 10
# Python:
# import wandb
#
# sweep_config = {
# "method": "bayes",
# "metric": {"name": "val/loss", "goal": "minimize"},
# "parameters": {
# "learning_rate": {"min": 0.0001, "max": 0.01},
# "batch_size": {"values": [16, 32, 64, 128]},
# "optimizer": {"values": ["adam", "sgd", "adamw"]},
# }
# }
#
# sweep_id = wandb.sweep(sweep_config, project="sweep-demo")
# wandb.agent(sweep_id, function=train, count=50)
@dataclass
class SweepMethod:
method: str
algorithm: str
best_for: str
efficiency: str
methods = [
SweepMethod("bayes",
"Bayesian Optimization (Gaussian Process)",
"ทั่วไป แนะนำ ใช้ Results เก่าเลือก Parameters ใหม่",
"สูง (หา Optimum เร็ว 20-50 runs)"),
SweepMethod("random",
"Random Search สุ่มจาก Search Space",
"Search Space กว้าง เริ่มต้น Explore",
"ปานกลาง (ต้อง 50-100+ runs)"),
SweepMethod("grid",
"Grid Search ทดสอบทุก Combination",
"Search Space เล็ก Parameters น้อย",
"ต่ำ (Combination มาก ใช้เวลานาน)"),
]
print("=== Sweep Methods ===")
for m in methods:
print(f" [{m.method}] {m.algorithm}")
print(f" Best for: {m.best_for}")
print(f" Efficiency: {m.efficiency}")
Reports & Model Registry
# === W&B Reports & Model Registry ===
# Artifacts (Model Versioning)
# import wandb
#
# # Log Model as Artifact
# run = wandb.init(project="my-project")
# artifact = wandb.Artifact("my-model", type="model")
# artifact.add_file("model_best.pth")
# run.log_artifact(artifact)
#
# # Download Model Artifact
# run = wandb.init()
# artifact = run.use_artifact("my-model:latest")
# artifact_dir = artifact.download()
# Model Registry (No Code - UI)
# 1. Go to Model Registry tab
# 2. Link Artifact to Registry
# 3. Set Stage: Staging → Production
# 4. Add Description, Tags
# 5. View Lineage: Dataset → Run → Model
@dataclass
class WBFeature:
feature: str
code_needed: str
ui_available: str
use_case: str
features = [
WBFeature("Experiment Dashboard",
"No (Auto-generated)",
"Full Dashboard Compare Filter Sort",
"เปรียบเทียบ Run ดู Metrics Trend"),
WBFeature("Reports",
"No (Drag-and-drop UI)",
"Interactive Markdown Charts Tables",
"แชร์ Results กับทีม สรุป Experiment"),
WBFeature("Artifacts",
"2 บรรทัด (log_artifact)",
"Browse Download Compare",
"Version Dataset Model Files"),
WBFeature("Model Registry",
"No (UI + optional API)",
"Stage Management Lineage Link",
"Model Lifecycle Staging → Production"),
WBFeature("Tables",
"1 บรรทัด (wandb.Table)",
"Interactive Filter Sort Visualize",
"Data Analysis EDA Error Analysis"),
WBFeature("Alerts",
"No (UI Config)",
"Slack Email Webhook",
"แจ้งเตือนเมื่อ Metric ถึง Threshold"),
]
print("=== W&B Features ===")
for f in features:
print(f" [{f.feature}] Code: {f.code_needed}")
print(f" UI: {f.ui_available}")
print(f" Use: {f.use_case}")
เคล็ดลับ
- wandb.init: ใส่ config ทุกครั้ง เปรียบเทียบ Hyperparameters ง่าย
- Sweeps: ใช้ Bayes เริ่มต้น 20-50 runs หา Best Parameters
- Tags: ใช้ Tags แบ่งกลุ่ม Run เช่น "baseline" "v2" "experiment"
- Artifacts: Log Model ทุกครั้ง ใช้ Model Registry จัดการ Stage
- Reports: สร้าง Report ทุกสัปดาห์ แชร์ Progress กับทีม
Weights & Biases คืออะไร
MLOps Platform Experiment Tracking Sweeps Artifacts Reports Model Registry wandb PyTorch Hugging Face Keras Low-Code Free Team
Experiment Tracking ทำอย่างไร
wandb.init wandb.log wandb.finish 2-3 บรรทัด Auto Dashboard Config Metrics Loss Accuracy PyTorch Lightning Hugging Face Callback
Sweeps ทำอย่างไร
Hyperparameter Tuning Bayes Random Grid sweep_config wandb.sweep wandb.agent Parameters min max values early_terminate hyperband
Reports & Collaboration ทำอย่างไร
Interactive Report Drag-drop Chart Markdown Share Link Team Workspace Artifacts Model Registry Stage Lineage Alert Slack Email
สรุป
Weights Biases W&B wandb Low Code Experiment Tracking Sweeps Bayes Artifacts Model Registry Reports Dashboard MLOps Production
