it

Stable Diffusion ComfyUI Metric Collection — เก็บ Metrics จาก AI Image Generation

stable diffusion comfyui metric collection
Stable Diffusion ComfyUI Metric Collection — เก็บ Metrics จาก AI Image Generation

Stable Diffusion และ ComfyUI คืออะไร

Stable Diffusion ComfyUI Metric Collection — เก็บ Metrics จาก AI Image Generation

Stable Diffusion เป็น open source text-to-image AI model ที่สร้างภาพจากข้อความ (prompts) พัฒนาโดย Stability AI รองรับ text-to-image, image-to-image, inpainting, outpainting และ ControlNet สำหรับควบคุม pose และ composition

ComfyUI เป็น node-based GUI สำหรับ Stable Diffusion ที่ให้ผู้ใช้สร้าง image generation workflows ด้วยการลาก nodes มาต่อกัน ข้อดีคือ flexible มากกว่า Automatic1111, รองรับ complex workflows เช่น multi-model pipelines, conditional generation, batch processing และ custom nodes จาก community

Metric Collection สำหรับ AI image generation สำคัญเพราะช่วย track generation speed (images/second), GPU utilization (VRAM usage, compute), model performance (quality scores), cost per image (electricity, cloud GPU costs) และ workflow efficiency (bottleneck identification)

Use cases ที่ต้องการ metrics ได้แก่ production image generation services, A/B testing different models/samplers, capacity planning สำหรับ GPU infrastructure, billing และ usage tracking สำหรับ SaaS และ quality monitoring เพื่อ detect model degradation

ติดตั้ง ComfyUI และ Stable Diffusion

วิธีติดตั้ง ComfyUI พร้อม monitoring

=== ติดตั้ง ComfyUI ===

Prerequisites

  • Python 3.10+
  • NVIDIA GPU with CUDA support
  • Git

Clone ComfyUI

git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI

สร้าง virtual environment

python -m venv venv

source venv/bin/activate # Linux/Mac

venv\Scripts\activate # Windows

ติดตั้ง dependencies

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt

ติดตั้ง monitoring dependencies

pip install prometheus_client psutil gputil pynvml flask

=== Download Models ===

SDXL 1.0

cd models/checkpoints
wget https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors

SD 1.5

wget https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors

VAE

cd ../vae
wget https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors
cd ../..

เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ Terraform State Log Management ELK

แนะนำเพิ่มเติม — คอร์สเทรด Forex ที่ iCafeForex

=== Docker Setup with Monitoring ===

docker-compose.yml

services:

comfyui:

build: .

ports:

  • "8188:8188"
  • "9090:9090" # Metrics endpoint

volumes:

  • ./models:/app/models
  • ./output:/app/output
  • ./custom_nodes:/app/custom_nodes

deploy:

resources:

reservations:

devices:

  • driver: nvidia

count: 1

capabilities: [gpu]

environment:

PROMETHEUS_METRICS: "true"

prometheus:

image: prom/prometheus:latest

ports: ["9091:9090"]

volumes:

  • ./prometheus.yml:/etc/prometheus/prometheus.yml

grafana:

image: grafana/grafana:latest

ports: ["3000:3000"]

environment:

GF_SECURITY_ADMIN_PASSWORD: admin

Start ComfyUI

python main.py --listen 0.0.0.0 --port 8188

เปิด browser: http://localhost:8188

เนื้อหาเกี่ยวข้อง — บทความที่เกี่ยวข้อง: Oscillator คืออะไร — วิธีตั้งค่าและใช้งานจริงพร้อมตัวอย่าง

สร้าง Workflow สำหรับ Image Generation

Stable Diffusion ComfyUI Metric Collection — เก็บ Metrics จาก AI Image Generation

ComfyUI workflow ผ่าน API

Metric Collection สำหรับ AI Image Generation

ระบบ collect metrics จาก ComfyUI

Automation และ Batch Processing

Batch generation ด้วย metrics tracking

Performance Monitoring และ Optimization

Monitor และ optimize generation performance

=== Prometheus Configuration ===

prometheus.yml

global:

scrape_interval: 15s

scrape_configs:

  • job_name: 'comfyui'

static_configs:

  • targets: ['localhost:9090']
  • job_name: 'nvidia_gpu'

static_configs:

  • targets: ['localhost:9400']

=== NVIDIA GPU Exporter (dcgm-exporter) ===

docker run -d --gpus all \
-p 9400:9400 \

nvcr.io/nvidia/k8s/dcgm-exporter:latest

=== Performance Optimization Tips ===

1. Model Loading Optimization

  • Keep models in VRAM (--highvram flag)
  • Use FP16 models instead of FP32 (half VRAM)

python main.py --listen 0.0.0.0 --highvram --fp16-vae

2. Xformers / Flash Attention

pip install xformers

python main.py --use-pytorch-cross-attention # or xformers auto

3. TensorRT Acceleration

