Spaces:
Sleeping
Sleeping
jordigonzm
commited on
Commit
•
8d4d3e5
1
Parent(s):
a0031b9
check installation files
Browse files- system/proxy.py +70 -0
- system/pycuda_check.py +14 -0
- system/pynvml_check.py +19 -0
- system/tensorflow_check.py +9 -0
- system/torch_check.py +9 -0
system/proxy.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from http.server import BaseHTTPRequestHandler, HTTPServer
|
2 |
+
import http.client
|
3 |
+
import socket
|
4 |
+
|
5 |
+
# Configuración del servidor backend
|
6 |
+
BACKEND_HOST = "localhost"
|
7 |
+
BACKEND_PORT = 8080
|
8 |
+
|
9 |
+
class TransparentProxy(BaseHTTPRequestHandler):
|
10 |
+
def do_GET(self):
|
11 |
+
self.proxy_request()
|
12 |
+
|
13 |
+
def do_POST(self):
|
14 |
+
self.proxy_request()
|
15 |
+
|
16 |
+
def proxy_request(self):
|
17 |
+
# Modifica la ruta para añadir /v1
|
18 |
+
modified_path = f"/v1{self.path}"
|
19 |
+
print(f"Redirigiendo la solicitud {self.command} a: {modified_path}")
|
20 |
+
|
21 |
+
# Establece una conexión al backend con un timeout extendido
|
22 |
+
conn = http.client.HTTPConnection(BACKEND_HOST, BACKEND_PORT, timeout=300) # Timeout de 5 minutos
|
23 |
+
|
24 |
+
try:
|
25 |
+
# Leer datos del cuerpo si existen
|
26 |
+
content_length = self.headers.get('Content-Length')
|
27 |
+
if content_length:
|
28 |
+
post_data = self.rfile.read(int(content_length))
|
29 |
+
conn.request(self.command, modified_path, body=post_data, headers=self.headers)
|
30 |
+
else:
|
31 |
+
conn.request(self.command, modified_path, headers=self.headers)
|
32 |
+
|
33 |
+
# Obtener la respuesta del backend
|
34 |
+
backend_response = conn.getresponse()
|
35 |
+
|
36 |
+
# Enviar la respuesta al cliente
|
37 |
+
self.send_response(backend_response.status, backend_response.reason)
|
38 |
+
|
39 |
+
# Reenviar todos los encabezados del backend al cliente
|
40 |
+
for key, value in backend_response.getheaders():
|
41 |
+
self.send_header(key, value)
|
42 |
+
self.end_headers()
|
43 |
+
|
44 |
+
# Reenviar el cuerpo de la respuesta en modo streaming
|
45 |
+
while True:
|
46 |
+
chunk = backend_response.read(1024)
|
47 |
+
if not chunk:
|
48 |
+
break
|
49 |
+
self.wfile.write(chunk)
|
50 |
+
self.wfile.flush() # Asegura que cada fragmento se envía inmediatamente al cliente
|
51 |
+
|
52 |
+
except socket.timeout:
|
53 |
+
self.send_error(504, "Gateway Timeout: El backend no respondió en el tiempo esperado.")
|
54 |
+
print("Error: Tiempo de espera agotado en la solicitud al backend.")
|
55 |
+
|
56 |
+
except Exception as e:
|
57 |
+
self.send_error(500, f"Error en el proxy: {e}")
|
58 |
+
print(f"Error al manejar la solicitud: {e}")
|
59 |
+
|
60 |
+
finally:
|
61 |
+
conn.close()
|
62 |
+
|
63 |
+
def run(server_class=HTTPServer, handler_class=TransparentProxy, port=7860):
|
64 |
+
server_address = ('', port)
|
65 |
+
httpd = server_class(server_address, handler_class)
|
66 |
+
print(f"Proxy corriendo en el puerto {port}")
|
67 |
+
httpd.serve_forever()
|
68 |
+
|
69 |
+
if __name__ == "__main__":
|
70 |
+
run()
|
system/pycuda_check.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pycuda.driver as cuda
|
2 |
+
import pycuda.autoinit
|
3 |
+
|
4 |
+
try:
|
5 |
+
cuda.init()
|
6 |
+
print(f"Detected {cuda.Device.count()} CUDA device(s).")
|
7 |
+
|
8 |
+
for i in range(cuda.Device.count()):
|
9 |
+
gpu = cuda.Device(i)
|
10 |
+
print(f"Device {i}: {gpu.name()}")
|
11 |
+
print(f" Compute Capability: {gpu.compute_capability()}")
|
12 |
+
print(f" Total Memory: {gpu.total_memory() // (1024 ** 2)} MB")
|
13 |
+
except cuda.Error as e:
|
14 |
+
print(f"CUDA initialization failed: {e}")
|
system/pynvml_check.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pynvml
|
2 |
+
|
3 |
+
try:
|
4 |
+
pynvml.nvmlInit()
|
5 |
+
device_count = pynvml.nvmlDeviceGetCount()
|
6 |
+
print(f"Number of GPUs: {device_count}")
|
7 |
+
|
8 |
+
for i in range(device_count):
|
9 |
+
handle = pynvml.nvmlDeviceGetHandleByIndex(i)
|
10 |
+
name = pynvml.nvmlDeviceGetName(handle)
|
11 |
+
memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
|
12 |
+
print(f"GPU {i}: {name.decode('utf-8')}")
|
13 |
+
print(f" Memory Total: {memory_info.total / (1024 ** 2)} MB")
|
14 |
+
print(f" Memory Free: {memory_info.free / (1024 ** 2)} MB")
|
15 |
+
print(f" Memory Used: {memory_info.used / (1024 ** 2)} MB")
|
16 |
+
|
17 |
+
pynvml.nvmlShutdown()
|
18 |
+
except pynvml.NVMLError as e:
|
19 |
+
print(f"Failed to initialize NVML: {e}")
|
system/tensorflow_check.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
|
3 |
+
gpus = tf.config.list_physical_devices('GPU')
|
4 |
+
if gpus:
|
5 |
+
print(f"Detected {len(gpus)} GPU(s):")
|
6 |
+
for gpu in gpus:
|
7 |
+
print(f" - {gpu.name}")
|
8 |
+
else:
|
9 |
+
print("No GPUs detected by TensorFlow. Check your configuration.")
|
system/torch_check.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
|
3 |
+
if torch.cuda.is_available():
|
4 |
+
print("CUDA is available.")
|
5 |
+
print(f"GPU Name: {torch.cuda.get_device_name(0)}")
|
6 |
+
print(f"CUDA Version: {torch.version.cuda}")
|
7 |
+
print(f"cuDNN Version: {torch.backends.cudnn.version()}")
|
8 |
+
else:
|
9 |
+
print("CUDA is not available. Check your driver and CUDA installation.")
|