Spaces:
Running
Running
gpu blocker fix: translator.py
Browse files- src/translator.py +15 -9
src/translator.py
CHANGED
|
@@ -578,16 +578,22 @@ class HachimiTranslator:
|
|
| 578 |
device=device,
|
| 579 |
compute_type=compute_type,
|
| 580 |
intra_threads=self._ct2_threads,
|
|
|
|
| 581 |
)
|
| 582 |
-
if device == "cuda"
|
| 583 |
-
#
|
| 584 |
-
#
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 591 |
translator = ctranslate2.Translator(
|
| 592 |
str(model_path / config.ct2_subdir), **kwargs
|
| 593 |
)
|
|
|
|
| 578 |
device=device,
|
| 579 |
compute_type=compute_type,
|
| 580 |
intra_threads=self._ct2_threads,
|
| 581 |
+
inter_threads=self._ct2_inter_threads,
|
| 582 |
)
|
| 583 |
+
if device == "cuda":
|
| 584 |
+
# LUÔN truyền device_index khi cuda — kể cả 1 GPU (vd "1" để
|
| 585 |
+
# chọn GPU 1; nếu bỏ qua thì CT2 mặc định GPU 0 = chạy sai).
|
| 586 |
+
if not gpu_indices:
|
| 587 |
+
raise RuntimeError("Không có GPU CUDA khả dụng.")
|
| 588 |
+
if len(gpu_indices) == 1:
|
| 589 |
+
kwargs["device_index"] = gpu_indices[0] # int
|
| 590 |
+
else:
|
| 591 |
+
# Đa GPU: list device + inter_threads=1 = 1 REPLICA/GPU.
|
| 592 |
+
# (CT2 inter_threads = replica MỖI device, KHÔNG phải tổng.
|
| 593 |
+
# Benchmark T4x2: 2GPU·1replica = 1.64× & NHANH NHẤT; 2
|
| 594 |
+
# replica/GPU = 4 worker CHẬM HƠN -17% + 4× VRAM → để =1.)
|
| 595 |
+
kwargs["device_index"] = gpu_indices
|
| 596 |
+
kwargs["inter_threads"] = 1
|
| 597 |
translator = ctranslate2.Translator(
|
| 598 |
str(model_path / config.ct2_subdir), **kwargs
|
| 599 |
)
|