Leon4gr45 commited on
Commit
111e96a
·
verified ·
1 Parent(s): 1256f93

safety: cap threads at CPU_THREADS_MAX (default 2) to prevent oversubscription if detection over-reports

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -56,8 +56,12 @@ def _effective_cpus():
56
 
57
 
58
  _CPU = _effective_cpus()
59
- CPU_THREADS = int(os.getenv("CPU_THREADS", str(_CPU))) # all cores per instance
60
- CPU_THREADS_BATCH = int(os.getenv("CPU_THREADS_BATCH", str(_CPU)))
 
 
 
 
61
  CONTEXT_SIZE = int(os.getenv("CONTEXT_SIZE", "16384")) # total; per-slot = ctx/parallel
62
  PARALLEL = int(os.getenv("PARALLEL", "2")) # continuous-batching slots
63
  BATCH_SIZE = int(os.getenv("BATCH_SIZE", "512"))
 
56
 
57
 
58
  _CPU = _effective_cpus()
59
+ # Hard ceiling on threads: even if detection over-reports (e.g. host cores leak
60
+ # through), never oversubscribe the ~2-vCPU tier. Raise CPU_THREADS_MAX if you
61
+ # move to a bigger CPU tier.
62
+ CPU_THREADS_MAX = int(os.getenv("CPU_THREADS_MAX", "2"))
63
+ CPU_THREADS = min(int(os.getenv("CPU_THREADS", str(_CPU))), CPU_THREADS_MAX)
64
+ CPU_THREADS_BATCH = min(int(os.getenv("CPU_THREADS_BATCH", str(_CPU))), CPU_THREADS_MAX)
65
  CONTEXT_SIZE = int(os.getenv("CONTEXT_SIZE", "16384")) # total; per-slot = ctx/parallel
66
  PARALLEL = int(os.getenv("PARALLEL", "2")) # continuous-batching slots
67
  BATCH_SIZE = int(os.getenv("BATCH_SIZE", "512"))