space: duration=120 for cold start + /api/status fast-path (causal_conv1d) probe
Browse files- space/app.py +29 -2
space/app.py
CHANGED
|
@@ -200,8 +200,11 @@ def _generate(messages, max_tokens, temperature, enable_thinking):
|
|
| 200 |
|
| 201 |
|
| 202 |
if spaces is not None:
|
| 203 |
-
#
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
|
| 207 |
# ----------------------------------------------------------------- the surface
|
|
@@ -224,6 +227,29 @@ WHISPERS = [
|
|
| 224 |
app = FastAPI()
|
| 225 |
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
@app.get("/api/status")
|
| 228 |
def status() -> dict:
|
| 229 |
"""Operational truth, no secrets: is the on-Space Warden actually loaded?"""
|
|
@@ -231,6 +257,7 @@ def status() -> dict:
|
|
| 231 |
"warden_ready": WARDEN_READY,
|
| 232 |
"warden_error": WARDEN_ERR,
|
| 233 |
"mamba": MAMBA_DIAG,
|
|
|
|
| 234 |
"model": MODEL_ID + (f"/{SUBFOLDER}" if SUBFOLDER else ""),
|
| 235 |
"zerogpu": spaces is not None,
|
| 236 |
}
|
|
|
|
| 200 |
|
| 201 |
|
| 202 |
if spaces is not None:
|
| 203 |
+
# The first call also forks the GPU worker and materializes the ~18GB
|
| 204 |
+
# model onto the real device (CUDA is emulated until then), which can eat
|
| 205 |
+
# a minute; steady-state generation of one line is seconds. Give cold
|
| 206 |
+
# start headroom — the slice is only held for the actual call.
|
| 207 |
+
_generate = spaces.GPU(duration=120)(_generate)
|
| 208 |
|
| 209 |
|
| 210 |
# ----------------------------------------------------------------- the surface
|
|
|
|
| 227 |
app = FastAPI()
|
| 228 |
|
| 229 |
|
| 230 |
+
def _fast_path_report() -> str:
|
| 231 |
+
"""Whether Nemotron-H's mamba CUDA fast path can engage. The slow naive
|
| 232 |
+
fallback is ~1 tok/s; the fast path needs BOTH mamba_ssm AND causal_conv1d
|
| 233 |
+
kernels present."""
|
| 234 |
+
try:
|
| 235 |
+
import importlib
|
| 236 |
+
|
| 237 |
+
bits = {}
|
| 238 |
+
try:
|
| 239 |
+
m = importlib.import_module("mamba_ssm.ops.triton.ssd_combined")
|
| 240 |
+
bits["mamba_chunk_scan_combined"] = m.mamba_chunk_scan_combined is not None
|
| 241 |
+
except Exception as e:
|
| 242 |
+
bits["mamba_ssm"] = f"FAIL {e}"
|
| 243 |
+
try:
|
| 244 |
+
c = importlib.import_module("causal_conv1d")
|
| 245 |
+
bits["causal_conv1d_fn"] = getattr(c, "causal_conv1d_fn", None) is not None
|
| 246 |
+
except Exception as e:
|
| 247 |
+
bits["causal_conv1d"] = f"FAIL {e}"
|
| 248 |
+
return str(bits)
|
| 249 |
+
except Exception as e:
|
| 250 |
+
return f"probe failed: {e}"
|
| 251 |
+
|
| 252 |
+
|
| 253 |
@app.get("/api/status")
|
| 254 |
def status() -> dict:
|
| 255 |
"""Operational truth, no secrets: is the on-Space Warden actually loaded?"""
|
|
|
|
| 257 |
"warden_ready": WARDEN_READY,
|
| 258 |
"warden_error": WARDEN_ERR,
|
| 259 |
"mamba": MAMBA_DIAG,
|
| 260 |
+
"fast_path": _fast_path_report(),
|
| 261 |
"model": MODEL_ID + (f"/{SUBFOLDER}" if SUBFOLDER else ""),
|
| 262 |
"zerogpu": spaces is not None,
|
| 263 |
}
|