Unverified Commit 98b215b8 authored by Xiaomeng Zhao's avatar Xiaomeng Zhao Committed by GitHub
Browse files

Merge pull request #1789 from opendatalab/release-1.2.0

Release 1.2.0
parents 82d4e451 b6d60bb0
...@@ -338,24 +338,7 @@ def txt_spans_extract_v2(pdf_page, spans, all_bboxes, all_discarded_blocks, lang ...@@ -338,24 +338,7 @@ def txt_spans_extract_v2(pdf_page, spans, all_bboxes, all_discarded_blocks, lang
def model_init(model_name: str): def model_init(model_name: str):
from transformers import LayoutLMv3ForTokenClassification from transformers import LayoutLMv3ForTokenClassification
device = get_device() device = torch.device(get_device())
if torch.cuda.is_available():
device = torch.device('cuda')
if torch.cuda.is_bf16_supported():
supports_bfloat16 = True
else:
supports_bfloat16 = False
elif str(device).startswith("npu"):
import torch_npu
if torch_npu.npu.is_available():
device = torch.device('npu')
supports_bfloat16 = False
else:
device = torch.device('cpu')
supports_bfloat16 = False
else:
device = torch.device('cpu')
supports_bfloat16 = False
if model_name == 'layoutreader': if model_name == 'layoutreader':
# 检测modelscope的缓存目录是否存在 # 检测modelscope的缓存目录是否存在
...@@ -371,9 +354,6 @@ def model_init(model_name: str): ...@@ -371,9 +354,6 @@ def model_init(model_name: str):
model = LayoutLMv3ForTokenClassification.from_pretrained( model = LayoutLMv3ForTokenClassification.from_pretrained(
'hantian/layoutreader' 'hantian/layoutreader'
) )
# 检查设备是否支持 bfloat16
if supports_bfloat16:
model.bfloat16()
model.to(device).eval() model.to(device).eval()
else: else:
logger.error('model name not allow') logger.error('model name not allow')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment