Spaces:
Paused
Paused
fix: cap torch threads al vCPU del container, no al host fisico
Browse files
modules/transcription/trocr_model.py
CHANGED
|
@@ -51,7 +51,9 @@ def _load():
|
|
| 51 |
)
|
| 52 |
# Threads de CPU: usa todos los cores físicos.
|
| 53 |
try:
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
except Exception:
|
| 56 |
pass
|
| 57 |
print(f"[TrOCR] Cuantizado. Threads CPU = {torch.get_num_threads()}")
|
|
|
|
| 51 |
)
|
| 52 |
# Threads de CPU: usa todos los cores físicos.
|
| 53 |
try:
|
| 54 |
+
# os.cpu_count() en contenedores devuelve el total del host, no los vCPUs asignados
|
| 55 |
+
container_cpus = int(os.getenv("TROCR_NUM_THREADS", "0")) or min(os.cpu_count() or 4, 8)
|
| 56 |
+
torch.set_num_threads(max(1, container_cpus - 1))
|
| 57 |
except Exception:
|
| 58 |
pass
|
| 59 |
print(f"[TrOCR] Cuantizado. Threads CPU = {torch.get_num_threads()}")
|