Upload PLAN.md with huggingface_hub
Browse files
PLAN.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Plan: Train Model Tạo Ảnh 4K
|
| 2 |
+
|
| 3 |
+
## Mục tiêu
|
| 4 |
+
Tạo model tạo ảnh chất lượng cao native 2K/4K, self-host trên VPS H100, bán API.
|
| 5 |
+
|
| 6 |
+
## Infra
|
| 7 |
+
- VPS: Azure, 80 vCPU, 629GB RAM, 2x NVIDIA H100 NVL 96GB
|
| 8 |
+
- Số lượng VPS: 3+ (có thể scale thêm)
|
| 9 |
+
- GPU Driver: 580.95.05, CUDA 13.0
|
| 10 |
+
|
| 11 |
+
## Architecture: Cascaded Pipeline
|
| 12 |
+
|
| 13 |
+
```
|
| 14 |
+
Stage 1: Flux (fine-tuned) → Generate 1024px
|
| 15 |
+
Stage 2: SUPIR/StableSR (fine-tuned) → Upscale 1K → 2K
|
| 16 |
+
Stage 3: SUPIR/StableSR (fine-tuned) → Upscale 2K → 4K
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
## Cost ước tính
|
| 20 |
+
- Data collection: $0 (crawl free) + ~$20K (Opus caption, tuỳ deal)
|
| 21 |
+
- Training: $0 (VPS free)
|
| 22 |
+
- Tổng: $0 - $20K
|
| 23 |
+
|
| 24 |
+
## Timeline: ~8-9 tuần
|
| 25 |
+
|
| 26 |
+
| Phase | Công việc | Thời gian |
|
| 27 |
+
|-------|-----------|-----------|
|
| 28 |
+
| Phase 1 | Setup môi trường | 2-3 ngày |
|
| 29 |
+
| Phase 2 | Data collection | 1-2 tuần |
|
| 30 |
+
| Phase 3 | Training (3 stages song song) | 4-6 tuần |
|
| 31 |
+
| Phase 4 | Evaluation & iteration | 1-2 tuần |
|
| 32 |
+
| Phase 5 | Serving & API | 3-5 ngày |
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## Phase 1: Setup môi trường
|
| 37 |
+
|
| 38 |
+
### Mỗi VPS cài:
|
| 39 |
+
- Python 3.10+
|
| 40 |
+
- PyTorch 2.x (CUDA 13.0)
|
| 41 |
+
- diffusers, transformers, accelerate, deepspeed
|
| 42 |
+
- img2dataset, webdataset
|
| 43 |
+
- SUPIR / StableSR dependencies
|
| 44 |
+
|
| 45 |
+
### Phân VPS:
|
| 46 |
+
- VPS-1: Data collection + Train Stage 1 (Flux)
|
| 47 |
+
- VPS-2: Train Stage 2 (SR 1K→2K)
|
| 48 |
+
- VPS-3: Train Stage 3 (SR 2K→4K)
|
| 49 |
+
|
| 50 |
+
---
|
| 51 |
+
|
| 52 |
+
## Phase 2: Data Collection
|
| 53 |
+
|
| 54 |
+
### 2A — Dataset Stage 1 (1-2M ảnh 1024px + caption)
|
| 55 |
+
- Crawl: Unsplash, Pexels, LAION-Aesthetics (score > 6.0)
|
| 56 |
+
- Caption: Opus 4.6 API
|
| 57 |
+
- Format: WebDataset (tar shards)
|
| 58 |
+
|
| 59 |
+
### 2B — Dataset Stage 2-3 (200K-500K ảnh 4K pairs)
|
| 60 |
+
- Crawl: Unsplash 4K, Flickr CC high-res
|
| 61 |
+
- Tạo pairs: downscale 4K → 2K → 1K
|
| 62 |
+
- Augmentation: crop, flip, color jitter, degradation
|
| 63 |
+
|
| 64 |
+
---
|
| 65 |
+
|
| 66 |
+
## Phase 3: Training
|
| 67 |
+
|
| 68 |
+
### Stage 1: Fine-tune Flux
|
| 69 |
+
- Base: Flux Dev / Schnell
|
| 70 |
+
- Method: LoRA rank 128 hoặc full fine-tune (DeepSpeed ZeRO-2)
|
| 71 |
+
- Batch size: 8-16 (2x H100)
|
| 72 |
+
- LR: 1e-5, cosine decay
|
| 73 |
+
- Steps: 100K-500K
|
| 74 |
+
- Resolution: 1024x1024
|
| 75 |
+
|
| 76 |
+
### Stage 2: SR 1K→2K
|
| 77 |
+
- Base: SUPIR / StableSR
|
| 78 |
+
- Loss: L1 + perceptual + GAN
|
| 79 |
+
- Batch size: 2-4 per GPU
|
| 80 |
+
- Steps: 200K-500K
|
| 81 |
+
|
| 82 |
+
### Stage 3: SR 2K→4K
|
| 83 |
+
- Base: SUPIR / StableSR
|
| 84 |
+
- Loss: L1 + perceptual + GAN
|
| 85 |
+
- Batch size: 1-2 per GPU
|
| 86 |
+
- Steps: 200K-500K
|
| 87 |
+
|
| 88 |
+
---
|
| 89 |
+
|
| 90 |
+
## Phase 4: Evaluation
|
| 91 |
+
- FID score, CLIP score
|
| 92 |
+
- Human eval
|
| 93 |
+
- So sánh với Midjourney, DALL-E 3, Flux Pro
|
| 94 |
+
- Iterate nếu chưa đạt
|
| 95 |
+
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
## Phase 5: Serving
|
| 99 |
+
- FastAPI + Triton Inference Server
|
| 100 |
+
- Queue: Redis/RabbitMQ
|
| 101 |
+
- Pipeline: Stage 1 → 2 → 3
|
| 102 |
+
- API: POST /generate, GET /status, GET /result
|
| 103 |
+
- TensorRT optimize, target < 30s/ảnh 4K
|