Update app.py
Browse files
app.py
CHANGED
|
@@ -162,15 +162,14 @@ def _load_embed_and_rerank_on_gpu():
|
|
| 162 |
def _load_generation_model_on_gpu():
|
| 163 |
"""
|
| 164 |
Try Nemotron 30B FP8 first.
|
| 165 |
-
If it fails
|
| 166 |
"""
|
| 167 |
global _gen_model, _gen_tokenizer
|
| 168 |
-
|
| 169 |
if _gen_model is not None and _gen_tokenizer is not None:
|
| 170 |
return _gen_model, _gen_tokenizer
|
| 171 |
|
| 172 |
device = _cuda()
|
| 173 |
-
|
| 174 |
# 1) Try Nemotron FP8
|
| 175 |
try:
|
| 176 |
print("[INFO] Lazy-loading GENERATION model (Nemotron 30B FP8) on GPU...")
|
|
@@ -179,33 +178,41 @@ def _load_generation_model_on_gpu():
|
|
| 179 |
trust_remote_code=True,
|
| 180 |
use_fast=True,
|
| 181 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
_gen_model = AutoModelForCausalLM.from_pretrained(
|
| 183 |
GENERATION_MODEL_ID,
|
| 184 |
trust_remote_code=True,
|
| 185 |
torch_dtype="auto",
|
| 186 |
device_map="auto",
|
| 187 |
-
attn_implementation=
|
| 188 |
).eval()
|
| 189 |
-
|
|
|
|
| 190 |
return _gen_model, _gen_tokenizer
|
| 191 |
|
| 192 |
except Exception as e:
|
| 193 |
print(f"[WARN] Nemotron FP8 load failed: {repr(e)}")
|
| 194 |
print(f"[WARN] Falling back to: {FALLBACK_GEN_MODEL_ID}")
|
| 195 |
-
|
| 196 |
_gen_tokenizer = AutoTokenizer.from_pretrained(
|
| 197 |
FALLBACK_GEN_MODEL_ID,
|
| 198 |
trust_remote_code=True,
|
| 199 |
use_fast=True,
|
| 200 |
)
|
|
|
|
| 201 |
_gen_model = AutoModelForCausalLM.from_pretrained(
|
| 202 |
FALLBACK_GEN_MODEL_ID,
|
| 203 |
trust_remote_code=True,
|
| 204 |
torch_dtype=torch.bfloat16,
|
| 205 |
device_map="auto",
|
| 206 |
-
attn_implementation=
|
| 207 |
).eval()
|
| 208 |
-
|
| 209 |
return _gen_model, _gen_tokenizer
|
| 210 |
|
| 211 |
|
|
|
|
| 162 |
def _load_generation_model_on_gpu():
|
| 163 |
"""
|
| 164 |
Try Nemotron 30B FP8 first.
|
| 165 |
+
If it fails, fall back to a smaller text model.
|
| 166 |
"""
|
| 167 |
global _gen_model, _gen_tokenizer
|
|
|
|
| 168 |
if _gen_model is not None and _gen_tokenizer is not None:
|
| 169 |
return _gen_model, _gen_tokenizer
|
| 170 |
|
| 171 |
device = _cuda()
|
| 172 |
+
|
| 173 |
# 1) Try Nemotron FP8
|
| 174 |
try:
|
| 175 |
print("[INFO] Lazy-loading GENERATION model (Nemotron 30B FP8) on GPU...")
|
|
|
|
| 178 |
trust_remote_code=True,
|
| 179 |
use_fast=True,
|
| 180 |
)
|
| 181 |
+
|
| 182 |
+
# FIX: We force 'eager' or 'flash_attention_2' because this model
|
| 183 |
+
# doesn't support the default 'sdpa' implementation yet.
|
| 184 |
+
# Since you installed the FA2 wheels, we'll try to use that first.
|
| 185 |
+
gen_attn_impl = ATTN_IMPL if ATTN_IMPL == "flash_attention_2" else "eager"
|
| 186 |
+
|
| 187 |
_gen_model = AutoModelForCausalLM.from_pretrained(
|
| 188 |
GENERATION_MODEL_ID,
|
| 189 |
trust_remote_code=True,
|
| 190 |
torch_dtype="auto",
|
| 191 |
device_map="auto",
|
| 192 |
+
attn_implementation=gen_attn_impl, # Changed here
|
| 193 |
).eval()
|
| 194 |
+
|
| 195 |
+
print(f"[INFO] Nemotron generation model loaded OK with {gen_attn_impl}")
|
| 196 |
return _gen_model, _gen_tokenizer
|
| 197 |
|
| 198 |
except Exception as e:
|
| 199 |
print(f"[WARN] Nemotron FP8 load failed: {repr(e)}")
|
| 200 |
print(f"[WARN] Falling back to: {FALLBACK_GEN_MODEL_ID}")
|
| 201 |
+
|
| 202 |
_gen_tokenizer = AutoTokenizer.from_pretrained(
|
| 203 |
FALLBACK_GEN_MODEL_ID,
|
| 204 |
trust_remote_code=True,
|
| 205 |
use_fast=True,
|
| 206 |
)
|
| 207 |
+
|
| 208 |
_gen_model = AutoModelForCausalLM.from_pretrained(
|
| 209 |
FALLBACK_GEN_MODEL_ID,
|
| 210 |
trust_remote_code=True,
|
| 211 |
torch_dtype=torch.bfloat16,
|
| 212 |
device_map="auto",
|
| 213 |
+
attn_implementation="sdpa", # Fallback model usually supports SDPA
|
| 214 |
).eval()
|
| 215 |
+
|
| 216 |
return _gen_model, _gen_tokenizer
|
| 217 |
|
| 218 |
|