Skip to content

Conversation

@liyuheng55555
Copy link

@liyuheng55555 liyuheng55555 commented Mar 10, 2025

Default concurrency is 3.
Using --concurrency to set it.

Based on my tests, a concurrency of 3 can speed up execution by approximately 2.5 times, while a concurrency of 10 can achieve around 3.2 times speedup. Therefore, the default concurrency level is set to 3.

My test environment is macbook air m3, deepseek-chat api.

Other discussion at: #870

@liyuheng55555
Copy link
Author

这个pr使用协程实现并发。

协程可能不是最佳的方式,多进程更好,我是这么分析的,整个翻译过程可以分成三步:

  1. ocr
  2. 大模型翻译
  3. 图片渲染

其中第二步如果使用api的话算是IO密集任务,协程能很好地加速这部分。第一步第三步属于计算密集型任务,协程机制上来说无法给计算密集型任务加速很多。

但我目前感觉协程的加速效果也足够满足需求,可能等以后有更大批量翻译需求的时候再给升级成多进程吧。

@frederik-uni
Copy link
Contributor

@liyuheng55555 shouldn’t this work in server mode too? It was meant to run on multiple servers instead of one so i didnt test it and only registered a single instance. I thought that a single instance would just allocate all the resources

@liyuheng55555
Copy link
Author

@frederik-uni I recently started participating in this project, so there are many things I still don’t understand. Are you referring to the server mode as the MangaTranslatorWS class?

It was meant to run on multiple servers

This sounds like a distributed system, or is it ?

@frederik-uni
Copy link
Contributor

@liyuheng55555 no the server is a separate module outside of the translator.
instance is registered

the shared module is used by the server. It allows one connection and allows to execute functions within the instance. It uses a pickle to send attribute values. I would just start another instance of the translator. This might take up some extra memory as another python runtime will be running but this won't cause any blocking issues or temporary variables that might be stored in the translator object. The only issue that might cause is probably that tensorflow/pytorch allocating the gpu/cpu could cause some issues. I know that working with notebooks or whatever they are called can cause this issue. Not sure if this will cause an issue tho

@liyuheng55555
Copy link
Author

@frederik-uni Thanks for your explanation. I’ll continue looking into it tomorrow.

@popcion
Copy link
Contributor

popcion commented Mar 10, 2025

有谁发现了batch模式没有logger,我一直用老版本不知道什么时候改没掉了,看起来有一段时间了没人觉得奇怪吗
Who found the batch mode without logger, I have been using the old version do not know when changed. Seems like it's been a while and no one thinks it's weird

# 在导入语句后添加  
import logging  
import sys  

# 配置logger以显示在命令行
def setup_console_logging(logger_instance, verbose): 
    console_handler = logging.StreamHandler(sys.stdout)
    if verbose: # Check verbose flag
        console_handler.setLevel(logging.DEBUG) 
        logger_instance.setLevel(logging.DEBUG) 
    else:
        console_handler.setLevel(logging.INFO)  
        logger_instance.setLevel(logging.INFO)   
    formatter = logging.Formatter('%(message)s')
    console_handler.setFormatter(formatter)

    # 检查是否已有控制台处理程序
    has_console_handler = False
    for handler in logger_instance.handlers:
        if isinstance(handler, logging.StreamHandler):
            has_console_handler = True
            break

    if not has_console_handler:
        logger_instance.addHandler(console_handler)

添加logger后发现获取子文件夹文件有问题,需要处理一下
测试的文件夹:
After adding logger, it is found that there is a problem in obtaining subfolder files. You need to process the tested folders
G:\test\1\1.jpg
G:\test\1\2.jpg
G:\test\1-translated(empty)
G:\test\3.png
G:\test\5.png

(venv) PS G:\tools\test\manga-image-translator-main-2-1> python -m manga_translator local -i "G:\test" --config-file "G:\tools\test\manga-image-translator-main-2-1\examples\config-example.json" --overwrite --use-gpu -v
[local] Namespace(verbose=True, attempts=0, ignore_errors=False, model_dir=None, use_gpu=True, use_gpu_limited=False, font_path='', pre_dict=None, post_dict=None, kernel_size=3, mode='local', input=['G:\\test'], dest='', format=None, overwrite=True, skip_no_text=False, use_mtpe=False, save_text=False, load_text=False, save_text_file='', prep_manual=False, save_quality=100, config_file='G:\\tools\\test\\manga-image-translator-main-2-1\\examples\\config-example.json', concurrency=3)
[local] Running in local mode
Translating: "G:\test\1-translated\3.png"
Failed to open image: G:\test\1-translated\3.png
Failed to translate "G:\test\1-translated\3.png"
Translating: "G:\test\1-translated\5.png"
Failed to open image: G:\test\1-translated\5.png
Failed to translate "G:\test\1-translated\5.png"
Translating: "G:\test\1-translated\1.jpg"
Failed to open image: G:\test\1-translated\1.jpg
Failed to translate "G:\test\1-translated\1.jpg"
Translating: "G:\test\1-translated\2.png"
Failed to open image: G:\test\1-translated\2.png
Failed to translate "G:\test\1-translated\2.png"
No further untranslated files found. Use --overwrite to write over existing translations.
(venv) PS G:\tools\test\manga-image-translator-main-2-1> 

@liyuheng55555
Copy link
Author

有谁发现了batch模式没有logger,我一直用老版本不知道什么时候改没掉了,看起来有一段时间了没人觉得奇怪吗
Who found the batch mode without logger, I have been using the old version do not know when changed. Seems like it's been a while and no one thinks it's weird

@popcion 我发现了,但还以为是没开某个参数导致的 XD

添加logger后发现获取子文件夹文件有问题,需要处理一下

好的,晚些时候我处理一下

@popcion
Copy link
Contributor

popcion commented Mar 21, 2025

文件夹的问题把root传过来就好了
async def translate_single_file(image_file):
tasks.append(translate_single_file(image_file))
改成
async def translate_single_file(root, image_file):
tasks.append(translate_single_file(root, image_file))

@zyddnys
Copy link
Owner

zyddnys commented Mar 31, 2025

有问题吗,没有我就合了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants