Skip to content

Commit 0423c4a

Browse files
committed
Add threading configuration
Adds a configuration option for inter_threads and intra_threads to Argos Translate that is passed to CTranslate2 https://community.libretranslate.com/t/unable-to-task-more-than-4-threads/1188
1 parent 1a60301 commit 0423c4a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

argostranslate/settings.py

+4
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,7 @@ class ModelProvider(Enum):
100100

101101
# Supported values: cpu and cuda
102102
device = os.environ.get("ARGOS_DEVICE_TYPE", "cpu")
103+
104+
# https://opennmt.net/CTranslate2/python/ctranslate2.Translator.html
105+
inter_threads = int(os.environ.get("ARGOS_INTER_THREADS", "1"))
106+
intra_threads = int(os.environ.get("ARGOS_INTRA_THREADS", "0"))

argostranslate/translate.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ def __init__(self, from_lang: Language, to_lang: Language, pkg: Package):
166166
def hypotheses(self, input_text: str, num_hypotheses: int = 4) -> list[Hypothesis]:
167167
if self.translator is None:
168168
model_path = str(self.pkg.package_path / "model")
169-
self.translator = ctranslate2.Translator(model_path, device=settings.device)
169+
self.translator = ctranslate2.Translator(
170+
model_path,
171+
device=settings.device,
172+
inter_threads=settings.inter_threads,
173+
intra_threads=settings.intra_threads,
174+
)
170175
paragraphs = ITranslation.split_into_paragraphs(input_text)
171176
info("paragraphs:", paragraphs)
172177
translated_paragraphs = []

0 commit comments

Comments
 (0)