Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
bd5252d9
Commit
bd5252d9
authored
Jun 17, 2025
by
myhloli
Browse files
fix: add conditional import for torch and torch_npu in config_reader.py
parent
b398a2d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
mineru/utils/config_reader.py
mineru/utils/config_reader.py
+7
-4
No files found.
mineru/utils/config_reader.py
View file @
bd5252d9
# Copyright (c) Opendatalab. All rights reserved.
import
json
import
os
from
loguru
import
logger
try
:
import
torch
import
torch_npu
except
ImportError
:
pass
# 定义配置文件名常量
CONFIG_FILE_NAME
=
os
.
getenv
(
'MINERU_TOOLS_CONFIG_JSON'
,
'mineru.json'
)
...
...
@@ -71,15 +77,12 @@ def get_device():
if
device_mode
is
not
None
:
return
device_mode
else
:
import
torch
if
torch
.
cuda
.
is_available
():
return
"cuda"
elif
torch
.
backends
.
mps
.
is_available
():
return
"mps"
else
:
try
:
import
torch_npu
if
torch_npu
.
npu
.
is_available
():
return
"npu"
except
Exception
as
e
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment