From be6f821c3c077d10316206fa0abd8b38c62ccdd6 Mon Sep 17 00:00:00 2001 From: chongchuanbing Date: Thu, 10 Oct 2024 10:06:03 +0800 Subject: [PATCH] fix: torch dependency start error (#2777) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? when use slim image, remove ```torch``` denpendency. ### Type of change - [✓] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: chongchuanbing Co-authored-by: Kevin Hu --- deepdoc/parser/pdf_parser.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/deepdoc/parser/pdf_parser.py b/deepdoc/parser/pdf_parser.py index e5268a8a4c2..ab888eb2a19 100644 --- a/deepdoc/parser/pdf_parser.py +++ b/deepdoc/parser/pdf_parser.py @@ -45,9 +45,12 @@ def __init__(self): self.updown_cnt_mdl = xgb.Booster() if not LIGHTEN: - import torch - if torch.cuda.is_available(): - self.updown_cnt_mdl.set_param({"device": "cuda"}) + try: + import torch + if torch.cuda.is_available(): + self.updown_cnt_mdl.set_param({"device": "cuda"}) + except Exception as e: + logging.error(str(e)) try: model_dir = os.path.join( get_project_base_directory(),