AndresCarreon commited on
Commit
54342fa
·
verified ·
1 Parent(s): a1fdcfe

GPU final: model resident on cuda (no per-call transfer) + 240s budget + one-shot — fixes empty-output timeout

Browse files
Files changed (2) hide show
  1. mind/backends.py +14 -12
  2. 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 = 120
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
- # Model stays on CPU at load. The .to("cuda") happens INSIDE the
371
- # @spaces.GPU function on EVERY call this is exactly what the
372
- # working bench Space does. ZeroGPU detaches the GPU between calls,
373
- # so the model must be (re)homed to cuda within each GPU context;
374
- # caching it (eager load or a one-time _on_cuda flag) leaves stale
375
- # cuda tensors that NVML-crash on the next call (June 12). With
376
- # one-shot generation there's one such call per wish.
 
 
 
 
 
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 — CPU deployment. The god runs in-process on llama.cpp (4B Nemotron
2
- # GGUF). No GPU, no torch reliable, real model, grammar-valid output.
 
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