From 6d4a4489b8c79e01450678c6b6d6f7bb3d2a14ac Mon Sep 17 00:00:00 2001 From: MahmoudAshraf97 Date: Thu, 23 May 2024 00:38:03 +0300 Subject: [PATCH] improved error message when extension is compiled against a different torch version than the one installed --- ctc_forced_aligner/alignment_utils.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ctc_forced_aligner/alignment_utils.py b/ctc_forced_aligner/alignment_utils.py index 8e0e47a..8cc421b 100644 --- a/ctc_forced_aligner/alignment_utils.py +++ b/ctc_forced_aligner/alignment_utils.py @@ -8,7 +8,22 @@ __version__ as transformers_version, ) from transformers.utils import is_flash_attn_2_available -from .ctc_forced_aligner import forced_align as forced_align_cpp + +try: + from .ctc_forced_aligner import forced_align as forced_align_cpp +except Exception as e: + if all( + substring in e.__repr__() + for substring in ["ctc_forced_aligner", "undefined symbol"] + ): + raise ImportError( + "ctc-forced-aligner package was build using a different version of " + "torch than the one currently installed, reinstall the package again using: \n" + "pip install git+https://github.com/MahmoudAshraf97/ctc-forced-aligner.git --force-reinstall --no-deps" + ) + else: + raise e + from typing import Optional, Tuple from packaging import version