Mahynlo
commited on
Commit
·
c3c998f
1
Parent(s):
ea26a06
Switch to Zephyr 7B (no gating required)
Browse files- config.py +4 -4
- model_llama_local.py +17 -5
config.py
CHANGED
|
@@ -11,16 +11,16 @@ Cambia aquí para elegir entre modelo local o API externa.
|
|
| 11 |
USE_LOCAL_MODEL = True # 🟢 Cambiar a True para usar modelo local
|
| 12 |
|
| 13 |
LOCAL_MODEL_CONFIG = {
|
| 14 |
-
"model_id": "
|
| 15 |
"load_in_8bit": True, # True = ~7GB RAM, False = ~14GB RAM
|
| 16 |
"max_new_tokens": 256,
|
| 17 |
"temperature": 0.0, # 0.0 = determinístico
|
| 18 |
}
|
| 19 |
|
| 20 |
# Alternativas para modelo local (16GB RAM disponibles):
|
| 21 |
-
# - "
|
| 22 |
-
# - "meta-llama/Llama-2-
|
| 23 |
-
# - "
|
| 24 |
|
| 25 |
|
| 26 |
# Opción 2: MODELO VIA API (Gemini u otros via LiteLLM)
|
|
|
|
| 11 |
USE_LOCAL_MODEL = True # 🟢 Cambiar a True para usar modelo local
|
| 12 |
|
| 13 |
LOCAL_MODEL_CONFIG = {
|
| 14 |
+
"model_id": "HuggingFaceH4/zephyr-7b-beta", # Zephyr (no requiere aprobación)
|
| 15 |
"load_in_8bit": True, # True = ~7GB RAM, False = ~14GB RAM
|
| 16 |
"max_new_tokens": 256,
|
| 17 |
"temperature": 0.0, # 0.0 = determinístico
|
| 18 |
}
|
| 19 |
|
| 20 |
# Alternativas para modelo local (16GB RAM disponibles):
|
| 21 |
+
# - "HuggingFaceH4/zephyr-7b-beta" (7B, ~7GB en 8-bit) ✅ ACTIVO - Sin aprobación
|
| 22 |
+
# - "meta-llama/Llama-2-7b-chat-hf" (7B, ~7GB en 8-bit) ⚠️ Requiere aprobación
|
| 23 |
+
# - "meta-llama/Llama-2-13b-chat-hf" (13B, ~13GB en 8-bit) ⚠️ Requiere aprobación
|
| 24 |
|
| 25 |
|
| 26 |
# Opción 2: MODELO VIA API (Gemini u otros via LiteLLM)
|
model_llama_local.py
CHANGED
|
@@ -144,8 +144,11 @@ class LocalHFModel:
|
|
| 144 |
|
| 145 |
def _format_llama_prompt(self, messages: List[Dict[str, str]]) -> str:
|
| 146 |
"""
|
| 147 |
-
Formatea mensajes al formato
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
| 149 |
"""
|
| 150 |
system_msg = ""
|
| 151 |
user_msg = ""
|
|
@@ -159,10 +162,19 @@ class LocalHFModel:
|
|
| 159 |
elif role == "user":
|
| 160 |
user_msg = content
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
else:
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
return prompt
|
| 168 |
|
|
|
|
| 144 |
|
| 145 |
def _format_llama_prompt(self, messages: List[Dict[str, str]]) -> str:
|
| 146 |
"""
|
| 147 |
+
Formatea mensajes al formato correcto según el modelo.
|
| 148 |
+
|
| 149 |
+
Soporta:
|
| 150 |
+
- Llama 2: <s>[INST] <<SYS>>...
|
| 151 |
+
- Zephyr: <|system|>...<|user|>...<|assistant|>
|
| 152 |
"""
|
| 153 |
system_msg = ""
|
| 154 |
user_msg = ""
|
|
|
|
| 162 |
elif role == "user":
|
| 163 |
user_msg = content
|
| 164 |
|
| 165 |
+
# Detectar formato según model_id
|
| 166 |
+
if "zephyr" in self.model_id.lower():
|
| 167 |
+
# Formato Zephyr
|
| 168 |
+
if system_msg:
|
| 169 |
+
prompt = f"<|system|>\n{system_msg}</s>\n<|user|>\n{user_msg}</s>\n<|assistant|>\n"
|
| 170 |
+
else:
|
| 171 |
+
prompt = f"<|user|>\n{user_msg}</s>\n<|assistant|>\n"
|
| 172 |
else:
|
| 173 |
+
# Formato Llama 2 (default)
|
| 174 |
+
if system_msg:
|
| 175 |
+
prompt = f"<s>[INST] <<SYS>>\n{system_msg}\n<</SYS>>\n\n{user_msg} [/INST]"
|
| 176 |
+
else:
|
| 177 |
+
prompt = f"<s>[INST] {user_msg} [/INST]"
|
| 178 |
|
| 179 |
return prompt
|
| 180 |
|