Skip to content

Commit b58d561

Browse files
committed
Merge branch 'main' into dev
2 parents 02ee5f1 + 12ade8b commit b58d561

File tree

11 files changed

+163
-82
lines changed

11 files changed

+163
-82
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ endef
155155
# ========== Build Targets ==========
156156

157157
# Valid build targets
158-
VALID_BUILD_TARGETS := backend database frontend runtime backend-python deer-flow mineru
158+
VALID_BUILD_TARGETS := backend database frontend runtime backend-python deer-flow mineru mineru-npu
159159

160160
# Generic docker build target with service name as parameter
161161
# Automatically prefixes image names with "datamate-" unless it's deer-flow

deployment/docker/datamate/docker-compose.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,28 @@ services:
9999
restart: on-failure
100100
environment:
101101
MINERU_MODEL_SOURCE: local
102-
MINERU_DEVICE_MODE: cpu # cpu|cuda|npu|mps
103-
MINERU_BACKEND_MODE: pipeline
102+
MINERU_DEVICE_MODE: npu # cpu|cuda|npu|mps
103+
VLLM_WORKER_MULTIPROC_METHOD: spawn
104104
privileged: true
105105
command:
106-
- python
107-
- /opt/runtime/datamate/mineru/mineru_api.py
108-
- --port
109-
- "9001"
106+
- mineru-openai-server
107+
- --engine vllm
108+
- --host 0.0.0.0
109+
- --port "8000"
110110
volumes:
111111
- dataset_volume:/dataset
112112
- mineru_log_volume:/var/log/datamate/mineru
113+
- /var/log/npu/:/usr/slog
114+
- /usr/local/dcmi:/usr/local/dcmi
115+
- /usr/local/bin/npu-smi:/usr/local/bin/npu-smi
116+
- /usr/local/Ascend/driver:/usr/local/Ascend/driver
113117
networks: [ datamate ]
114118
profiles: [ mineru ]
119+
devices:
120+
- /dev/davinci0
121+
- /dev/davinci_manager
122+
- /dev/devmm_svm
123+
- /dev/hisi_hdc
115124

116125
# 5) redis
117126
datamate-redis:

deployment/helm/datamate/charts/ray-cluster/values.yaml

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,10 @@ head:
5858
# in the headGroupSpec. See https://github.com/ray-project/kuberay/pull/1128 for more details.
5959
serviceAccountName: ""
6060
restartPolicy: ""
61-
rayStartParams:
62-
object-store-memory: '78643200'
61+
rayStartParams: {}
6362
# containerEnv specifies environment variables for the Ray container,
6463
# Follows standard K8s container env schema.
65-
containerEnv:
66-
- name: RAY_DEDUP_LOGS
67-
value: "0"
68-
- name: RAY_TQDM_PATCH_PRINT
69-
value: "0"
70-
- name: MYSQL_HOST
71-
value: "datamate-database"
72-
- name: MYSQL_PORT
73-
value: "3306"
74-
- name: MYSQL_USER
75-
value: "root"
76-
- name: MYSQL_PASSWORD
77-
value: "password"
78-
- name: MYSQL_DATABASE
79-
value: "datamate"
64+
containerEnv: []
8065
# - name: EXAMPLE_ENV
8166
# value: "1"
8267
envFrom: []
@@ -93,14 +78,7 @@ head:
9378
# It is usually best to set requests equal to limits.
9479
# See https://docs.ray.io/en/latest/cluster/kubernetes/user-guides/config.html#resources
9580
# for further guidance.
96-
resources:
97-
limits:
98-
cpu: "2"
99-
# To avoid out-of-memory issues, never allocate less than 2G memory for the Ray head.
100-
memory: "8G"
101-
requests:
102-
cpu: "1"
103-
memory: "2G"
81+
resources: {}
10482
annotations: {}
10583
nodeSelector: {}
10684
tolerations: []
@@ -156,21 +134,7 @@ worker:
156134
initContainers: []
157135
# containerEnv specifies environment variables for the Ray container,
158136
# Follows standard K8s container env schema.
159-
containerEnv:
160-
- name: RAY_DEDUP_LOGS
161-
value: "0"
162-
- name: RAY_TQDM_PATCH_PRINT
163-
value: "0"
164-
- name: MYSQL_HOST
165-
value: "datamate-database"
166-
- name: MYSQL_PORT
167-
value: "3306"
168-
- name: MYSQL_USER
169-
value: "root"
170-
- name: MYSQL_PASSWORD
171-
value: "password"
172-
- name: MYSQL_DATABASE
173-
value: "datamate"
137+
containerEnv: []
174138
# - name: EXAMPLE_ENV
175139
# value: "1"
176140
envFrom: []
@@ -187,13 +151,7 @@ worker:
187151
# It is usually best to set requests equal to limits.
188152
# See https://docs.ray.io/en/latest/cluster/kubernetes/user-guides/config.html#resources
189153
# for further guidance.
190-
resources:
191-
limits:
192-
cpu: "4"
193-
memory: "8G"
194-
requests:
195-
cpu: "1"
196-
memory: "1G"
154+
resources: {}
197155
annotations: {}
198156
nodeSelector: {}
199157
tolerations: []

