Sourav122005 commited on
Commit
a43aa25
·
verified ·
1 Parent(s): 3087da9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -6
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=4096, # Shifting context window to 4K slashes active memory requirements in half
30
- n_batch=32, # Drop processing batches from 512 to 32 to eliminate peak memory spikes
31
- n_threads=2 # Explicitly bounds CPU thread contention blocks
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():