W&B MLOps
Weights Biases Career Development IT MLOps Experiment Tracking Model Registry Hyperparameter Sweep Artifacts Reports Portfolio Resume Production ML
| Feature | W&B | MLflow | Neptune | Comet ML |
|---|---|---|---|---|
| Experiment Track | ดีมาก | ดี | ดีมาก | ดีมาก |
| UI/Dashboard | ดีมาก | ปานกลาง | ดี | ดี |
| Sweep | Built-in Bayes | Plugin | Plugin | Built-in |
| Model Registry | ดี | ดีมาก | ดี | ดี |
| Free Tier | Personal unlimited | Open source | Limited | Limited |
| เหมาะกับ | Research + Prod | Enterprise OSS | Research | Research |
Experiment Tracking
# === W&B Experiment Tracking ===
# pip install wandb torch torchvision
# import wandb
# import torch
# import torch.nn as nn
#
# # Initialize
# wandb.init(
# project="image-classifier",
# name="resnet50-baseline",
# config={
# "architecture": "ResNet50",
# "dataset": "CIFAR-10",
# "epochs": 50,
# "batch_size": 32,
# "learning_rate": 0.001,
# "optimizer": "Adam",
# "weight_decay": 1e-4,
# }
# )
# config = wandb.config
#
# # Training Loop
# for epoch in range(config.epochs):
# model.train()
# for batch_idx, (data, target) in enumerate(train_loader):
# optimizer.zero_grad()
# output = model(data)
# loss = criterion(output, target)
# loss.backward()
# optimizer.step()
#
# wandb.log({
# "train/loss": loss.item(),
# "train/batch": batch_idx,
# "epoch": epoch,
# })
#
# # Validation
# val_loss, val_acc = evaluate(model, val_loader)
# wandb.log({
# "val/loss": val_loss,
# "val/accuracy": val_acc,
# "epoch": epoch,
# "learning_rate": optimizer.param_groups[0]["lr"],
# })
#
# # Log model checkpoint
# if val_acc > best_acc:
# wandb.save("best_model.pth")
# best_acc = val_acc
#
# wandb.finish()
from dataclasses import dataclass
@dataclass
class ExperimentRun:
run_name: str
model: str
lr: float
batch_size: int
val_acc: float
val_loss: float
epochs: int
duration: str
runs = [
ExperimentRun("resnet50-baseline", "ResNet50", 0.001, 32, 0.923, 0.245, 50, "2h 15m"),
ExperimentRun("resnet50-lr-high", "ResNet50", 0.01, 32, 0.891, 0.312, 50, "2h 10m"),
ExperimentRun("resnet50-batch64", "ResNet50", 0.001, 64, 0.918, 0.258, 50, "1h 45m"),
ExperimentRun("efficientnet-b0", "EfficientNet-B0", 0.001, 32, 0.935, 0.198, 50, "3h 20m"),
ExperimentRun("vit-small", "ViT-Small", 0.0003, 32, 0.941, 0.182, 100, "5h 40m"),
]
print("=== Experiment Runs ===")
for r in runs:
print(f" [{r.run_name}] Model: {r.model}")
print(f" LR: {r.lr} | BS: {r.batch_size} | Epochs: {r.epochs}")
print(f" Val Acc: {r.val_acc:.3f} | Val Loss: {r.val_loss:.3f} | Time: {r.duration}")
Hyperparameter Sweep
# === W&B Sweep Configuration ===
# sweep_config = {
# "method": "bayes", # grid, random, bayes
# "metric": {
# "name": "val/accuracy",
# "goal": "maximize"
# },
# "parameters": {
# "learning_rate": {
# "min": 0.0001,
# "max": 0.01,
# "distribution": "log_uniform_values"
# },
# "batch_size": {
# "values": [16, 32, 64, 128]
# },
# "optimizer": {
# "values": ["adam", "sgd", "adamw"]
# },
# "weight_decay": {
# "min": 1e-5,
# "max": 1e-2,
# "distribution": "log_uniform_values"
# },
# "dropout": {
# "min": 0.1,
# "max": 0.5
# }
# },
# "early_terminate": {
# "type": "hyperband",
# "min_iter": 10,
# "eta": 3
# }
# }
#
# sweep_id = wandb.sweep(sweep_config, project="image-classifier")
# wandb.agent(sweep_id, function=train, count=50)
@dataclass
class SweepResult:
rank: int
lr: float
batch_size: int
optimizer: str
dropout: float
val_acc: float
results = [
SweepResult(1, 0.00032, 32, "adamw", 0.25, 0.945),
SweepResult(2, 0.00045, 64, "adam", 0.20, 0.941),
SweepResult(3, 0.00028, 32, "adamw", 0.30, 0.939),
SweepResult(4, 0.001, 32, "adam", 0.15, 0.935),
SweepResult(5, 0.0005, 128, "sgd", 0.20, 0.928),
]
print("\n=== Top 5 Sweep Results ===")
for r in results:
print(f" Rank {r.rank}: Val Acc {r.val_acc:.3f}")
print(f" LR: {r.lr} | BS: {r.batch_size} | Opt: {r.optimizer} | Drop: {r.dropout}")
Career Portfolio
# === Building ML Career Portfolio ===
@dataclass
class PortfolioProject:
project: str
tech_stack: str
wandb_features: str
skill_demonstrated: str
portfolio_url: str
projects = [
PortfolioProject("Image Classification", "PyTorch ResNet EfficientNet",
"Experiment Tracking, Sweep, Model Registry",
"Deep Learning, Hyperparameter Tuning, MLOps",
"wandb.ai/username/image-classifier"),
PortfolioProject("NLP Sentiment Analysis", "HuggingFace Transformers BERT",
"Fine-tuning Tracking, Dataset Versioning",
"NLP, Transfer Learning, Data Pipeline",
"wandb.ai/username/sentiment"),
PortfolioProject("Object Detection", "YOLOv8 COCO Dataset",
"mAP Tracking, Confusion Matrix, Media Panel",
"Computer Vision, Model Evaluation",
"wandb.ai/username/yolo-detection"),
PortfolioProject("Time Series Forecast", "Prophet LSTM Transformer",
"Multi-model Comparison, Reports",
"Time Series, Feature Engineering",
"wandb.ai/username/forecasting"),
]
print("ML Career Portfolio:")
for p in projects:
print(f" [{p.project}] Stack: {p.tech_stack}")
print(f" W&B: {p.wandb_features}")
print(f" Skills: {p.skill_demonstrated}")
print(f" URL: {p.portfolio_url}")
career_path = {
"Junior ML Engineer": "W&B basics, Experiment Tracking, 2-3 projects",
"ML Engineer": "Sweeps, Model Registry, CI/CD, 5+ projects",
"Senior ML Engineer": "Full MLOps pipeline, Team collaboration, Reports",
"ML Architect": "Platform design, W&B Server self-hosted, Enterprise",
"Research Scientist": "Advanced experiments, Paper-quality Reports",
}
print(f"\n\nCareer Path:")
for k, v in career_path.items():
print(f" [{k}]: {v}")
เคล็ดลับ
- wandb.init: ตั้ง Project Name และ Config ทุกครั้ง
- Sweep: ใช้ Bayes Method สำหรับ Sweep ประสิทธิภาพดีกว่า Random
- Report: สร้าง W&B Report แชร์ผลงานแทน Notebook
- Portfolio: ใช้ W&B Public Profile เป็น ML Portfolio
- Community: เข้าร่วม W&B Community เรียนรู้จากู้คืนอื่น
การนำความรู้ไปประยุกต์ใช้งานจริง
แหล่งเรียนรู้ที่แนะนำ ได้แก่ Official Documentation ที่อัพเดทล่าสุดเสมอ Online Course จาก Coursera Udemy edX ช่อง YouTube คุณภาพทั้งไทยและอังกฤษ และ Community อย่าง Discord Reddit Stack Overflow ที่ช่วยแลกเปลี่ยนประสบการณ์กับนักพัฒนาทั่วโลก
Weights and Biases คืออะไร
MLOps Platform Experiment Tracking Metrics Loss Accuracy Model Registry Version Hyperparameter Sweep Artifacts Reports ฟรี Personal
ช่วยพัฒนาอาชีพ IT อย่างไร
ML Portfolio Public Profile Experiment Reports Hiring Manager MLOps Skill Resume Best Practices Certification Community Events Meetups
Experiment Tracking ทำอย่างไร
wandb.init() Project Config wandb.log() Metrics Step wandb.config Hyperparameters wandb.watch() Gradient Dashboard เปรียบเทียบ Run
Hyperparameter Sweep ทำอย่างไร
Sweep Config Parameter Space grid random bayes Metric Optimize wandb.sweep() wandb.agent() Parallel Coordinates Plot Early Terminate
สรุป
Weights Biases Career Development IT MLOps Experiment Tracking Model Registry Hyperparameter Sweep Portfolio Resume Reports Community Production ML