deployment/helm/datamate/values.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ database:
7777
subPath: database
7878

7979
backend:
80+
securityContext:
81+
capabilities:
82+
add:
83+
- SYS_ADMIN
8084
env:
8185
- name: DB_PASSWORD
8286
value: *dbPass
@@ -170,6 +174,30 @@ runtime:
170174
ray-cluster:
171175
enabled: true
172176
head:
177+
rayStartParams:
178+
num-cpus: '0'
179+
containerEnv:
180+
- name: RAY_DEDUP_LOGS
181+
value: "0"
182+
- name: RAY_TQDM_PATCH_PRINT
183+
value: "0"
184+
- name: MYSQL_HOST
185+
value: "datamate-database"
186+
- name: MYSQL_PORT
187+
value: "3306"
188+
- name: MYSQL_USER
189+
value: "root"
190+
- name: MYSQL_PASSWORD
191+
value: *dbPass
192+
- name: MYSQL_DATABASE
193+
value: "datamate"
194+
resources:
195+
limits:
196+
cpu: "4"
197+
memory: "16G"
198+
requests:
199+
cpu: "1"
200+
memory: "2G"
173201
volumes:
174202
- *datasetVolume
175203
- *flowVolume
@@ -196,6 +224,28 @@ ray-cluster:
196224
- containerPort: 8081
197225
volumeMounts: *runtimeVolumeMounts
198226
worker:
227+
containerEnv:
228+
- name: RAY_DEDUP_LOGS
229+
value: "0"
230+
- name: RAY_TQDM_PATCH_PRINT
231+
value: "0"
232+
- name: MYSQL_HOST
233+
value: "datamate-database"
234+
- name: MYSQL_PORT
235+
value: "3306"
236+
- name: MYSQL_USER
237+
value: "root"
238+
- name: MYSQL_PASSWORD
239+
value: *dbPass
240+
- name: MYSQL_DATABASE
241+
value: "datamate"
242+
resources:
243+
limits:
244+
cpu: "8"
245+
memory: "64G"
246+
requests:
247+
cpu: "1"
248+
memory: "2G"
199249
volumes:
200250
- *datasetVolume
201251
- *flowVolume

