Spaces:
Paused
Paused
lazy import torch/cordon for ZeroGPU compatibility
Browse files
app.py
CHANGED
|
@@ -11,9 +11,10 @@ from pathlib import Path
|
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
import spaces
|
| 14 |
-
import torch
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Configure logging for HuggingFace Spaces visibility
|
| 19 |
logging.basicConfig(
|
|
@@ -57,7 +58,13 @@ def analyze_logs(
|
|
| 57 |
|
| 58 |
This function is decorated with @spaces.GPU to run on ZeroGPU.
|
| 59 |
The GPU is allocated when this function is called.
|
|
|
|
|
|
|
|
|
|
| 60 |
"""
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
start_time = time.time()
|
| 63 |
logger.info("=" * 60)
|
|
@@ -338,13 +345,12 @@ result = analyzer.analyze_file(Path("system.log"))
|
|
| 338 |
|
| 339 |
|
| 340 |
# Startup logging
|
| 341 |
-
# NOTE:
|
| 342 |
logger.info("=" * 60)
|
| 343 |
logger.info("Cordon Space starting...")
|
| 344 |
logger.info(f"Python version: {sys.version}")
|
| 345 |
logger.info(f"Gradio version: {gr.__version__}")
|
| 346 |
-
logger.info(
|
| 347 |
-
logger.info("CUDA check deferred to @spaces.GPU function (ZeroGPU)")
|
| 348 |
logger.info("=" * 60)
|
| 349 |
|
| 350 |
# Create and launch the demo
|
|
|
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
import spaces
|
|
|
|
| 14 |
|
| 15 |
+
# NOTE: Do NOT import torch or cordon at module level!
|
| 16 |
+
# ZeroGPU requires all CUDA-related imports to happen inside @spaces.GPU functions.
|
| 17 |
+
# Importing torch at module level can trigger CUDA initialization and hang the space.
|
| 18 |
|
| 19 |
# Configure logging for HuggingFace Spaces visibility
|
| 20 |
logging.basicConfig(
|
|
|
|
| 58 |
|
| 59 |
This function is decorated with @spaces.GPU to run on ZeroGPU.
|
| 60 |
The GPU is allocated when this function is called.
|
| 61 |
+
|
| 62 |
+
IMPORTANT: torch and cordon are imported here (not at module level)
|
| 63 |
+
because ZeroGPU only allocates GPU resources inside @spaces.GPU functions.
|
| 64 |
"""
|
| 65 |
+
# Lazy imports - only load when GPU is allocated
|
| 66 |
+
import torch
|
| 67 |
+
from cordon import AnalysisConfig, SemanticLogAnalyzer
|
| 68 |
|
| 69 |
start_time = time.time()
|
| 70 |
logger.info("=" * 60)
|
|
|
|
| 345 |
|
| 346 |
|
| 347 |
# Startup logging
|
| 348 |
+
# NOTE: torch is imported lazily inside @spaces.GPU function for ZeroGPU compatibility
|
| 349 |
logger.info("=" * 60)
|
| 350 |
logger.info("Cordon Space starting...")
|
| 351 |
logger.info(f"Python version: {sys.version}")
|
| 352 |
logger.info(f"Gradio version: {gr.__version__}")
|
| 353 |
+
logger.info("PyTorch/Cordon loaded lazily inside @spaces.GPU function")
|
|
|
|
| 354 |
logger.info("=" * 60)
|
| 355 |
|
| 356 |
# Create and launch the demo
|