Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,12 +23,11 @@ model_path = hf_hub_download(
|
|
| 23 |
)
|
| 24 |
|
| 25 |
print("Initializing memory-optimized llama.cpp execution runtime...")
|
| 26 |
-
# Hardened configurations specifically tuned to avoid OOM crashes on free shared CPU tiers
|
| 27 |
llm = Llama(
|
| 28 |
model_path=model_path,
|
| 29 |
-
n_ctx=
|
| 30 |
-
n_batch=32, #
|
| 31 |
-
n_threads=2
|
| 32 |
)
|
| 33 |
|
| 34 |
@app.get("/")
|
|
@@ -39,13 +38,12 @@ def read_root():
|
|
| 39 |
async def chat_completions(request: Request):
|
| 40 |
body = await request.json()
|
| 41 |
messages = body.get("messages", [])
|
| 42 |
-
|
| 43 |
response = llm.create_chat_completion(
|
| 44 |
messages=messages,
|
| 45 |
temperature=0.3,
|
| 46 |
top_p=0.95,
|
| 47 |
stream=True,
|
| 48 |
-
max_tokens=1536
|
| 49 |
)
|
| 50 |
|
| 51 |
def stream_generator():
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
print("Initializing memory-optimized llama.cpp execution runtime...")
|
|
|
|
| 26 |
llm = Llama(
|
| 27 |
model_path=model_path,
|
| 28 |
+
n_ctx=6144, # Expanded context window from 4096 to 6144 for longer historical tracks
|
| 29 |
+
n_batch=32, # Kept at 32 to guarantee flat peak memory profiles
|
| 30 |
+
n_threads=2
|
| 31 |
)
|
| 32 |
|
| 33 |
@app.get("/")
|
|
|
|
| 38 |
async def chat_completions(request: Request):
|
| 39 |
body = await request.json()
|
| 40 |
messages = body.get("messages", [])
|
|
|
|
| 41 |
response = llm.create_chat_completion(
|
| 42 |
messages=messages,
|
| 43 |
temperature=0.3,
|
| 44 |
top_p=0.95,
|
| 45 |
stream=True,
|
| 46 |
+
max_tokens=3072 # Doubled token headroom from 1536 to 3072
|
| 47 |
)
|
| 48 |
|
| 49 |
def stream_generator():
|