GPU final: model resident on cuda (no per-call transfer) + 240s budget + one-shot — fixes empty-output timeout
Browse files- mind/backends.py +14 -12
- requirements.txt +8 -2
mind/backends.py
CHANGED
|
@@ -327,7 +327,7 @@ class ZeroGPUBackend:
|
|
| 327 |
# kernels, which cannot import on the ZeroGPU image (no compatible CUDA libs
|
| 328 |
# at startup — June 12). 4B GGUF remains the llama.cpp local mode.
|
| 329 |
DEFAULT_MODEL = "nvidia/NVIDIA-Nemotron-Nano-9B-v2"
|
| 330 |
-
GPU_DURATION_S =
|
| 331 |
|
| 332 |
def __init__(self, model_id: str | None = None, max_input_tokens: int = 4096):
|
| 333 |
self.model_id = model_id or os.environ.get(
|
|
@@ -367,19 +367,21 @@ class ZeroGPUBackend:
|
|
| 367 |
low_cpu_mem_usage=True,
|
| 368 |
)
|
| 369 |
self._model.eval()
|
| 370 |
-
#
|
| 371 |
-
#
|
| 372 |
-
#
|
| 373 |
-
#
|
| 374 |
-
#
|
| 375 |
-
#
|
| 376 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
|
| 378 |
def _generate(prompt: str, max_new_tokens: int, temperature: float) -> str:
|
| 379 |
-
import torch as _torch
|
| 380 |
-
|
| 381 |
-
if _torch.cuda.is_available():
|
| 382 |
-
self._model.to("cuda")
|
| 383 |
|
| 384 |
# Nemotron-Nano-9B-v2 is a reasoning model that THINKS by
|
| 385 |
# default; "/no_think" in the system slot disables it (June 12
|
|
|
|
| 327 |
# kernels, which cannot import on the ZeroGPU image (no compatible CUDA libs
|
| 328 |
# at startup — June 12). 4B GGUF remains the llama.cpp local mode.
|
| 329 |
DEFAULT_MODEL = "nvidia/NVIDIA-Nemotron-Nano-9B-v2"
|
| 330 |
+
GPU_DURATION_S = 240
|
| 331 |
|
| 332 |
def __init__(self, model_id: str | None = None, max_input_tokens: int = 4096):
|
| 333 |
self.model_id = model_id or os.environ.get(
|
|
|
|
| 367 |
low_cpu_mem_usage=True,
|
| 368 |
)
|
| 369 |
self._model.eval()
|
| 370 |
+
# Move to cuda ONCE at load, guarded by `import spaces` (the lib
|
| 371 |
+
# virtualizes it and keeps the model resident across @spaces.GPU
|
| 372 |
+
# calls). With ONE-SHOT generation a wish is a single GPU call, so
|
| 373 |
+
# the multi-call NVML crash can't happen — and keeping the model
|
| 374 |
+
# resident avoids the ~67s CPU→GPU transfer that, done per-call, ate
|
| 375 |
+
# the whole GPU time budget and left no time to generate (→ empty
|
| 376 |
+
# output → fallback, June 12). Resident + one call = fast real output.
|
| 377 |
+
try:
|
| 378 |
+
import spaces # noqa: F401
|
| 379 |
+
self._model.to("cuda")
|
| 380 |
+
except ImportError:
|
| 381 |
+
pass # local/CPU dev
|
| 382 |
|
| 383 |
def _generate(prompt: str, max_new_tokens: int, temperature: float) -> str:
|
| 384 |
+
import torch as _torch # noqa: F401
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
# Nemotron-Nano-9B-v2 is a reasoning model that THINKS by
|
| 387 |
# default; "/no_think" in the system slot disables it (June 12
|
requirements.txt
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
-
# GODSEED —
|
| 2 |
-
#
|
|
|
|
| 3 |
fastapi>=0.115
|
| 4 |
uvicorn>=0.30
|
| 5 |
gradio>=5
|
|
@@ -8,3 +9,8 @@ huggingface_hub>=0.30
|
|
| 8 |
|
| 9 |
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
| 10 |
llama-cpp-python>=0.3.8
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GODSEED — live backend = zerogpu (NVIDIA Nemotron-Nano-9B-v2 on ZeroGPU,
|
| 2 |
+
# one-shot generation = one @spaces.GPU call per wish). llama-cpp stays as the
|
| 3 |
+
# documented CPU fallback (Llama Champion badge).
|
| 4 |
fastapi>=0.115
|
| 5 |
uvicorn>=0.30
|
| 6 |
gradio>=5
|
|
|
|
| 9 |
|
| 10 |
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
| 11 |
llama-cpp-python>=0.3.8
|
| 12 |
+
|
| 13 |
+
transformers>=5.4
|
| 14 |
+
accelerate>=0.34.0
|
| 15 |
+
einops
|
| 16 |
+
sentencepiece
|