deployment/kubernetes/mineru/deploy.yaml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,32 @@ spec:
2222
image: datamate-mineru
2323
imagePullPolicy: IfNotPresent
2424
command:
25-
- python
26-
- /opt/runtime/datamate/mineru/mineru_api.py
25+
- mineru-openai-server
26+
args:
27+
- --engine
28+
- vllm
29+
- --host
30+
- 0.0.0.0
2731
- --port
28-
- "9001"
32+
- "8000"
2933
env:
3034
- name: MINERU_MODEL_SOURCE
3135
value: local
3236
- name: MINERU_DEVICE_MODE
33-
value: cpu
34-
- name: MINERU_BACKEND_MODE
35-
value: pipeline
37+
value: npu
38+
- name: VLLM_WORKER_MULTIPROC_METHOD
39+
value: spawn
3640
ports:
37-
- containerPort: 9001
41+
- containerPort: 8000
3842
resources:
3943
limits:
40-
cpu: 16
44+
cpu: 8
4145
memory: 32Gi
46+
huawei.com/Ascend910: 1
4247
requests:
4348
cpu: 100m
4449
memory: 100Mi
50+
huawei.com/Ascend910: 1
4551
volumeMounts:
4652
- name: dataset-volume
4753
mountPath: /dataset
@@ -67,8 +73,8 @@ metadata:
6773
spec:
6874
type: ClusterIP
6975
ports:
70-
- port: 9001
71-
targetPort: 9001
76+
- port: 8000
77+
targetPort: 8000
7278
protocol: TCP
7379
selector:
7480
app: datamate

