Spaces:
Sleeping
Sleeping
Update models.py
Browse files
models.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# models.py
|
2 |
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
@@ -7,12 +7,10 @@ from config import EMBEDDING_MODEL_NAME
|
|
7 |
|
8 |
# Cargar el modelo de embeddings
|
9 |
def load_embedding_model():
|
10 |
-
# Se determina el dispositivo y se convierte a un objeto torch.device.
|
11 |
device_str = 'cuda' if torch.cuda.is_available() else 'cpu'
|
12 |
device = torch.device(device_str)
|
13 |
|
14 |
-
#
|
15 |
-
# Esto fuerza a la librería a cargar 'model.safetensors' en lugar de 'pytorch_model.bin'.
|
16 |
embedding_model = SentenceTransformer(
|
17 |
EMBEDDING_MODEL_NAME,
|
18 |
device=device,
|
@@ -22,7 +20,7 @@ def load_embedding_model():
|
|
22 |
print(f"Embedding model loaded on device: {embedding_model.device}")
|
23 |
return embedding_model
|
24 |
|
25 |
-
# Cargar el modelo Yi-Coder
|
26 |
def load_yi_coder_model():
|
27 |
device_str = 'cuda' if torch.cuda.is_available() else 'cpu'
|
28 |
device = torch.device(device_str)
|
@@ -35,7 +33,6 @@ def load_yi_coder_model():
|
|
35 |
model_path,
|
36 |
torch_dtype=torch.float16,
|
37 |
low_cpu_mem_usage=True,
|
38 |
-
# También es buena práctica añadirlo aquí, aunque no era la causa del error.
|
39 |
use_safetensors=True
|
40 |
).to(device).eval()
|
41 |
|
|
|
1 |
+
# models.py (Este código ahora es CORRECTO con el nuevo requirements.txt)
|
2 |
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
7 |
|
8 |
# Cargar el modelo de embeddings
|
9 |
def load_embedding_model():
|
|
|
10 |
device_str = 'cuda' if torch.cuda.is_available() else 'cpu'
|
11 |
device = torch.device(device_str)
|
12 |
|
13 |
+
# Esta línea ahora funcionará gracias a la actualización en requirements.txt
|
|
|
14 |
embedding_model = SentenceTransformer(
|
15 |
EMBEDDING_MODEL_NAME,
|
16 |
device=device,
|
|
|
20 |
print(f"Embedding model loaded on device: {embedding_model.device}")
|
21 |
return embedding_model
|
22 |
|
23 |
+
# Cargar el modelo Yi-Coder
|
24 |
def load_yi_coder_model():
|
25 |
device_str = 'cuda' if torch.cuda.is_available() else 'cpu'
|
26 |
device = torch.device(device_str)
|
|
|
33 |
model_path,
|
34 |
torch_dtype=torch.float16,
|
35 |
low_cpu_mem_usage=True,
|
|
|
36 |
use_safetensors=True
|
37 |
).to(device).eval()
|
38 |
|