pip install tensorrt

แนะนำเพิ่มเติม — บทวิเคราะห์จาก XM Signal

Convert model to TensorRT for 2-3x speedup

python convert_to_trt.py --model sdxl --height 1024 --width 1024

4. Batch Size Optimization

เนื้อหาเกี่ยวข้อง — แนะนำให้อ่าน docker build คือ — ข้อมูลครบถ้วน 2026

Test different batch sizes to find optimal for your GPU

VRAM usage scales linearly with batch size

RTX 3090 (24GB): batch 1-4 for SDXL, 1-8 for SD1.5

RTX 4090 (24GB): batch 1-4 for SDXL, 1-8 for SD1.5

A100 (80GB): batch 1-16 for SDXL

5. Resolution Optimization

Generate at lower resolution, then upscale

512x512 -> upscale 4x = 2048x2048 (faster than generating at 2048)

=== Grafana Dashboard Queries ===

GPU Utilization

rate(comfyui_gpu_utilization[5m])

Generation Rate (images/hour)

rate(comfyui_generations_total[1h]) * 3600

Average Generation Time

comfyui_generation_avg_ms

VRAM Usage %

comfyui_gpu_vram_used_mb / comfyui_gpu_vram_total_mb * 100

=== Alerting Rules ===

alerting_rules.yml

groups:

  • name: comfyui

rules:

  • alert: GPUHighTemperature

expr: comfyui_gpu_temperature > 85

for: 5m

เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ WebSocket Scaling Edge Deployment

labels:

severity: warning

annotations:

summary: "GPU temperature above 85C"

  • alert: VRAMNearFull

expr: comfyui_gpu_vram_used_mb / comfyui_gpu_vram_total_mb > 0.95

for: 1m

labels:

severity: critical

annotations:

summary: "GPU VRAM usage above 95%"

  • alert: SlowGeneration

expr: comfyui_generation_avg_ms > 30000

for: 10m

labels:

severity: warning

annotations:

summary: "Average generation time exceeds 30s"

echo "Performance monitoring configured"

FAQ คำถามที่พบบ่อย

Q: ComfyUI กับ Automatic1111 ต่างกันอย่างไร?

A: Automatic1111 (A1111) มี web UI ที่ใช้งานง่ายกว่าสำหรับผู้เริ่มต้น มี extensions ecosystem ใหญ่ ComfyUI ใช้ node-based workflow ที่ flexible กว่ามาก สร้าง complex pipelines ได้ ใช้ VRAM น้อยกว่า (efficient memory management) และเร็วกว่า สำหรับ production workloads ComfyUI เหมาะกว่าเพราะ API support ดี automation ง่าย และ reproducible workflows

Q: ต้องการ GPU อะไรสำหรับ Stable Diffusion?

A: ขั้นต่ำ NVIDIA GPU 8GB VRAM (RTX 3060) สำหรับ SD 1.5 แนะนำ 12GB+ VRAM (RTX 3060 12GB, RTX 4070) สำหรับ SDXL ต้อง 12GB+ VRAM สำหรับ production ที่ต้อง generate เร็ว RTX 4090 (24GB) หรือ A100 (40/80GB) เหมาะสม ราคา cloud GPU A100 ประมาณ $1-3/hr on-demand สำหรับ AMD GPU รองรับผ่าน ROCm แต่ performance ต่ำกว่า NVIDIA

Q: จะ track cost per image ได้อย่างไร?

A: คำนวณจาก GPU power consumption (watts) * generation time (hours) * electricity rate (THB/kWh) เช่น RTX 4090 ใช้ ~450W generation 5 วินาที = 0.000625 kWh * 5 THB/kWh = 0.003 THB/image สำหรับ cloud GPU คำนวณจาก hourly rate / images per hour เช่น A100 $3/hr generate 720 images/hr = $0.004/image ใช้ metrics collector track generation time แล้วคำนวณ cost อัตโนมัติ

Q: จะ monitor quality ของ generated images ได้อย่างไร?

A: ใช้ automated quality metrics เช่น FID (Frechet Inception Distance) วัดความคล้าย distribution กับ real images, CLIP Score วัดความตรงกับ prompt, Aesthetic Score วัดความสวย ใช้ LAION aesthetic predictor เก็บ scores ใน metrics database แล้ว track over time ถ้า scores ลดลงอาจบ่งบอกว่า model degradation หรือ prompt quality ลดลง สำหรับ production ใช้ human evaluation เสริมด้วย automated metrics

XM Legend · เทรดเดอร์ & ผู้สอน Forex 13 ปี

ผู้ก่อตั้ง SiamCafe ตั้งแต่ปี 1997 · เทรดเดอร์สาย Forex มากกว่า 13 ปี ได้รับการยกย่องเป็น XM Legend · แบ่งปันความรู้ Forex, ไอที, AI และการเทรด จากประสบการณ์จริงในตลาดจริง