Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,25 @@ import os
|
|
| 3 |
# Must be set before torch's OpenMP/MKL thread pools initialize on first use.
|
| 4 |
# This is the most reliable way to make sure BLAS/OpenMP actually uses all
|
| 5 |
# cores instead of a conservative default.
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
os.environ.setdefault("OMP_NUM_THREADS", _CPU_THREADS)
|
| 8 |
os.environ.setdefault("MKL_NUM_THREADS", _CPU_THREADS)
|
| 9 |
|
|
@@ -85,8 +103,6 @@ def startup_event():
|
|
| 85 |
else:
|
| 86 |
MODEL = Qwen3TTSModel.from_pretrained(MODEL_NAME, **load_kwargs)
|
| 87 |
|
| 88 |
-
MODEL.eval() # disables dropout etc.; inference-only mode
|
| 89 |
-
|
| 90 |
SUPPORTED_SPEAKERS = MODEL.get_supported_speakers()
|
| 91 |
SUPPORTED_LANGUAGES = MODEL.get_supported_languages()
|
| 92 |
|
|
|
|
| 3 |
# Must be set before torch's OpenMP/MKL thread pools initialize on first use.
|
| 4 |
# This is the most reliable way to make sure BLAS/OpenMP actually uses all
|
| 5 |
# cores instead of a conservative default.
|
| 6 |
+
def _detect_cpu_threads() -> int:
|
| 7 |
+
# Respect a value the platform/container already set -- on cgroup-limited
|
| 8 |
+
# containers (like HF Spaces) this is often the *correct* real quota,
|
| 9 |
+
# whereas os.cpu_count() reports the host machine's full core count and
|
| 10 |
+
# will cause thread oversubscription if trusted blindly.
|
| 11 |
+
for var in ("OMP_NUM_THREADS", "MKL_NUM_THREADS"):
|
| 12 |
+
val = os.environ.get(var)
|
| 13 |
+
if val and val.isdigit() and int(val) > 0:
|
| 14 |
+
return int(val)
|
| 15 |
+
# sched_getaffinity reflects CPU-affinity/cgroup restrictions more
|
| 16 |
+
# accurately than os.cpu_count() on Linux; fall back to cpu_count if
|
| 17 |
+
# unavailable (e.g. non-Linux).
|
| 18 |
+
try:
|
| 19 |
+
return len(os.sched_getaffinity(0))
|
| 20 |
+
except AttributeError:
|
| 21 |
+
return os.cpu_count() or 4
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
_CPU_THREADS = str(_detect_cpu_threads())
|
| 25 |
os.environ.setdefault("OMP_NUM_THREADS", _CPU_THREADS)
|
| 26 |
os.environ.setdefault("MKL_NUM_THREADS", _CPU_THREADS)
|
| 27 |
|
|
|
|
| 103 |
else:
|
| 104 |
MODEL = Qwen3TTSModel.from_pretrained(MODEL_NAME, **load_kwargs)
|
| 105 |
|
|
|
|
|
|
|
| 106 |
SUPPORTED_SPEAKERS = MODEL.get_supported_speakers()
|
| 107 |
SUPPORTED_LANGUAGES = MODEL.get_supported_languages()
|
| 108 |
|