Spaces:
Sleeping
Sleeping
Commit
·
5a63400
1
Parent(s):
745484d
Fix initial bugs
Browse files- Dockerfile +3 -1
- app.py +24 -19
Dockerfile
CHANGED
|
@@ -24,10 +24,12 @@ RUN mkdir -p csgo/spawn config checkpoints cache && \
|
|
| 24 |
|
| 25 |
# Set environment variables
|
| 26 |
ENV PYTHONPATH=/app/src:/app
|
| 27 |
-
ENV CUDA_VISIBLE_DEVICES=""
|
| 28 |
ENV OMP_NUM_THREADS=2
|
| 29 |
ENV MKL_NUM_THREADS=2
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
# Set cache directories to writable locations
|
| 32 |
ENV TORCH_HOME=/tmp/torch
|
| 33 |
ENV HF_HOME=/tmp/huggingface
|
|
|
|
| 24 |
|
| 25 |
# Set environment variables
|
| 26 |
ENV PYTHONPATH=/app/src:/app
|
|
|
|
| 27 |
ENV OMP_NUM_THREADS=2
|
| 28 |
ENV MKL_NUM_THREADS=2
|
| 29 |
|
| 30 |
+
# Don't set CUDA_VISIBLE_DEVICES="" - let HF Spaces GPU be detected
|
| 31 |
+
# ENV CUDA_VISIBLE_DEVICES="" # Removed - this disables GPU!
|
| 32 |
+
|
| 33 |
# Set cache directories to writable locations
|
| 34 |
ENV TORCH_HOME=/tmp/torch
|
| 35 |
ENV HF_HOME=/tmp/huggingface
|
app.py
CHANGED
|
@@ -3,13 +3,30 @@ Web-based Diamond CSGO AI Player for Hugging Face Spaces
|
|
| 3 |
Uses FastAPI + WebSocket for real-time keyboard input and game streaming
|
| 4 |
"""
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import asyncio
|
| 7 |
import base64
|
| 8 |
import io
|
| 9 |
import json
|
| 10 |
import logging
|
| 11 |
-
import os
|
| 12 |
-
import tempfile
|
| 13 |
from pathlib import Path
|
| 14 |
from typing import Dict, List, Optional, Set
|
| 15 |
|
|
@@ -53,20 +70,7 @@ os.environ.setdefault("SDL_VIDEODRIVER", "dummy")
|
|
| 53 |
os.environ.setdefault("SDL_AUDIODRIVER", "dummy")
|
| 54 |
os.environ.setdefault("PYGAME_HIDE_SUPPORT_PROMPT", "1")
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
if "OMP_NUM_THREADS" not in os.environ or not os.environ["OMP_NUM_THREADS"].isdigit():
|
| 58 |
-
os.environ["OMP_NUM_THREADS"] = "2"
|
| 59 |
-
|
| 60 |
-
# Set up proper cache directories for HF Spaces
|
| 61 |
-
temp_dir = tempfile.gettempdir()
|
| 62 |
-
os.environ.setdefault("TORCH_HOME", os.path.join(temp_dir, "torch"))
|
| 63 |
-
os.environ.setdefault("HF_HOME", os.path.join(temp_dir, "huggingface"))
|
| 64 |
-
os.environ.setdefault("TRANSFORMERS_CACHE", os.path.join(temp_dir, "transformers"))
|
| 65 |
-
|
| 66 |
-
# Create cache directories
|
| 67 |
-
for cache_var in ["TORCH_HOME", "HF_HOME", "TRANSFORMERS_CACHE"]:
|
| 68 |
-
cache_path = os.environ[cache_var]
|
| 69 |
-
os.makedirs(cache_path, exist_ok=True)
|
| 70 |
connected_clients: Set[WebSocket] = set()
|
| 71 |
|
| 72 |
class WebKeyMap:
|
|
@@ -212,18 +216,19 @@ class WebGameEngine:
|
|
| 212 |
cfg.agent = OmegaConf.load(config_path / "agent" / "csgo.yaml")
|
| 213 |
cfg.env = OmegaConf.load(config_path / "env" / "csgo.yaml")
|
| 214 |
|
| 215 |
-
# Use
|
| 216 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 217 |
logger.info(f"Using device: {device}")
|
| 218 |
|
| 219 |
-
# Log GPU availability and CUDA info for debugging
|
| 220 |
if torch.cuda.is_available():
|
| 221 |
logger.info(f"CUDA available: {torch.cuda.is_available()}")
|
| 222 |
logger.info(f"GPU device count: {torch.cuda.device_count()}")
|
| 223 |
logger.info(f"Current GPU: {torch.cuda.get_device_name(0)}")
|
| 224 |
logger.info(f"GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.1f} GB")
|
|
|
|
| 225 |
else:
|
| 226 |
-
logger.info("CUDA not available, using CPU
|
| 227 |
|
| 228 |
# Initialize agent first
|
| 229 |
num_actions = cfg.env.num_actions
|
|
|
|
| 3 |
Uses FastAPI + WebSocket for real-time keyboard input and game streaming
|
| 4 |
"""
|
| 5 |
|
| 6 |
+
# Fix environment variables FIRST, before any other imports
|
| 7 |
+
import os
|
| 8 |
+
import tempfile
|
| 9 |
+
|
| 10 |
+
# Fix OMP_NUM_THREADS immediately (before PyTorch/NumPy imports)
|
| 11 |
+
if "OMP_NUM_THREADS" not in os.environ or not os.environ.get("OMP_NUM_THREADS", "").isdigit():
|
| 12 |
+
os.environ["OMP_NUM_THREADS"] = "2"
|
| 13 |
+
|
| 14 |
+
# Set up cache directories immediately
|
| 15 |
+
temp_dir = tempfile.gettempdir()
|
| 16 |
+
os.environ.setdefault("TORCH_HOME", os.path.join(temp_dir, "torch"))
|
| 17 |
+
os.environ.setdefault("HF_HOME", os.path.join(temp_dir, "huggingface"))
|
| 18 |
+
os.environ.setdefault("TRANSFORMERS_CACHE", os.path.join(temp_dir, "transformers"))
|
| 19 |
+
|
| 20 |
+
# Create cache directories
|
| 21 |
+
for cache_var in ["TORCH_HOME", "HF_HOME", "TRANSFORMERS_CACHE"]:
|
| 22 |
+
cache_path = os.environ[cache_var]
|
| 23 |
+
os.makedirs(cache_path, exist_ok=True)
|
| 24 |
+
|
| 25 |
import asyncio
|
| 26 |
import base64
|
| 27 |
import io
|
| 28 |
import json
|
| 29 |
import logging
|
|
|
|
|
|
|
| 30 |
from pathlib import Path
|
| 31 |
from typing import Dict, List, Optional, Set
|
| 32 |
|
|
|
|
| 70 |
os.environ.setdefault("SDL_AUDIODRIVER", "dummy")
|
| 71 |
os.environ.setdefault("PYGAME_HIDE_SUPPORT_PROMPT", "1")
|
| 72 |
|
| 73 |
+
# Environment variables already set at top of file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
connected_clients: Set[WebSocket] = set()
|
| 75 |
|
| 76 |
class WebKeyMap:
|
|
|
|
| 216 |
cfg.agent = OmegaConf.load(config_path / "agent" / "csgo.yaml")
|
| 217 |
cfg.env = OmegaConf.load(config_path / "env" / "csgo.yaml")
|
| 218 |
|
| 219 |
+
# Use GPU if available, otherwise fall back to CPU
|
| 220 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 221 |
logger.info(f"Using device: {device}")
|
| 222 |
|
| 223 |
+
# Log GPU availability and CUDA info for debugging
|
| 224 |
if torch.cuda.is_available():
|
| 225 |
logger.info(f"CUDA available: {torch.cuda.is_available()}")
|
| 226 |
logger.info(f"GPU device count: {torch.cuda.device_count()}")
|
| 227 |
logger.info(f"Current GPU: {torch.cuda.get_device_name(0)}")
|
| 228 |
logger.info(f"GPU memory: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.1f} GB")
|
| 229 |
+
logger.info("🚀 GPU acceleration enabled!")
|
| 230 |
else:
|
| 231 |
+
logger.info("CUDA not available, using CPU mode")
|
| 232 |
|
| 233 |
# Initialize agent first
|
| 234 |
num_actions = cfg.env.num_actions
|