Skip to content

Commit

Permalink
Add threading configuration
Browse files Browse the repository at this point in the history
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
  • Loading branch information
PJ-Finlay committed Aug 15, 2024
1 parent 1a60301 commit 0423c4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions argostranslate/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ class ModelProvider(Enum):

# Supported values: cpu and cuda
device = os.environ.get("ARGOS_DEVICE_TYPE", "cpu")

# https://opennmt.net/CTranslate2/python/ctranslate2.Translator.html
inter_threads = int(os.environ.get("ARGOS_INTER_THREADS", "1"))
intra_threads = int(os.environ.get("ARGOS_INTRA_THREADS", "0"))
7 changes: 6 additions & 1 deletion argostranslate/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def __init__(self, from_lang: Language, to_lang: Language, pkg: Package):
def hypotheses(self, input_text: str, num_hypotheses: int = 4) -> list[Hypothesis]:
if self.translator is None:
model_path = str(self.pkg.package_path / "model")
self.translator = ctranslate2.Translator(model_path, device=settings.device)
self.translator = ctranslate2.Translator(
model_path,
device=settings.device,
inter_threads=settings.inter_threads,
intra_threads=settings.intra_threads,
)
paragraphs = ITranslation.split_into_paragraphs(input_text)
info("paragraphs:", paragraphs)
translated_paragraphs = []
Expand Down

0 comments on commit 0423c4a

Please sign in to comment.