Commit 4e330e55 authored by dmMaze's avatar dmMaze
Browse files

add low vram mode for sakura translator (enabled by default)

parent 8f9ddd4e
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -47,8 +47,6 @@ $ python3 launch.py

第一次运行会自动安装 torch 等依赖项并下载所需模型和文件,如果模型下载失败,需要手动从 [MEGA](https://mega.nz/folder/gmhmACoD#dkVlZ2nphOkU5-2ACb5dKw)[Google Drive](https://drive.google.com/drive/folders/1uElIYRLNakJj-YS0Kd3r3HE-wzeEvrWd?usp=sharing) 下载 data 文件夹(或者报错里提到缺失的文件),并保存到源码目录下的对应位置。

如果要使用Sugoi翻译器(仅日译英),下载[离线模型](https://drive.google.com/drive/folders/1KnDlfUM9zbnYFTo6iCbnBaBKabXfnVJm),将 ```sugoi_translator``` 移入 BallonsTranslator/ballontranslator/data/models。 

## 构建 macOS 应用(适用 apple silicon 芯片)
<i>如果构建不成功也可以直接跑源码</i>

@@ -192,8 +190,8 @@ Sugoi 翻译器作者: [mingshiba](https://www.patreon.com/mingshiba)
 * 谷歌翻译器已经关闭中国服务,大陆再用需要设置全局代理,并在设置面板把 url 换成*.com
 * 彩云,需要申请 [token](https://dashboard.caiyunapp.com/)
 * papago  
 * DeepL 和 Sugoi (及它的 CT2 Translation 转换)翻译器,感谢 [Snowad14](https://github.com/Snowad14)  
 * 支持 [Sakura-13B-Galgame](https://github.com/SakuraLLM/Sakura-13B-Galgame)
 * DeepL 和 Sugoi (及它的 CT2 Translation 转换)翻译器,感谢 [Snowad14](https://github.com/Snowad14),如果要使用Sugoi翻译器(仅日译英),下载[离线模型](https://drive.google.com/drive/folders/1KnDlfUM9zbnYFTo6iCbnBaBKabXfnVJm),将 ```sugoi_translator``` 移入 BallonsTranslator/ballontranslator/data/models。 
 * 支持 [Sakura-13B-Galgame](https://github.com/SakuraLLM/Sakura-13B-Galgame)。如果在本地单卡上运行且显存不足,可以在设置面板里勾选 ```low vram mode``` (默认启用)。

其它优秀的离线英文翻译模型请参考[这条讨论](https://github.com/dmMaze/BallonsTranslator/discussions/515)  
如需添加新的翻译器请参考[加别的翻译器](doc/加别的翻译器.md),本程序添加新翻译器只需要继承基类实现两个接口即可不需要理会代码其他部分,欢迎大佬提 pr
+3 −5
Original line number Diff line number Diff line
@@ -124,8 +124,6 @@ sh scripts/build-macos-app.sh

</details> 

To use Sugoi translator(Japanese-English only), download [offline model](https://drive.google.com/drive/folders/1KnDlfUM9zbnYFTo6iCbnBaBKabXfnVJm), move "sugoi_translator" into the BallonsTranslator/ballontranslator/data/models.  

# Usage

**It is recommended to run the program in a terminal in case it crashed and left no information, see the following gif.**
@@ -226,8 +224,8 @@ Available translators: Google, DeepL, ChatGPT, Sugoi, Caiyun, Baidu. Papago, and
 * Google shuts down translate service in China, please set corresponding 'url' in config panel to *.com.
 * [Caiyun](https://dashboard.caiyunapp.com/), [ChatGPT](https://platform.openai.com/playground), [Yandex](https://yandex.com/dev/translate/), [Baidu](http://developers.baidu.com/), and [DeepL](https://www.deepl.com/docs-api/api-access) translators needs to require a token or api key.
 * DeepL & Sugoi translator (and it's CT2 Translation conversion) thanks to [Snowad14](https://github.com/Snowad14).
 * Sugoi translates Japanese to English completely offline.
 * [Sakura-13B-Galgame](https://github.com/SakuraLLM/Sakura-13B-Galgame)
 * Sugoi translates Japanese to English completely offline. Download [offline model](https://drive.google.com/drive/folders/1KnDlfUM9zbnYFTo6iCbnBaBKabXfnVJm), move "sugoi_translator" into the BallonsTranslator/ballontranslator/data/models. 
 * [Sakura-13B-Galgame](https://github.com/SakuraLLM/Sakura-13B-Galgame), check ```low vram mode``` in config panel if you\'re running it locally on a single device and encountered a crash due to vram OOM (enabled by default).

For other good offline English translators, please refer to this [thread](https://github.com/dmMaze/BallonsTranslator/discussions/515).  
To add a new translator, please reference [how_to_add_new_translator](doc/how_to_add_new_translator.md), it is simple as subclass a BaseClass and implementing two interfaces, then you can use it in the application, you are welcome to contribute to the project.  
+6 −0
Original line number Diff line number Diff line
@@ -96,6 +96,12 @@ class BaseModule:
    def updateParam(self, param_key: str, param_content):
        self.set_param_value(param_key, param_content)

    @property
    def low_vram_mode(self):
        if 'low vram mode' in self.params:
            return self.get_param_value('low vram mode')
        return False

    def is_cpu_intensive(self)->bool:
        if self.params is not None and 'device' in self.params:
            return self.params['device']['value'] == 'cpu'
+5 −0
Original line number Diff line number Diff line
@@ -73,6 +73,11 @@ class GPTTranslator(BaseTranslator):
        '3rd party api url': '',
        'frequency penalty': 0.0,
        'presence penalty': 0.0,
        'low vram mode': {
            'value': False,
            'description': 'check it if you\'re running it locally on a single device and encountered a crash due to vram OOM',
            'type': 'checkbox',
        }
    }

    def _setup_translator(self):
+5 −0
Original line number Diff line number Diff line
@@ -360,6 +360,11 @@ class SakuraTranslator(BaseTranslator):
    concate_text = False
    cht_require_convert = True
    params: Dict = {
        'low vram mode': {
            'value': True,
            'description': 'check it if you\'re running it locally on a single device and encountered a crash due to vram OOM',
            'type': 'checkbox',
        },
        'api baseurl': 'https://127.0.0.1:8080/v1',
        'dict path': '',
        'version': {
Loading