From 416e2e1dd54aa17f5fddcdc7190865a4ede48386 Mon Sep 17 00:00:00 2001 From: NumZ Date: Sun, 22 Jun 2025 17:07:50 +0200 Subject: [PATCH] Update README --- VRAM_OPTIMIZATIONS_SUMMARY.md | 185 ---------------------------------- 1 file changed, 185 deletions(-) delete mode 100644 VRAM_OPTIMIZATIONS_SUMMARY.md diff --git a/VRAM_OPTIMIZATIONS_SUMMARY.md b/VRAM_OPTIMIZATIONS_SUMMARY.md deleted file mode 100644 index 94bd280..0000000 --- a/VRAM_OPTIMIZATIONS_SUMMARY.md +++ /dev/null @@ -1,185 +0,0 @@ -# 🚀 Optimisations VRAM Ultra-Agressives - SeedVR2 - -## 📊 Problème Résolu - -**Avant optimisations :** - -- ❌ VRAM pic : 23.5GB (dépassement GPU 24GB) -- ❌ Accumulation entre batches : 6.5GB → 16.3GB → 22.3GB -- ❌ Erreurs Out of Memory fréquentes - -**Après optimisations :** - -- ✅ VRAM pic réduit : ~12-15GB (réduction de ~40-50%) -- ✅ Meilleur nettoyage entre batches -- ✅ Compatible GPU 12GB+ avec modèle 3B - ---- - -## 🔧 Optimisations Ultra-Agressives Implémentées - -### 1. **Calcul DiT Séquentiel avec Offloading** - -```python -# AVANT: Calcul parallèle (consomme 2x la VRAM) -pos_result = dit(input_pos) # 11GB -neg_result = dit(input_neg) # 11GB + 11GB = 22GB - -# APRÈS: Calcul séquentiel avec offloading -pos_result = dit(input_pos) # 11GB -pos_result_cpu = pos_result.cpu() # Offload sur CPU -del pos_result; torch.cuda.empty_cache() # Libérer GPU -neg_result = dit(input_neg) # 11GB (réutilise l'espace) -pos_result = pos_result_cpu.to("cuda") # Recharger -result = cfg_combine(pos_result, neg_result) # 11GB final -``` - -### 2. **Nettoyage Mémoire Ultra-Agressif** - -```python -# Après chaque batch -runner.dit.to("cpu") # Libérer DiT -runner.vae.to("cpu") # Libérer VAE -torch.cuda.empty_cache() # Vider cache -torch.cuda.synchronize() # Attendre fin opérations -gc.collect() # Garbage collection Python -``` - -### 3. **Gradient Checkpointing Simulé** - -```python -# Utiliser torch.utils.checkpoint si disponible -if hasattr(torch.utils.checkpoint, 'checkpoint'): - result = torch.utils.checkpoint.checkpoint( - model, input, use_reentrant=False - ) -``` - -### 4. **Calculs In-Place pour CFG** - -```python -# AVANT: Créer nouveaux tenseurs -result = neg_result + cfg_scale * (pos_result - neg_result) # 3 tenseurs - -# APRÈS: Calculs in-place -pos_result.sub_(neg_result) # pos_result -= neg_result -pos_result.mul_(cfg_scale) # pos_result *= cfg_scale -result = neg_result.add_(pos_result) # 1 seul tenseur final -``` - -### 5. **Monitoring VRAM Détaillé** - -```python -print(f"🔍 VRAM avant DiT step: {vram:.1f}GB") -print(f"🔍 VRAM après calcul positif: {vram:.1f}GB") -print(f"🔍 VRAM après calcul négatif: {vram:.1f}GB") -print(f"🔍 VRAM après DiT step: {vram:.1f}GB") -``` - ---- - -## 📈 Résultats Attendus - -### Avant vs Après - -| Étape | Avant | Après | Réduction | -| ------------------ | ------------ | ----- | --------- | -| Chargement modèle | 13GB | 6.5GB | -50% | -| DiT calcul positif | 11GB | 11GB | 0% | -| DiT calcul négatif | +11GB (22GB) | 11GB | -50% | -| CFG combinaison | +2GB (24GB) | 11GB | -54% | -| Entre batches | 16.3GB | ~7GB | -57% | - -### Performance par GPU - -| GPU | VRAM | Modèle | Batch Size | Mode | Status | -| -------- | ---- | ------ | ---------- | --------------- | -------------- | -| RTX 4090 | 24GB | 7B | 60-80 | auto | ✅ Optimal | -| RTX 4080 | 16GB | 3B | 40-50 | economy | ✅ Bon | -| RTX 4070 | 12GB | 3B | 20-30 | extreme_economy | ✅ Minimal | -| RTX 4060 | 8GB | - | - | - | ❌ Insuffisant | - ---- - -## 🧪 Test des Optimisations - -### Validation Rapide - -```bash -cd ComfyUI/custom_nodes/ComfyUI-SeedVR2_VideoUpscaler -python test_optimizations_final.py -``` - -### Logs à Surveiller - -``` -🔍 VRAM avant DiT step 0: 6.5GB # Début normal -🔍 VRAM après calcul positif: 17.5GB # Pic temporaire -🔍 VRAM après calcul négatif: 12.0GB # Réduction après offload -🔍 VRAM après DiT step 0: 11.5GB # Stabilisation -🔍 VRAM après nettoyage batch: 7.0GB # Retour proche initial -``` - ---- - -## ⚙️ Configuration Recommandée - -### Interface ComfyUI - -- **vram_mode**: `extreme_economy` pour GPU 12-16GB -- **batch_size**: Commencer par 20, augmenter si stable -- **quantization**: `auto_fp16` (obligatoire) - -### Paramètres Avancés - -```python -# Dans seedvr2.py - Ajustements possibles -OFFLOAD_THRESHOLD = 20.0 # GB - Seuil pour offloading automatique -MAX_BATCH_SIZE_12GB = 20 # Batch max pour GPU 12GB -MAX_BATCH_SIZE_16GB = 40 # Batch max pour GPU 16GB -``` - ---- - -## 🚨 Dépannage - -### Si VRAM > 20GB persistante - -1. **Réduire batch_size** à 10-15 -2. **Redémarrer ComfyUI** pour nettoyer complètement -3. **Vérifier** qu'aucun autre processus utilise le GPU -4. **Forcer** `extreme_economy` mode - -### Si erreur "checkpoint not found" - -- Le gradient checkpointing est optionnel -- Fallback automatique vers calcul normal -- Performance légèrement réduite mais fonctionnel - -### Si performance très lente - -- **GPU trop petit** : Passer au modèle 3B -- **Batch trop petit** : Augmenter si VRAM permet -- **Offloading excessif** : Ajuster OFFLOAD_THRESHOLD - ---- - -## 🎯 Prochaines Améliorations - -1. **Quantification INT8** : Réduction supplémentaire de 50% -2. **Pipeline asynchrone** : Calcul pendant transferts CPU/GPU -3. **Cache intelligent** : Réutiliser calculs similaires -4. **Compression dynamique** : Compresser activations non critiques - ---- - -## ✅ Checklist de Validation - -- [ ] Monitoring VRAM détaillé s'affiche -- [ ] VRAM pic < 15GB sur GPU 16GB+ -- [ ] Pas d'erreur OOM -- [ ] VRAM revient proche initial entre batches -- [ ] Performance acceptable (< 2x plus lent) -- [ ] Qualité vidéo préservée - -**Objectif atteint** : SeedVR2 fonctionnel sur GPU 12-24GB avec réduction VRAM de ~50% 🎉