Spaces:
Runtime error
Runtime error
Unlimited output (max_tokens=-1); raise default N_CTX to 32768
Browse files
README.md
CHANGED
|
@@ -22,7 +22,8 @@ On startup it:
|
|
| 22 |
|
| 23 |
- **Tiny + fast:** 0.8B on CPU-basic is quick; great for low-latency chat.
|
| 24 |
- **Chain-of-thought:** `<think>` shown in the collapsible panel; the answer stays clean.
|
| 25 |
-
- **Context:**
|
|
|
|
| 26 |
|
| 27 |
Tunable via Space variables (no rebuild): `MODEL_REPO`, `GGUF_FILE` (e.g. `...Q5_K_M.gguf`,
|
| 28 |
`...Q8_0.gguf`), `N_CTX`, `MAX_TOKENS`, `NUM_THREADS`, `SYSTEM_PROMPT`, `LLAMA_EXTRA_ARGS`.
|
|
|
|
| 22 |
|
| 23 |
- **Tiny + fast:** 0.8B on CPU-basic is quick; great for low-latency chat.
|
| 24 |
- **Chain-of-thought:** `<think>` shown in the collapsible panel; the answer stays clean.
|
| 25 |
+
- **Context:** 32,768 tokens by default (model native up to **262,144** — raise `N_CTX`, slower on CPU).
|
| 26 |
+
- **Output length:** unlimited by default (`MAX_TOKENS=-1`) — generates until done or context is full.
|
| 27 |
|
| 28 |
Tunable via Space variables (no rebuild): `MODEL_REPO`, `GGUF_FILE` (e.g. `...Q5_K_M.gguf`,
|
| 29 |
`...Q8_0.gguf`), `N_CTX`, `MAX_TOKENS`, `NUM_THREADS`, `SYSTEM_PROMPT`, `LLAMA_EXTRA_ARGS`.
|
app.py
CHANGED
|
@@ -22,9 +22,10 @@ BIN = "/opt/llamabin"
|
|
| 22 |
# ALWAYS opens a <think> block; this lets "Fast (no thinking)" actually skip reasoning).
|
| 23 |
CHAT_TEMPLATE_FILE = os.environ.get("CHAT_TEMPLATE_FILE", "/home/user/app/chat_template.jinja")
|
| 24 |
LLAMA = f"http://127.0.0.1:{LLAMA_PORT}"
|
| 25 |
-
# Qwen3.5-0.8B native context = 262144.
|
| 26 |
-
#
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def _env():
|
|
@@ -88,8 +89,9 @@ app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_credentials=False,
|
|
| 88 |
allow_methods=["*"], allow_headers=["*"])
|
| 89 |
|
| 90 |
# Sensible defaults (only applied when the caller doesn't set them). Overridable per request.
|
|
|
|
| 91 |
DEFAULTS = {"temperature": 0.3, "top_p": 0.9, "top_k": 20, "repeat_penalty": 1.05,
|
| 92 |
-
"max_tokens": int(os.environ.get("MAX_TOKENS", "
|
| 93 |
|
| 94 |
|
| 95 |
@app.get("/health")
|
|
|
|
| 22 |
# ALWAYS opens a <think> block; this lets "Fast (no thinking)" actually skip reasoning).
|
| 23 |
CHAT_TEMPLATE_FILE = os.environ.get("CHAT_TEMPLATE_FILE", "/home/user/app/chat_template.jinja")
|
| 24 |
LLAMA = f"http://127.0.0.1:{LLAMA_PORT}"
|
| 25 |
+
# Qwen3.5-0.8B native context = 262144. We default to a generous 32768 window (good for
|
| 26 |
+
# large files / long chats) while keeping startup + memory reasonable on CPU; raise N_CTX up
|
| 27 |
+
# to 262144 via a Space variable if you really need it (much slower prefill on CPU).
|
| 28 |
+
N_CTX = os.environ.get("N_CTX", "32768")
|
| 29 |
|
| 30 |
|
| 31 |
def _env():
|
|
|
|
| 89 |
allow_methods=["*"], allow_headers=["*"])
|
| 90 |
|
| 91 |
# Sensible defaults (only applied when the caller doesn't set them). Overridable per request.
|
| 92 |
+
# max_tokens = -1 -> UNLIMITED output (generate until EOS or the context window is full).
|
| 93 |
DEFAULTS = {"temperature": 0.3, "top_p": 0.9, "top_k": 20, "repeat_penalty": 1.05,
|
| 94 |
+
"max_tokens": int(os.environ.get("MAX_TOKENS", "-1"))}
|
| 95 |
|
| 96 |
|
| 97 |
@app.get("/health")
|