| # Plan: Train Model Tạo Ảnh 4K |
|
|
| ## Mục tiêu |
| Tạo model tạo ảnh chất lượng cao native 2K/4K, self-host trên VPS H100, bán API. |
|
|
| ## Infra |
| - VPS: Azure, 80 vCPU, 629GB RAM, 2x NVIDIA H100 NVL 96GB |
| - Số lượng VPS: 3+ (có thể scale thêm) |
| - GPU Driver: 580.95.05, CUDA 13.0 |
|
|
| ## Architecture: Cascaded Pipeline |
|
|
| ``` |
| Stage 1: Flux (fine-tuned) → Generate 1024px |
| Stage 2: SUPIR/StableSR (fine-tuned) → Upscale 1K → 2K |
| Stage 3: SUPIR/StableSR (fine-tuned) → Upscale 2K → 4K |
| ``` |
|
|
| ## Cost ước tính |
| - Data collection: $0 (crawl free) + ~$20K (Opus caption, tuỳ deal) |
| - Training: $0 (VPS free) |
| - Tổng: $0 - $20K |
|
|
| ## Timeline: ~8-9 tuần |
|
|
| | Phase | Công việc | Thời gian | |
| |-------|-----------|-----------| |
| | Phase 1 | Setup môi trường | 2-3 ngày | |
| | Phase 2 | Data collection | 1-2 tuần | |
| | Phase 3 | Training (3 stages song song) | 4-6 tuần | |
| | Phase 4 | Evaluation & iteration | 1-2 tuần | |
| | Phase 5 | Serving & API | 3-5 ngày | |
|
|
| --- |
|
|
| ## Phase 1: Setup môi trường |
|
|
| ### Mỗi VPS cài: |
| - Python 3.10+ |
| - PyTorch 2.x (CUDA 13.0) |
| - diffusers, transformers, accelerate, deepspeed |
| - img2dataset, webdataset |
| - SUPIR / StableSR dependencies |
|
|
| ### Phân VPS: |
| - VPS-1: Data collection + Train Stage 1 (Flux) |
| - VPS-2: Train Stage 2 (SR 1K→2K) |
| - VPS-3: Train Stage 3 (SR 2K→4K) |
|
|
| --- |
|
|
| ## Phase 2: Data Collection |
|
|
| ### 2A — Dataset Stage 1 (1-2M ảnh 1024px + caption) |
| - Crawl: Unsplash, Pexels, LAION-Aesthetics (score > 6.0) |
| - Caption: Opus 4.6 API |
| - Format: WebDataset (tar shards) |
|
|
| ### 2B — Dataset Stage 2-3 (200K-500K ảnh 4K pairs) |
| - Crawl: Unsplash 4K, Flickr CC high-res |
| - Tạo pairs: downscale 4K → 2K → 1K |
| - Augmentation: crop, flip, color jitter, degradation |
|
|
| --- |
|
|
| ## Phase 3: Training |
|
|
| ### Stage 1: Fine-tune Flux |
| - Base: Flux Dev / Schnell |
| - Method: LoRA rank 128 hoặc full fine-tune (DeepSpeed ZeRO-2) |
| - Batch size: 8-16 (2x H100) |
| - LR: 1e-5, cosine decay |
| - Steps: 100K-500K |
| - Resolution: 1024x1024 |
|
|
| ### Stage 2: SR 1K→2K |
| - Base: SUPIR / StableSR |
| - Loss: L1 + perceptual + GAN |
| - Batch size: 2-4 per GPU |
| - Steps: 200K-500K |
|
|
| ### Stage 3: SR 2K→4K |
| - Base: SUPIR / StableSR |
| - Loss: L1 + perceptual + GAN |
| - Batch size: 1-2 per GPU |
| - Steps: 200K-500K |
|
|
| --- |
|
|
| ## Phase 4: Evaluation |
| - FID score, CLIP score |
| - Human eval |
| - So sánh với Midjourney, DALL-E 3, Flux Pro |
| - Iterate nếu chưa đạt |
|
|
| --- |
|
|
| ## Phase 5: Serving |
| - FastAPI + Triton Inference Server |
| - Queue: Redis/RabbitMQ |
| - Pipeline: Stage 1 → 2 → 3 |
| - API: POST /generate, GET /status, GET /result |
| - TensorRT optimize, target < 30s/ảnh 4K |
|
|