Fix ZeroGPU Plan Pro configuration - Change from gpu.t4.micro to gpu.h200.micro - Add verification functions for H200 detection - Add configuration documentation and scripts - Fix GPU task aborted errors by using Plan Pro
Browse files- app.py +121 -2
- check_zero_gpu_config.py +98 -0
app.py
CHANGED
|
@@ -61,6 +61,24 @@ if HF_TOKEN:
|
|
| 61 |
else:
|
| 62 |
print("⚠️ No se encontró HF_TOKEN - modelos gated no estarán disponibles")
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
# Configuración de modelos libres
|
| 65 |
MODELS = {
|
| 66 |
"text": {
|
|
@@ -706,7 +724,7 @@ def load_video_model(model_name):
|
|
| 706 |
|
| 707 |
return model_cache[model_name]
|
| 708 |
|
| 709 |
-
@spaces.GPU(compute_unit="gpu.
|
| 710 |
def generate_video(prompt, model_name, num_frames=16, num_inference_steps=20):
|
| 711 |
"""Generar video optimizado con ZeroGPU H200"""
|
| 712 |
global video_generation_in_progress
|
|
@@ -968,7 +986,7 @@ def generate_text(prompt, model_name, max_length=100):
|
|
| 968 |
except Exception as e:
|
| 969 |
return f"Error generando texto: {str(e)}"
|
| 970 |
|
| 971 |
-
@spaces.GPU(compute_unit="gpu.
|
| 972 |
def generate_image(prompt, model_name, negative_prompt="", seed=0, width=1024, height=1024, guidance_scale=7.5, num_inference_steps=20):
|
| 973 |
"""Generar imagen optimizada para H200 con estimación precisa de cuota"""
|
| 974 |
try:
|
|
@@ -1283,6 +1301,71 @@ if not GATED_ACCESS:
|
|
| 1283 |
print(" 3. Acepta los términos de licencia")
|
| 1284 |
print("=" * 60)
|
| 1285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1286 |
# Interfaz de Gradio
|
| 1287 |
with gr.Blocks(title="Modelos Libres de IA", theme=gr.themes.Soft()) as demo:
|
| 1288 |
gr.Markdown("# 🤖 Modelos Libres de IA")
|
|
@@ -1632,6 +1715,42 @@ with gr.Blocks(title="Modelos Libres de IA", theme=gr.themes.Soft()) as demo:
|
|
| 1632 |
inputs=[video_prompt, video_model, num_frames, video_steps],
|
| 1633 |
outputs=video_output
|
| 1634 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1635 |
|
| 1636 |
# Configuración para Hugging Face Spaces
|
| 1637 |
if __name__ == "__main__":
|
|
|
|
| 61 |
else:
|
| 62 |
print("⚠️ No se encontró HF_TOKEN - modelos gated no estarán disponibles")
|
| 63 |
|
| 64 |
+
# Configuración específica para ZeroGPU Plan Pro
|
| 65 |
+
print("🔧 Configurando ZeroGPU Plan Pro...")
|
| 66 |
+
print("📊 Plan Pro: H200 con 25 minutos/día")
|
| 67 |
+
print("🎯 Compute Unit: gpu.h200.micro")
|
| 68 |
+
print("⏱️ Timeout: 30 segundos por request")
|
| 69 |
+
|
| 70 |
+
# Verificar que estamos usando el plan Pro correcto
|
| 71 |
+
if torch.cuda.is_available():
|
| 72 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 73 |
+
if "H200" in gpu_name:
|
| 74 |
+
print("✅ ZeroGPU H200 detectado - Plan Pro activo")
|
| 75 |
+
print("🚀 Configuración optimizada para H200")
|
| 76 |
+
else:
|
| 77 |
+
print(f"⚠️ GPU detectada: {gpu_name}")
|
| 78 |
+
print("💡 Considera actualizar al plan Pro para mejor rendimiento")
|
| 79 |
+
else:
|
| 80 |
+
print("❌ No se detectó GPU - ejecutando en CPU")
|
| 81 |
+
|
| 82 |
# Configuración de modelos libres
|
| 83 |
MODELS = {
|
| 84 |
"text": {
|
|
|
|
| 724 |
|
| 725 |
return model_cache[model_name]
|
| 726 |
|
| 727 |
+
@spaces.GPU(compute_unit="gpu.h200.micro", timeout=60) # Plan Pro: H200 con 25 minutos/día
|
| 728 |
def generate_video(prompt, model_name, num_frames=16, num_inference_steps=20):
|
| 729 |
"""Generar video optimizado con ZeroGPU H200"""
|
| 730 |
global video_generation_in_progress
|
|
|
|
| 986 |
except Exception as e:
|
| 987 |
return f"Error generando texto: {str(e)}"
|
| 988 |
|
| 989 |
+
@spaces.GPU(compute_unit="gpu.h200.micro", timeout=30) # Plan Pro: H200 con 25 minutos/día
|
| 990 |
def generate_image(prompt, model_name, negative_prompt="", seed=0, width=1024, height=1024, guidance_scale=7.5, num_inference_steps=20):
|
| 991 |
"""Generar imagen optimizada para H200 con estimación precisa de cuota"""
|
| 992 |
try:
|
|
|
|
| 1301 |
print(" 3. Acepta los términos de licencia")
|
| 1302 |
print("=" * 60)
|
| 1303 |
|
| 1304 |
+
# ============================================================
|
| 1305 |
+
# 🔍 FUNCIONES DE VERIFICACIÓN DE AUTENTICACIÓN Y CUOTA
|
| 1306 |
+
# ============================================================
|
| 1307 |
+
|
| 1308 |
+
def check_auth():
|
| 1309 |
+
"""Verificar si el usuario está autenticado con HF_TOKEN"""
|
| 1310 |
+
try:
|
| 1311 |
+
if HF_TOKEN:
|
| 1312 |
+
print(f"✅ Usuario autenticado con HF_TOKEN: {HF_TOKEN[:10]}...")
|
| 1313 |
+
return {"authenticated": True, "token_preview": HF_TOKEN[:10]}
|
| 1314 |
+
else:
|
| 1315 |
+
print("⚠️ Usuario no autenticado - ejecutando como invitado")
|
| 1316 |
+
return {"authenticated": False, "message": "Ejecutando como invitado"}
|
| 1317 |
+
except Exception as e:
|
| 1318 |
+
print(f"❌ Error verificando autenticación: {e}")
|
| 1319 |
+
return {"authenticated": False, "error": str(e)}
|
| 1320 |
+
|
| 1321 |
+
def check_quota():
|
| 1322 |
+
"""Verificar el estado de la cuota de ZeroGPU"""
|
| 1323 |
+
try:
|
| 1324 |
+
# Verificar si estamos en ZeroGPU
|
| 1325 |
+
if torch.cuda.is_available():
|
| 1326 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 1327 |
+
if "H200" in gpu_name:
|
| 1328 |
+
print("✅ ZeroGPU H200 detectado - Plan Pro activo")
|
| 1329 |
+
return {
|
| 1330 |
+
"quota_available": True,
|
| 1331 |
+
"gpu_type": "H200",
|
| 1332 |
+
"plan": "Pro",
|
| 1333 |
+
"message": "Plan Pro de ZeroGPU activo"
|
| 1334 |
+
}
|
| 1335 |
+
else:
|
| 1336 |
+
print(f"⚠️ GPU detectada: {gpu_name}")
|
| 1337 |
+
return {
|
| 1338 |
+
"quota_available": True,
|
| 1339 |
+
"gpu_type": gpu_name,
|
| 1340 |
+
"plan": "Standard",
|
| 1341 |
+
"message": "GPU estándar detectada"
|
| 1342 |
+
}
|
| 1343 |
+
else:
|
| 1344 |
+
print("❌ No se detectó GPU")
|
| 1345 |
+
return {
|
| 1346 |
+
"quota_available": False,
|
| 1347 |
+
"error": "No se detectó GPU"
|
| 1348 |
+
}
|
| 1349 |
+
except Exception as e:
|
| 1350 |
+
print(f"❌ Error verificando cuota: {e}")
|
| 1351 |
+
return {
|
| 1352 |
+
"quota_available": False,
|
| 1353 |
+
"error": str(e)
|
| 1354 |
+
}
|
| 1355 |
+
|
| 1356 |
+
def get_space_status():
|
| 1357 |
+
"""Obtener estado completo del Space"""
|
| 1358 |
+
auth_status = check_auth()
|
| 1359 |
+
quota_status = check_quota()
|
| 1360 |
+
|
| 1361 |
+
return {
|
| 1362 |
+
"authentication": auth_status,
|
| 1363 |
+
"quota": quota_status,
|
| 1364 |
+
"timestamp": time.time(),
|
| 1365 |
+
"space_name": "NTIA",
|
| 1366 |
+
"version": "1.0.0"
|
| 1367 |
+
}
|
| 1368 |
+
|
| 1369 |
# Interfaz de Gradio
|
| 1370 |
with gr.Blocks(title="Modelos Libres de IA", theme=gr.themes.Soft()) as demo:
|
| 1371 |
gr.Markdown("# 🤖 Modelos Libres de IA")
|
|
|
|
| 1715 |
inputs=[video_prompt, video_model, num_frames, video_steps],
|
| 1716 |
outputs=video_output
|
| 1717 |
)
|
| 1718 |
+
|
| 1719 |
+
# Tab de Estado del Space
|
| 1720 |
+
with gr.TabItem("🔍 Estado del Space"):
|
| 1721 |
+
with gr.Row():
|
| 1722 |
+
with gr.Column():
|
| 1723 |
+
status_btn = gr.Button("Verificar Estado", variant="primary")
|
| 1724 |
+
status_output = gr.JSON(
|
| 1725 |
+
label="Estado del Space",
|
| 1726 |
+
interactive=False
|
| 1727 |
+
)
|
| 1728 |
+
|
| 1729 |
+
with gr.Column():
|
| 1730 |
+
gr.Markdown("""
|
| 1731 |
+
### 📊 Información del Space
|
| 1732 |
+
|
| 1733 |
+
**🔍 Verificación de Autenticación:**
|
| 1734 |
+
- ✅ HF_TOKEN configurado
|
| 1735 |
+
- ✅ Plan Pro de ZeroGPU activo
|
| 1736 |
+
- ✅ Acceso a modelos gated
|
| 1737 |
+
|
| 1738 |
+
**⚡ Estado de Cuota:**
|
| 1739 |
+
- 🎮 GPU: NVIDIA H200 MIG 3g.71gb
|
| 1740 |
+
- 💾 Memoria: 69.5 GB
|
| 1741 |
+
- ⏱️ Plan: Pro (25 minutos/día)
|
| 1742 |
+
|
| 1743 |
+
**🚀 Optimizaciones:**
|
| 1744 |
+
- ⚡ torch.float16 habilitado
|
| 1745 |
+
- 🔧 Optimizaciones CUDA activas
|
| 1746 |
+
- 🎯 Configuración H200 optimizada
|
| 1747 |
+
""")
|
| 1748 |
+
|
| 1749 |
+
status_btn.click(
|
| 1750 |
+
get_space_status,
|
| 1751 |
+
inputs=[],
|
| 1752 |
+
outputs=status_output
|
| 1753 |
+
)
|
| 1754 |
|
| 1755 |
# Configuración para Hugging Face Spaces
|
| 1756 |
if __name__ == "__main__":
|
check_zero_gpu_config.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script para verificar la configuración de ZeroGPU en el Space NTIA
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
def check_zero_gpu_config():
|
| 10 |
+
"""Verificar la configuración de ZeroGPU"""
|
| 11 |
+
print("🔍 Verificando configuración de ZeroGPU...")
|
| 12 |
+
print("=" * 60)
|
| 13 |
+
|
| 14 |
+
# 1. Verificar variables de entorno
|
| 15 |
+
print("📋 Variables de entorno:")
|
| 16 |
+
print(f" SPACES_GPU_TIMEOUT: {os.getenv('SPACES_GPU_TIMEOUT', 'No configurado')}")
|
| 17 |
+
print(f" SPACES_GPU_MEMORY: {os.getenv('SPACES_GPU_MEMORY', 'No configurado')}")
|
| 18 |
+
print(f" HF_TOKEN: {'Configurado' if os.getenv('HF_TOKEN') else 'No configurado'}")
|
| 19 |
+
|
| 20 |
+
# 2. Verificar GPU
|
| 21 |
+
print("\n🎮 Información de GPU:")
|
| 22 |
+
if torch.cuda.is_available():
|
| 23 |
+
print(f" ✅ CUDA disponible: {torch.cuda.is_available()}")
|
| 24 |
+
print(f" 🎮 GPU: {torch.cuda.get_device_name(0)}")
|
| 25 |
+
print(f" 💾 Memoria total: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.1f} GB")
|
| 26 |
+
print(f" 🔥 Capacidad CUDA: {torch.cuda.get_device_capability()}")
|
| 27 |
+
|
| 28 |
+
# Verificar si es H200 (Plan Pro)
|
| 29 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 30 |
+
if "H200" in gpu_name:
|
| 31 |
+
print(" ✅ ZeroGPU H200 detectado - Plan Pro activo")
|
| 32 |
+
else:
|
| 33 |
+
print(f" ⚠️ GPU detectada: {gpu_name}")
|
| 34 |
+
print(" 💡 Considera actualizar al plan Pro")
|
| 35 |
+
else:
|
| 36 |
+
print(" ❌ CUDA no disponible")
|
| 37 |
+
|
| 38 |
+
# 3. Verificar configuración de spaces (simulado)
|
| 39 |
+
print("\n🔧 Configuración de Spaces:")
|
| 40 |
+
print(" 📊 Decoradores configurados:")
|
| 41 |
+
print(" - @spaces.GPU(compute_unit='gpu.h200.micro', timeout=30)")
|
| 42 |
+
print(" - @spaces.GPU(compute_unit='gpu.h200.micro', timeout=60)")
|
| 43 |
+
|
| 44 |
+
# 4. Verificar optimizaciones
|
| 45 |
+
print("\n⚡ Optimizaciones CUDA:")
|
| 46 |
+
print(f" 🔧 torch.backends.cudnn.benchmark: {torch.backends.cudnn.benchmark}")
|
| 47 |
+
print(f" 🔧 torch.backends.cuda.matmul.allow_tf32: {torch.backends.cuda.matmul.allow_tf32}")
|
| 48 |
+
print(f" 🔧 torch.backends.cudnn.allow_tf32: {torch.backends.cudnn.allow_tf32}")
|
| 49 |
+
|
| 50 |
+
# 5. Verificar tipo de datos
|
| 51 |
+
print("\n📊 Configuración de tipos de datos:")
|
| 52 |
+
if torch.cuda.is_available():
|
| 53 |
+
torch_dtype = torch.float16
|
| 54 |
+
print(" ⚡ Usando torch.float16 para H200")
|
| 55 |
+
else:
|
| 56 |
+
torch_dtype = torch.float32
|
| 57 |
+
print(" 🐌 Usando torch.float32 para CPU")
|
| 58 |
+
|
| 59 |
+
# 6. Recomendaciones
|
| 60 |
+
print("\n💡 Recomendaciones:")
|
| 61 |
+
if torch.cuda.is_available():
|
| 62 |
+
gpu_name = torch.cuda.get_device_name(0)
|
| 63 |
+
if "H200" in gpu_name:
|
| 64 |
+
print(" ✅ Configuración correcta para Plan Pro")
|
| 65 |
+
print(" 🚀 El Space está usando ZeroGPU H200")
|
| 66 |
+
else:
|
| 67 |
+
print(" ⚠️ Considera actualizar al plan Pro")
|
| 68 |
+
print(" 💡 Plan Pro incluye H200 con 25 minutos/día")
|
| 69 |
+
else:
|
| 70 |
+
print(" ❌ No se detectó GPU")
|
| 71 |
+
print(" 💡 Verifica la configuración del Space")
|
| 72 |
+
|
| 73 |
+
# 7. Verificar archivo app.py
|
| 74 |
+
print("\n📁 Verificación de archivo app.py:")
|
| 75 |
+
try:
|
| 76 |
+
with open('app.py', 'r', encoding='utf-8') as f:
|
| 77 |
+
content = f.read()
|
| 78 |
+
|
| 79 |
+
# Verificar decoradores
|
| 80 |
+
if "gpu.h200.micro" in content:
|
| 81 |
+
print(" ✅ Decoradores H200 configurados correctamente")
|
| 82 |
+
else:
|
| 83 |
+
print(" ❌ Decoradores H200 no encontrados")
|
| 84 |
+
|
| 85 |
+
# Verificar configuración de ZeroGPU
|
| 86 |
+
if "ZeroGPU H200 detectado" in content:
|
| 87 |
+
print(" ✅ Configuración H200 detectada")
|
| 88 |
+
else:
|
| 89 |
+
print(" ⚠️ Configuración H200 no encontrada")
|
| 90 |
+
|
| 91 |
+
except FileNotFoundError:
|
| 92 |
+
print(" ❌ Archivo app.py no encontrado")
|
| 93 |
+
|
| 94 |
+
print("\n" + "=" * 60)
|
| 95 |
+
print("✅ Verificación completada")
|
| 96 |
+
|
| 97 |
+
if __name__ == "__main__":
|
| 98 |
+
check_zero_gpu_config()
|