Hjgugugjhuhjggg
commited on
Commit
•
c696739
1
Parent(s):
c6ab5e0
Update app.py
Browse files
app.py
CHANGED
@@ -21,10 +21,7 @@ nltk.download('stopwords')
|
|
21 |
|
22 |
app = FastAPI()
|
23 |
|
24 |
-
|
25 |
-
device = torch.device("cuda")
|
26 |
-
else:
|
27 |
-
device = torch.device("cpu")
|
28 |
|
29 |
modelos = {
|
30 |
"gpt2-medium": VLLM(model="gpt2-medium", device=device),
|
@@ -38,8 +35,8 @@ caches = {
|
|
38 |
}
|
39 |
|
40 |
cadenas = {
|
41 |
-
nombre: LLMChain(modelo,
|
42 |
-
for nombre, modelo,
|
43 |
}
|
44 |
|
45 |
summarizer = pipeline("summarization", device=device)
|
@@ -52,6 +49,7 @@ def keep_alive():
|
|
52 |
cadena.ask("¿Cuál es el sentido de la vida?")
|
53 |
except Exception as e:
|
54 |
logging.error(f"Error en modelo {cadena}: {e}")
|
|
|
55 |
time.sleep(300)
|
56 |
|
57 |
def liberar_recursos():
|
@@ -65,7 +63,6 @@ def liberar_recursos():
|
|
65 |
os.kill(proc.info['pid'], 9)
|
66 |
time.sleep(60)
|
67 |
|
68 |
-
# Iniciar hilos en segundo plano
|
69 |
threading.Thread(target=keep_alive, daemon=True).start()
|
70 |
threading.Thread(target=liberar_recursos, daemon=True).start()
|
71 |
|
|
|
21 |
|
22 |
app = FastAPI()
|
23 |
|
24 |
+
device = torch.device("cpu")
|
|
|
|
|
|
|
25 |
|
26 |
modelos = {
|
27 |
"gpt2-medium": VLLM(model="gpt2-medium", device=device),
|
|
|
35 |
}
|
36 |
|
37 |
cadenas = {
|
38 |
+
nombre: LLMChain(modelo, caché)
|
39 |
+
for nombre, modelo, caché in zip(modelos.keys(), modelos.values(), caches.values())
|
40 |
}
|
41 |
|
42 |
summarizer = pipeline("summarization", device=device)
|
|
|
49 |
cadena.ask("¿Cuál es el sentido de la vida?")
|
50 |
except Exception as e:
|
51 |
logging.error(f"Error en modelo {cadena}: {e}")
|
52 |
+
cadenas.pop(cadena)
|
53 |
time.sleep(300)
|
54 |
|
55 |
def liberar_recursos():
|
|
|
63 |
os.kill(proc.info['pid'], 9)
|
64 |
time.sleep(60)
|
65 |
|
|
|
66 |
threading.Thread(target=keep_alive, daemon=True).start()
|
67 |
threading.Thread(target=liberar_recursos, daemon=True).start()
|
68 |
|