Repository navigation
Paralellism to improve performance, access is denied error #548
|
Hello, However, I'm hit with this error every time: Does anyone have any idea on what could be done to fix this issue, or if there's a better way of improving performance on translations? Right now a text with around 40k characters takes 30 seconds to translate, which is far from ideal. |
Replies: 2 comments 4 replies
|
That rename into the shared
If the first works and the second also removes the error, that points toward workers racing during lazy initialization/resource setup. Treat that as a diagnostic result rather than proof that concurrent calls are supported by your installed versions. If it still fails with one worker, a file lock or directory permissions deserves a closer look. For the timing, measure the first call separately from a second call in the same process. Otherwise the 30 seconds may include model loading/setup, and adding workers can multiply memory use or contend with the inference engine's own threads. One other detail: your regex allows an empty capture ( |
|
Oh, before I forget, my version of argostranslate is Anyway, def measure_execution(func, *args):
start = time.perf_counter()
retv = func(*args)
end = time.perf_counter()
timeTaken = end - start
return retv, timeTaken
def exec_parallel_translate(from_code, to_code, text):
retv = ""
worker_count = 10
chunkSize = math.ceil(len(text)/worker_count)
textChunks = [textChunk.group(1) for textChunk in re.finditer(r"(.{0," + str(chunkSize) + r"}(?: |$))", text, flags=re.MULTILINE | re.S) if textChunk.group(1)]
with concurrent.futures.ThreadPoolExecutor(max_workers=worker_count) as executor:
results = executor.map(measure_execution, repeat(argostranslate.translate.translate), textChunks, repeat(from_code), repeat(to_code))
for value, timeTaken in results:
retv += value
print(f"Single thread execution time: {timeTaken}" )
return retv
def exec_translate_offline(from_code, to_code, text):
retv = ""
retv, timeTakenSingleSmall = measure_execution(argostranslate.translate.translate,"Olá Mundo", from_code, to_code)
retv, timeTakenParallelLarge = measure_execution(exec_parallel_translate, from_code, to_code, text)
retv, timeTakenSingleLarge = measure_execution(argostranslate.translate.translate, text, from_code, to_code)
print("Single thread, small text: " + str(timeTakenSingleSmall))
print("Multi thread, large text:" + str(timeTakenParallelLarge))
print("Single thread, large text:" + str(timeTakenSingleLarge))
return retvAnd the result of one execution: Single thread execution time: 19.593026700080372 Actually, it seems that no matter how I adjust the worker count and the chunk size, the result is almost always exactly the same. Suspicious, makes me think it's not actually executing in parallel at all. |
That rename into the shared
stanza/resources.jsonmakes concurrent initialization a likely suspect, although the traceback alone doesn't prove it. I'd try two small comparisons before changing permissions:max_workers=1.If the first works and the second also removes the error, that points toward workers racing during lazy initialization/resource setup. Treat that as a diagnostic result rather than proof that concurrent calls are supported by your installed versions. If it still fails with one worker, a file lock or directory permissions deserves a closer l…