Leon4gr45 commited on
Commit
911ccc5
·
verified ·
1 Parent(s): eb5a9f7

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
@@ -57,8 +57,12 @@ def _effective_cpus():
57
 
58
 
59
  _CPU = _effective_cpus()
60
- CPU_THREADS = int(os.getenv("CPU_THREADS", str(_CPU)))
61
- CPU_THREADS_BATCH = int(os.getenv("CPU_THREADS_BATCH", str(_CPU)))
 
 
 
 
62
  CONTEXT_SIZE = int(os.getenv("CONTEXT_SIZE", "8192")) # incl. image tokens; per-slot = ctx/parallel
63
  PARALLEL = int(os.getenv("PARALLEL", "2"))
64
  BATCH_SIZE = int(os.getenv("BATCH_SIZE", "512"))
 
57
 
58
 
59
  _CPU = _effective_cpus()
60
+ # Hard ceiling on threads: even if detection over-reports (e.g. host cores leak
61
+ # through), never oversubscribe the ~2-vCPU tier. Raise CPU_THREADS_MAX if you
62
+ # move to a bigger CPU tier.
63
+ CPU_THREADS_MAX = int(os.getenv("CPU_THREADS_MAX", "2"))
64
+ CPU_THREADS = min(int(os.getenv("CPU_THREADS", str(_CPU))), CPU_THREADS_MAX)
65
+ CPU_THREADS_BATCH = min(int(os.getenv("CPU_THREADS_BATCH", str(_CPU))), CPU_THREADS_MAX)
66
  CONTEXT_SIZE = int(os.getenv("CONTEXT_SIZE", "8192")) # incl. image tokens; per-slot = ctx/parallel
67
  PARALLEL = int(os.getenv("PARALLEL", "2"))
68
  BATCH_SIZE = int(os.getenv("BATCH_SIZE", "512"))