[Update] 後方互換性のためのモデルの重みディレクトリ名変更機能を追加
This commit is contained in:
@@ -2870,9 +2870,12 @@ class Controller:
|
||||
if hasattr(self, '_ctranslate2_available_cache'):
|
||||
# 起動時のキャッシュを使用: 選択中の重みタイプのみ設定
|
||||
config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT[config.CTRANSLATE2_WEIGHT_TYPE] = self._ctranslate2_available_cache
|
||||
else:
|
||||
# 通常時は全重みタイプをチェック
|
||||
|
||||
# すべての重みタイプをチェック(キャッシュされていないものだけ)
|
||||
for weight_type in config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT.keys():
|
||||
# 選択中のウェイトはキャッシュで設定済みなのでスキップ
|
||||
if hasattr(self, '_ctranslate2_available_cache') and weight_type == config.CTRANSLATE2_WEIGHT_TYPE:
|
||||
continue
|
||||
config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT[weight_type] = model.checkTranslatorCTranslate2ModelWeight(weight_type)
|
||||
|
||||
def updateTranslationEngineAndEngineList(self):
|
||||
@@ -2899,9 +2902,12 @@ class Controller:
|
||||
if hasattr(self, '_whisper_available_cache'):
|
||||
# 起動時のキャッシュを使用: 選択中の重みタイプのみ設定
|
||||
config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[config.WHISPER_WEIGHT_TYPE] = self._whisper_available_cache
|
||||
else:
|
||||
# 通常時は全重みタイプをチェック
|
||||
|
||||
# すべての重みタイプをチェック(キャッシュされていないものだけ)
|
||||
for weight_type in config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT.keys():
|
||||
# 選択中のウェイトはキャッシュで設定済みなのでスキップ
|
||||
if hasattr(self, '_whisper_available_cache') and weight_type == config.WHISPER_WEIGHT_TYPE:
|
||||
continue
|
||||
config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[weight_type] = model.checkTranscriptionWhisperModelWeight(weight_type)
|
||||
|
||||
def updateTranscriptionEngine(self):
|
||||
@@ -3134,6 +3140,9 @@ class Controller:
|
||||
# Download weights
|
||||
if connected_network is True:
|
||||
printLog("Download CTranslate2 Model Weight")
|
||||
# 後方互換用
|
||||
model.backwardCompatibleTranslatorCTranslate2ModelRenameWeightsDir()
|
||||
|
||||
weight_type = config.CTRANSLATE2_WEIGHT_TYPE
|
||||
th_download_ctranslate2 = None
|
||||
if model.checkTranslatorCTranslate2ModelWeight(weight_type) is False:
|
||||
|
||||
@@ -25,7 +25,7 @@ from models.transcription.transcription_recorder import SelectedMicEnergyRecorde
|
||||
from models.transcription.transcription_transcriber import AudioTranscriber
|
||||
from models.translation.translation_languages import translation_lang
|
||||
from models.transcription.transcription_languages import transcription_lang
|
||||
from models.translation.translation_utils import checkCTranslate2Weight, downloadCTranslate2Weight, downloadCTranslate2Tokenizer
|
||||
from models.translation.translation_utils import checkCTranslate2Weight, downloadCTranslate2Weight, downloadCTranslate2Tokenizer, backwardCompatibleRenameWeightsDir
|
||||
from models.transcription.transcription_whisper import checkWhisperWeight, downloadWhisperWeight
|
||||
from models.transliteration.transliteration_transliterator import Transliterator
|
||||
from models.overlay.overlay import Overlay
|
||||
@@ -158,6 +158,9 @@ class Model:
|
||||
# Log and continue; callers should handle missing features.
|
||||
errorLogging()
|
||||
|
||||
def backwardCompatibleTranslatorCTranslate2ModelRenameWeightsDir(self):
|
||||
return backwardCompatibleRenameWeightsDir(config.PATH_LOCAL)
|
||||
|
||||
def checkTranslatorCTranslate2ModelWeight(self, weight_type:str):
|
||||
return checkCTranslate2Weight(config.PATH_LOCAL, weight_type)
|
||||
|
||||
|
||||
@@ -48,22 +48,23 @@ ctranslate2_weights = {
|
||||
},
|
||||
}
|
||||
|
||||
def backwardCompatibleRenameWeightsDir(root: str):
|
||||
# 後方互換のためファイル名を変更する
|
||||
legacy_dirs = {
|
||||
"m2m100_418M": "m2m100_418M-ct2-int8",
|
||||
"m2m100_12b": "m2m100_1.2B-ct2-int8",
|
||||
}
|
||||
|
||||
for weight_type_old, weight_type_new in legacy_dirs.items():
|
||||
path = os_path.join(root, "weights", "ctranslate2", weight_type_new)
|
||||
old_path = os_path.join(root, "weights", "ctranslate2", weight_type_old)
|
||||
if os_path.isdir(old_path):
|
||||
os_rename(old_path, path)
|
||||
|
||||
def checkCTranslate2Weight(root: str, weight_type: str = "m2m100_418M-ct2-int8"):
|
||||
weight_directory_name = ctranslate2_weights[weight_type]["directory_name"]
|
||||
path = os_path.join(root, "weights", "ctranslate2", weight_directory_name)
|
||||
|
||||
# 後方互換のためファイル名を変更する
|
||||
legacy_dirs = {
|
||||
"m2m100_418M-ct2-int8": "m2m100_418M",
|
||||
"m2m100_1.2B-ct2-int8": "m2m100_12b",
|
||||
}
|
||||
|
||||
legacy_dir = legacy_dirs.get(weight_type, None)
|
||||
if legacy_dir:
|
||||
old_path = os_path.join(root, "weights", "ctranslate2", legacy_dir)
|
||||
if os_path.isdir(old_path):
|
||||
os_rename(old_path, path)
|
||||
|
||||
try:
|
||||
# モデルロード可能かどうかで判定
|
||||
compute_type = getBestComputeType("cpu", 0)
|
||||
|
||||
Reference in New Issue
Block a user