Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat: enhance bf16 support checks for gcu, musa, and npu devices

myhloli2e0b8365393e
diff --git a/mineru/utils/block_sort.py b/mineru/utils/block_sort.py
index ab6e5f62..c00d2634 100644
--- a/mineru/utils/block_sort.py
+++ b/mineru/utils/block_sort.py
@@ -187,14 +187,17 @@ def model_init(model_name: str):
elif device_name.startswith("mps"):
bf_16_support = True
elif device_name.startswith("gcu"):
- if torch.gcu.is_bf16_supported():
- bf_16_support = True
+ if hasattr(torch, 'gcu') and torch.gcu.is_available():
+ if torch.gcu.is_bf16_supported():
+ bf_16_support = True
elif device_name.startswith("musa"):
- if torch.musa.is_bf16_supported():
- bf_16_support = True
+ if hasattr(torch, 'musa') and torch.musa.is_available():
+ if torch.musa.is_bf16_supported():
+ bf_16_support = True
elif device_name.startswith("npu"):
- if torch.npu.is_bf16_supported():
- bf_16_support = True
+ if hasattr(torch, 'npu') and torch.npu.is_available():
+ if torch.npu.is_bf16_supported():
+ bf_16_support = True
if model_name == 'layoutreader':
# 检测modelscope的缓存目录是否存在