runtime/ops/formatter/mineru_formatter/process.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,58 @@
55
Description: MinerU PDF文本抽取
66
Create: 2025/10/29 17:24
77
"""
8-
import json
8+
import os
9+
import shutil
910
import time
10-
from loguru import logger
1111
from typing import Dict, Any
1212

13-
from datamate.core.base_op import Mapper
1413
from datamate.common.utils.rest_client import http_request
14+
from datamate.core.base_op import Mapper
15+
from loguru import logger
16+
from mineru.cli.common import do_parse, read_fn
17+
from mineru.cli.fast_api import get_infer_result
18+
from pypdf import PdfReader
1519

1620

1721
class MineruFormatter(Mapper):
1822
"""基于外部API,抽取PDF中的文本"""
1923

2024
def __init__(self, *args, **kwargs):
2125
super(MineruFormatter, self).__init__(*args, **kwargs)
22-
self.base_url = "http://datamate-mineru:9001"
23-
self.pdf_extract_url = f"{self.base_url}/api/pdf-extract"
26+
self.server_url = "http://datamate-mineru:8000"
27+
self.backend = "vlm-http-client"
28+
self.output_dir = "/dataset/outputs"
2429

2530
def execute(self, sample: Dict[str, Any]) -> Dict[str, Any]:
2631
start = time.time()
2732
filename = sample[self.filename_key]
28-
if not filename.lower().endswith(".pdf"):
33+
filename_without_ext = os.path.splitext(filename)[0]
34+
if not filename.lower().endswith((".png", ".jpeg", ".jpg", ".webp", ".gif", ".pdf")):
2935
return sample
3036
try:
31-
data = {"source_path": sample[self.filepath_key], "export_path": sample[self.export_path_key]}
32-
response = http_request(method="POST", url=self.pdf_extract_url, data=data)
33-
sample[self.text_key] = json.loads(response.text).get("result")
37+
filepath = sample[self.filepath_key]
38+
parse_dir = os.path.join(self.output_dir, filename_without_ext, "vlm")
39+
pdf_bytes = read_fn(filepath)
40+
total_page = len(PdfReader(filepath).pages)
41+
content = ""
42+
for page in range(0, total_page, 10):
43+
do_parse(
44+
output_dir=self.output_dir,
45+
pdf_file_names=[filename_without_ext],
46+
pdf_bytes_list=[pdf_bytes],
47+
p_lang_list=["ch"],
48+
backend=self.backend,
49+
server_url=self.server_url,
50+
start_page_id=page,
51+
end_page_id=min(page + 9, total_page - 1),
52+
)
53+
if os.path.exists(parse_dir):
54+
content += get_infer_result(".md", filename_without_ext, parse_dir)
55+
shutil.rmtree(parse_dir)
56+
sample[self.text_key] = content
3457
logger.info(
3558
f"fileName: {filename}, method: MineruFormatter costs {(time.time() - start):6f} s")
36-
except UnicodeDecodeError as err:
37-
logger.exception(f"fileName: {filename}, method: MineruFormatter causes decode error: {err}")
59+
except Exception as e:
60+
logger.exception(f"fileName: {filename}, method: MineruFormatter causes error: {e}")
3861
raise
3962
return sample

runtime/ops/pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ dependencies = [
1111
"emoji>=2.15.0",
1212
"jieba>=0.42.1",
1313
"loguru>=0.7.3",
14-
"numpy==1.23.3",
14+
"mineru>=2.6.5",
15+
"numpy==1.24.3",
16+
"python-multipart>=0.0.20",
1517
"opencv-contrib-python-headless==4.7.0.72",
1618
"opencv-python-headless==4.7.0.72",
1719
"openslide-python>=1.4.3",
@@ -29,4 +31,4 @@ dependencies = [
2931
"sqlalchemy>=2.0.44",
3032
"xmltodict>=1.0.2",
3133
"zhconv>=1.4.3",
32-
]
34+
]

runtime/python-executor/datamate/core/base_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ def create_failure_sample(self, sample: Dict[str, Any], op_name, excp: BaseExcep
146146
def read_file(self, sample):
147147
filepath = sample[self.filepath_key]
148148
filetype = sample[self.filetype_key]
149-
if filetype in ["ppt", "pptx", "docx", "doc", "xlsx"]:
149+
if filetype in ["ppt", "pptx", "docx", "doc", "xlsx", "csv", "md", "pdf"]:
150150
elements = partition(filename=filepath)
151151
sample[self.text_key] = "\n\n".join([str(el) for el in elements])
152-
elif filetype in ["txt", "md", "markdown", "xml", "html", "csv", "json", "jsonl"]:
152+
elif filetype in ["txt", "md", "markdown", "xml", "html", "json", "jsonl"]:
153153
with open(filepath, 'rb') as f:
154154
content = f.read()
155155
sample[self.text_key] = content.decode("utf-8-sig").replace("\r\n", "\n")

runtime/python-executor/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dependencies = [
2121
"loguru>=0.7.3",
2222
"opencv-python-headless>=4.12.0.88",
2323
"ray[data,default]==2.52.1",
24-
"unstructured[csv,docx,pptx,xlsx]==0.18.15",
24+
"unstructured[csv,docx,pptx,xlsx,pdf,md]==0.18.15",
2525
"uvicorn[standard]>=0.38.0",
2626
]
2727

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 基础镜像配置 vLLM 或 LMDeploy ,请根据实际需要选择其中一个,要求 ARM(AArch64) CPU + Ascend NPU。
2+
# Base image containing the vLLM inference environment, requiring ARM(AArch64) CPU + Ascend NPU.
3+
FROM quay.io/ascend/vllm-ascend:v0.11.0rc2
4+
# Base image containing the LMDeploy inference environment, requiring ARM(AArch64) CPU + Ascend NPU.
5+
# FROM crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/ascend:mineru-a2
6+
7+
8+
# Install libgl for opencv support & Noto fonts for Chinese characters
9+
RUN apt-get update && \
10+
apt-get install -y \
11+
fonts-noto-core \
12+
fonts-noto-cjk \
13+
fontconfig \
14+
libgl1 \
15+
libglib2.0-0 && \
16+
fc-cache -fv && \
17+
apt-get clean && \
18+
rm -rf /var/lib/apt/lists/*
19+
20+
# Install mineru latest
21+
RUN python3 -m pip install -U pip -i https://mirrors.aliyun.com/pypi/simple && \
22+
python3 -m pip install 'mineru[core]>=2.6.5' \
23+
numpy==1.26.4 \
24+
opencv-python==4.11.0.86 \
25+
-i https://mirrors.aliyun.com/pypi/simple && \
26+
python3 -m pip cache purge
27+
28+
# Download models and update the configuration file
29+
RUN TORCH_DEVICE_BACKEND_AUTOLOAD=0 /bin/bash -c "mineru-models-download -s modelscope -m all"
30+
31+
# Set the entry point to activate the virtual environment and run the command line tool
32+
ENTRYPOINT ["/bin/bash", "-c", "export MINERU_MODEL_SOURCE=local && exec \"$@\"", "--"]

0 commit comments

Comments
 (0)