ngocdang83 commited on
Commit
eb79ca3
·
verified ·
1 Parent(s): f459f82

gpu blocker fix: translator.py

Browse files
Files changed (1) hide show
  1. 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" and len(gpu_indices) > 1:
583
- # Đa GPU: gán list device + inter_threads=1 = 1 REPLICA/GPU.
584
- # (CT2 inter_threads = số replica MỖI device, KHÔNG phải tổng.
585
- # Benchmark T4x2: 2GPU·1replica = 1.64× & NHANH NHẤT; 2 replica/
586
- # GPU = 4 worker lại CHẬM HƠN -17% + tốn 4× VRAM. Phải để =1.)
587
- kwargs["device_index"] = gpu_indices
588
- kwargs["inter_threads"] = 1
589
- else:
590
- kwargs["inter_threads"] = self._ct2_inter_threads
 
 
 
 
 
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
  )