멀티쓰레드·GPU 병렬 처리

멀티쓰레드·GPU 병렬 처리

CTranslate2는 쓰레드 수와 GPU 사용을 명시적으로 조절할 수 있어요. devicedevice_index로 GPU를 고르고, inter_threads/intra_threads로 병렬 처리를 조절해요.

translator = ctranslate2.Translator(
    "ct2_model",
    device="cuda",        # "cpu" 또는 "cuda"
    device_index=[0, 1],  # 사용할 GPU 인덱스 목록
    inter_threads=4,      # 서로 다른 입력을 병렬 처리하는 쓰레드 수
    intra_threads=1,      # 단일 연산 내부 병렬화 쓰레드 수
)

확인 포인트

  • inter_threads는 배치 단위 병렬화, intra_threads는 연산 내부 병렬화로 이해하면 쉬워요.
  • GPU 메모리가 빠듯하다면 max_batch_size로 배치 크기를 제한할 수 있어요.

출처: https://opennmt.net/CTranslate2/parallel.html

더 알아보기