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
7ae4f80d
Commit
7ae4f80d
authored
Jun 12, 2025
by
myhloli
Browse files
feat: enhance device detection to support NPU and improve error handling
parent
5f1a509f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
6 deletions
+20
-6
mineru/backend/pipeline/pipeline_analyze.py
mineru/backend/pipeline/pipeline_analyze.py
+12
-5
mineru/utils/config_reader.py
mineru/utils/config_reader.py
+8
-1
No files found.
mineru/backend/pipeline/pipeline_analyze.py
View file @
7ae4f80d
import
os
import
os
import
time
import
time
import
numpy
as
np
from
typing
import
List
,
Tuple
import
PIL.Image
import
torch
import
torch
from
.model_init
import
MineruPipelineModel
from
.model_init
import
MineruPipelineModel
...
@@ -150,7 +151,7 @@ def doc_analyze(
...
@@ -150,7 +151,7 @@ def doc_analyze(
def
batch_image_analyze
(
def
batch_image_analyze
(
images_with_extra_info
:
l
ist
[
(
np
.
ndarray
,
bool
,
str
)
],
images_with_extra_info
:
L
ist
[
Tuple
[
PIL
.
Image
.
Image
,
bool
,
str
]
],
formula_enable
=
None
,
formula_enable
=
None
,
table_enable
=
None
):
table_enable
=
None
):
# os.environ['CUDA_VISIBLE_DEVICES'] = str(idx)
# os.environ['CUDA_VISIBLE_DEVICES'] = str(idx)
...
@@ -163,9 +164,15 @@ def batch_image_analyze(
...
@@ -163,9 +164,15 @@ def batch_image_analyze(
device
=
get_device
()
device
=
get_device
()
if
str
(
device
).
startswith
(
'npu'
):
if
str
(
device
).
startswith
(
'npu'
):
import
torch_npu
try
:
if
torch_npu
.
npu
.
is_available
():
import
torch_npu
torch
.
npu
.
set_compile_mode
(
jit_compile
=
False
)
if
torch_npu
.
npu
.
is_available
():
torch
.
npu
.
set_compile_mode
(
jit_compile
=
False
)
except
Exception
as
e
:
raise
RuntimeError
(
"NPU is selected as device, but torch_npu is not available. "
"Please ensure that the torch_npu package is installed correctly."
)
from
e
if
str
(
device
).
startswith
(
'npu'
)
or
str
(
device
).
startswith
(
'cuda'
):
if
str
(
device
).
startswith
(
'npu'
)
or
str
(
device
).
startswith
(
'cuda'
):
vram
=
get_vram
(
device
)
vram
=
get_vram
(
device
)
...
...
mineru/utils/config_reader.py
View file @
7ae4f80d
...
@@ -74,8 +74,15 @@ def get_device():
...
@@ -74,8 +74,15 @@ def get_device():
else
:
else
:
if
torch
.
cuda
.
is_available
():
if
torch
.
cuda
.
is_available
():
return
"cuda"
return
"cuda"
if
torch
.
backends
.
mps
.
is_available
():
el
if
torch
.
backends
.
mps
.
is_available
():
return
"mps"
return
"mps"
else
:
try
:
import
torch_npu
if
torch_npu
.
npu
.
is_available
():
return
"npu"
except
Exception
as
e
:
pass
return
"cpu"
return
"cpu"
...
...
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