Skip to content

Commit

Permalink
refactor: speed up model estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
aiwantaozi committed Dec 17, 2024
1 parent a655951 commit 1a5673b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions vox_box/estimator/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from vox_box.estimator.faster_whisper import FasterWhisper
from vox_box.estimator.funasr import FunASR
from vox_box.utils.model import create_model_dict
from concurrent.futures import ThreadPoolExecutor, as_completed


def estimate_model(cfg: Config) -> Dict:
Expand All @@ -25,7 +26,14 @@ def estimate_model(cfg: Config) -> Dict:
def get_model_info(estimator: Estimator) -> Dict:
return estimator.model_info()

for e in estimators:
model_info = e.model_info()
if model_info["supported"]:
return model_info
with ThreadPoolExecutor() as executor:
futures = {executor.submit(get_model_info, e): e for e in estimators}
for future in as_completed(futures):
result = future.result()
if result["supported"]:
for f in futures:
if not f.done():
f.cancel()
return result

return model_info

0 comments on commit 1a5673b

Please sign in to comment.