memect-ppx 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. memect_ppx-0.0.1/LICENSE +165 -0
  2. memect_ppx-0.0.1/PKG-INFO +301 -0
  3. memect_ppx-0.0.1/README.md +257 -0
  4. memect_ppx-0.0.1/pyproject.toml +121 -0
  5. memect_ppx-0.0.1/setup.cfg +4 -0
  6. memect_ppx-0.0.1/src/memect/__init__.py +4 -0
  7. memect_ppx-0.0.1/src/memect/app.py +303 -0
  8. memect_ppx-0.0.1/src/memect/base/__init__.py +0 -0
  9. memect_ppx-0.0.1/src/memect/base/api.py +75 -0
  10. memect_ppx-0.0.1/src/memect/base/bbox.py +795 -0
  11. memect_ppx-0.0.1/src/memect/base/config.py +394 -0
  12. memect_ppx-0.0.1/src/memect/base/debug.py +290 -0
  13. memect_ppx-0.0.1/src/memect/base/images.py +301 -0
  14. memect_ppx-0.0.1/src/memect/base/job.py +398 -0
  15. memect_ppx-0.0.1/src/memect/base/lists.py +288 -0
  16. memect_ppx-0.0.1/src/memect/base/matrix.py +309 -0
  17. memect_ppx-0.0.1/src/memect/base/pdfs.py +103 -0
  18. memect_ppx-0.0.1/src/memect/base/sdk.py +288 -0
  19. memect_ppx-0.0.1/src/memect/base/task.py +732 -0
  20. memect_ppx-0.0.1/src/memect/base/test.py +51 -0
  21. memect_ppx-0.0.1/src/memect/base/utils.py +330 -0
  22. memect_ppx-0.0.1/src/memect/base/zip.py +171 -0
  23. memect_ppx-0.0.1/src/memect/cli.py +244 -0
  24. memect_ppx-0.0.1/src/memect/conf/__init__.py +0 -0
  25. memect_ppx-0.0.1/src/memect/conf/log.default.py +154 -0
  26. memect_ppx-0.0.1/src/memect/conf/settings.custom.py +4 -0
  27. memect_ppx-0.0.1/src/memect/conf/settings.default.py +600 -0
  28. memect_ppx-0.0.1/src/memect/nvidia_path.py +56 -0
  29. memect_ppx-0.0.1/src/memect/pdf/__init__.py +0 -0
  30. memect_ppx-0.0.1/src/memect/pdf/backup/formula_model.py +95 -0
  31. memect_ppx-0.0.1/src/memect/pdf/backup/layout.py +65 -0
  32. memect_ppx-0.0.1/src/memect/pdf/backup/otsl_ai.py +281 -0
  33. memect_ppx-0.0.1/src/memect/pdf/backup/watermark.py +481 -0
  34. memect_ppx-0.0.1/src/memect/pdf/base.py +2486 -0
  35. memect_ppx-0.0.1/src/memect/pdf/chars.py +1416 -0
  36. memect_ppx-0.0.1/src/memect/pdf/commons.py +86 -0
  37. memect_ppx-0.0.1/src/memect/pdf/default/footer.py +10 -0
  38. memect_ppx-0.0.1/src/memect/pdf/default/footnote.py +11 -0
  39. memect_ppx-0.0.1/src/memect/pdf/default/header.py +11 -0
  40. memect_ppx-0.0.1/src/memect/pdf/default/parser.py +601 -0
  41. memect_ppx-0.0.1/src/memect/pdf/default/pdf.py +269 -0
  42. memect_ppx-0.0.1/src/memect/pdf/default/pdf_pdfoxide.py +130 -0
  43. memect_ppx-0.0.1/src/memect/pdf/default/pdf_pymupdf.py +1193 -0
  44. memect_ppx-0.0.1/src/memect/pdf/default/table/_wbk.py +52 -0
  45. memect_ppx-0.0.1/src/memect/pdf/default/table/_wbk_ai.py +906 -0
  46. memect_ppx-0.0.1/src/memect/pdf/default/table/_wbk_default.py +2640 -0
  47. memect_ppx-0.0.1/src/memect/pdf/default/table/_wbk_default2.py +2429 -0
  48. memect_ppx-0.0.1/src/memect/pdf/default/table/_wbk_locator.py +2526 -0
  49. memect_ppx-0.0.1/src/memect/pdf/default/table/_wtable.py +2364 -0
  50. memect_ppx-0.0.1/src/memect/pdf/default/table/auto.py +56 -0
  51. memect_ppx-0.0.1/src/memect/pdf/default/table/line.py +637 -0
  52. memect_ppx-0.0.1/src/memect/pdf/default/table/llm.py +142 -0
  53. memect_ppx-0.0.1/src/memect/pdf/default/table/parser.py +88 -0
  54. memect_ppx-0.0.1/src/memect/pdf/default/table/wbk.py +36 -0
  55. memect_ppx-0.0.1/src/memect/pdf/default/table/ybk.py +111 -0
  56. memect_ppx-0.0.1/src/memect/pdf/default/tree/parser.py +10 -0
  57. memect_ppx-0.0.1/src/memect/pdf/docx.py +38 -0
  58. memect_ppx-0.0.1/src/memect/pdf/font.py +508 -0
  59. memect_ppx-0.0.1/src/memect/pdf/fonts/__init__.py +9 -0
  60. memect_ppx-0.0.1/src/memect/pdf/fonts/tool.py +103 -0
  61. memect_ppx-0.0.1/src/memect/pdf/grid.py +590 -0
  62. memect_ppx-0.0.1/src/memect/pdf/html/__init__.py +4 -0
  63. memect_ppx-0.0.1/src/memect/pdf/html/renderer.py +2020 -0
  64. memect_ppx-0.0.1/src/memect/pdf/llm/deepseek.py +241 -0
  65. memect_ppx-0.0.1/src/memect/pdf/llm/glm.py +421 -0
  66. memect_ppx-0.0.1/src/memect/pdf/llm/llm.py +223 -0
  67. memect_ppx-0.0.1/src/memect/pdf/llm/mineru.py +0 -0
  68. memect_ppx-0.0.1/src/memect/pdf/llm/paddle.py +408 -0
  69. memect_ppx-0.0.1/src/memect/pdf/model.py +885 -0
  70. memect_ppx-0.0.1/src/memect/pdf/otsl.py +223 -0
  71. memect_ppx-0.0.1/src/memect/pdf/parser.py +332 -0
  72. memect_ppx-0.0.1/src/memect/pdf/patch_table_cls.py +48 -0
  73. memect_ppx-0.0.1/src/memect/pdf/pdf2image.py +561 -0
  74. memect_ppx-0.0.1/src/memect/pdf/plane.py +185 -0
  75. memect_ppx-0.0.1/src/memect/pdf/pptx.py +663 -0
  76. memect_ppx-0.0.1/src/memect/pdf/service.py +456 -0
  77. memect_ppx-0.0.1/src/memect/pdf/sort.py +92 -0
  78. memect_ppx-0.0.1/src/memect/pdf/vline.py +1072 -0
  79. memect_ppx-0.0.1/src/memect/pdf/watermark.py +481 -0
  80. memect_ppx-0.0.1/src/memect/pdf/wingdings.py +907 -0
  81. memect_ppx-0.0.1/src/memect/web/__init__.py +0 -0
  82. memect_ppx-0.0.1/src/memect_ppx.egg-info/PKG-INFO +301 -0
  83. memect_ppx-0.0.1/src/memect_ppx.egg-info/SOURCES.txt +86 -0
  84. memect_ppx-0.0.1/src/memect_ppx.egg-info/dependency_links.txt +1 -0
  85. memect_ppx-0.0.1/src/memect_ppx.egg-info/entry_points.txt +2 -0
  86. memect_ppx-0.0.1/src/memect_ppx.egg-info/requires.txt +40 -0
  87. memect_ppx-0.0.1/src/memect_ppx.egg-info/top_level.txt +2 -0
  88. memect_ppx-0.0.1/src/ppx.py +6 -0
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,301 @@
1
+ Metadata-Version: 2.4
2
+ Name: memect-ppx
3
+ Version: 0.0.1
4
+ Summary: memect-ppx 是一个 PDF / 图片文档解析工具,将输入文件转换为结构化的 Markdown、JSON。支持本地模型(默认)和多种 LLM 后端(DeepSeek、PaddleOCR、GLM等),适用于高精度文档理解场景。
5
+ Requires-Python: >=3.12
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: anyio>=4.12.1
9
+ Requires-Dist: beautifulsoup4>=4.14.3
10
+ Requires-Dist: concurrent-log-handler>=0.9.29
11
+ Requires-Dist: fastapi>=0.135.1
12
+ Requires-Dist: filetype>=1.2.0
13
+ Requires-Dist: fonttools>=4.62.1
14
+ Requires-Dist: freetype-py>=2.5.1
15
+ Requires-Dist: httpx[brotli,http2,socks]>=0.28.1
16
+ Requires-Dist: openai>=2.29.0
17
+ Requires-Dist: orjson>=3.11.7
18
+ Requires-Dist: pdf-oxide>=0.3.17
19
+ Requires-Dist: pillow>=12.1.1
20
+ Requires-Dist: pptx-ea-font>=0.0.4
21
+ Requires-Dist: pydantic>=2.12.5
22
+ Requires-Dist: pymupdf>=1.27.2
23
+ Requires-Dist: pypdf>=6.9.1
24
+ Requires-Dist: python-multipart>=0.0.22
25
+ Requires-Dist: python-pptx>=1.0.2
26
+ Requires-Dist: rapid-layout>=1.2.1
27
+ Requires-Dist: rapidocr>=3.8.1
28
+ Requires-Dist: rich>=14.3.3
29
+ Requires-Dist: shapely>=2.1.2
30
+ Requires-Dist: table-cls>=1.2.0
31
+ Requires-Dist: typer>=0.24.1
32
+ Requires-Dist: uvicorn[standard]>=0.42.0
33
+ Requires-Dist: openvino==2025.4.1; sys_platform == "darwin" and platform_machine == "x86_64"
34
+ Requires-Dist: openvino; sys_platform != "darwin" or platform_machine != "x86_64"
35
+ Provides-Extra: cuda
36
+ Requires-Dist: nvidia-cuda-runtime-cu12; extra == "cuda"
37
+ Requires-Dist: nvidia-cudnn-cu12; extra == "cuda"
38
+ Requires-Dist: nvidia-cublas-cu12; extra == "cuda"
39
+ Requires-Dist: nvidia-cufft-cu12; extra == "cuda"
40
+ Requires-Dist: nvidia-curand-cu12; extra == "cuda"
41
+ Requires-Dist: nvidia-cuda-nvrtc-cu12; extra == "cuda"
42
+ Requires-Dist: nvidia-nvjpeg-cu12; extra == "cuda"
43
+ Dynamic: license-file
44
+
45
+ # 说明
46
+
47
+ ## 系统要求
48
+
49
+ | 平台 | 要求 |
50
+ |------|------|
51
+ | Linux | Ubuntu **>= 20.04**(推荐 22.04 / 24.04),Python >= 3.12 |
52
+ | macOS (Apple Silicon) | Python >= 3.12 |
53
+ | macOS (Intel) | Python 3.12 ~ 3.13(受 OpenVINO 限制) |
54
+
55
+ > GPU 加速需要 NVIDIA 驱动 + CUDA 12.x,并安装 `onnxruntime-gpu` 及 `memect-ppx[cuda]`。
56
+
57
+ ## 安装
58
+
59
+ ```bash
60
+ #>=3.12
61
+ $uv venv -p 3.12
62
+ $source .venv/bin/activate
63
+
64
+ #如果是在已经存在的环境中,建议先删除
65
+ #$uv pip uninstall opencv-python opencv-contrib-python opencv-contrib-headless opencv-contrib-python-headless
66
+ #$uv pip uninstall onnxruntime onnxruntime-gpu
67
+
68
+ #or opencv-contrib-python-headless
69
+ $uv pip install opencv-contrib-python --no-config
70
+
71
+ #cpu版本
72
+ $uv pip install memect-ppx
73
+ $uv pip install onnxruntime --no-config
74
+
75
+ #gpu版本
76
+ #安装依赖的cuda库,如果系统中已经全局安装,可以不安装,需要和onnxruntime-gpu的一致
77
+ #如果是其他版本,请根据onnxruntime-gpu的要求安装几个
78
+ $uv pip install memect-ppx[cuda]
79
+ #这个必须安装
80
+ $uv pip install onnxruntime-gpu --no-config
81
+
82
+
83
+ #安装方法二
84
+ $git clone
85
+ $cd ppx
86
+ $uv venv -p 3.12
87
+ $uv sync --no-install-project
88
+ #如果需要使用gpu,如果系统中已经全局安装,可以不安装,或者安装另外的版本
89
+ $uv sync --extra cuda
90
+
91
+ #这两个必须手动安装
92
+ #or opencv-contrib-python-headless
93
+ $uv pip install opencv-contrib-python --no-config
94
+ #or onnxruntime-gpu
95
+ $uv pip install onnxruntime --no-config
96
+
97
+
98
+
99
+ #默认解析
100
+ $./app parse a.pdf
101
+
102
+ #使用大模型解析,如果模型的base_url,model,api_key 和默认设置不一样,可以在命令行中指定,或者在./conf/settings.py中
103
+ $./app parse a.pdf --backend deepseek --deepseek '{"base_url":"http://127.0.0.1:4000/v1","model":"deepseek-ocr-2","api_key":""}'
104
+ $./app parse a.pdf --backend paddle --paddle '{"base_url":"http://127.0.0.1:4001/v1","model":"paddleocr-vl","api_key":""}'
105
+ $./app parse a.pdf --backend glm --glm '{"base_url":"http://127.0.0.1:4002/v1","model":"glmocr","api_key":""}'
106
+
107
+
108
+ #如果经常使用,可以写到配置文件中
109
+ $mkdir conf
110
+ #可以为json文件或者py文件: settings={}
111
+ #参考src/memect/conf/settings.custom.py 语法
112
+ $vi conf/settings.py
113
+ $vi conf/log.py
114
+
115
+ #如果在配置文件中写好了路径和模型等,就不需要在命令行再指定
116
+ $ppx parse a.pdf --backend deepseek
117
+ ```
118
+
119
+ ```bash
120
+ $git clone
121
+ #mac intel,且需要使用onnxruntime等,只能够使用3.12<=python<=3.13
122
+ #linux或者mac m,使用>=3.12
123
+ $uv venv -p 3.12
124
+ #uv的其它操作,都是对默认的环境:.venv,即使激活了一个环境,也需要"--active"参数
125
+ #而pip操作,为了和pip兼容,会安装到激活环境,或者通过"-p",UV_PYTHON=xxx等来设置
126
+
127
+ #目前还是使用requirements.txt安装依赖更加方便,虽然uv支持了很多的冲突处理,但是
128
+ #还不够,还无法快速的解决多个同名包的冲突
129
+
130
+ $source .venv/bin/activate
131
+ $uv pip install requirements.txt
132
+ #因为opencv,onnxruntime,torch可能被第三方库指定了不同的版本,如:headless/contrib,cpu/gpu
133
+ #所以这里统一先清除,再安装
134
+ $uv pip uninstall -r requirements.uninstall.txt
135
+ #安装cpu或者cuda一个即可
136
+ $uv pip install -r requirements.cpu.txt
137
+ $uv pip install -r requirements.cuda.txt
138
+ $uv pip install -r requirements.opencv.txt
139
+
140
+ $./app start
141
+
142
+ #解析pdf,pdf+ocr(自动)
143
+ ./app parse a.pdf
144
+
145
+ #解析pdf,总是使用ocr
146
+ ./app parse a.pdf --ocr yes
147
+
148
+ #解析pdf,不使用ocr
149
+ ./app parse a.pdf --ocr no
150
+
151
+ #解析图片
152
+ ./app parse 1.png
153
+
154
+ #指定使用哪个llm:deepseek,paddle,glm,对于文本,没有每个字符的坐标
155
+ ./app parse 1.pdf --backend deepseek
156
+
157
+ #常用配置可以通过命令行参数或者环境变量,或者本地文件,如:
158
+ #本地文件,目录为:./conf/settings.py, ./conf/log.py
159
+ #常用参数
160
+ $./app parse 1.pdf --set xx.xx.xx=1
161
+ $./app parse 1.pdf --backend deepseek --url http://127.0.0.1:/1111/v1
162
+ $./app parse 1.pdf --backend glm --url http://127.0.0.1:1111/v1
163
+ $./app parse 1.pdf --backend paddle --url http://127.0.0.1:1111/v1
164
+
165
+ #解析目录下的所有pdf或者图片,如果没有
166
+ $./app parse dir1
167
+
168
+ #输出到这个目录
169
+ $./app parse dir1 -o dir2
170
+
171
+ #表示dir1目录下的所有图片作为一个整体解析,也就是连续的多个页面
172
+ $./app parse dir1 --images
173
+
174
+
175
+ ```
176
+
177
+ ## Docker Compose
178
+
179
+ ```bash
180
+ #
181
+ $cd x2x
182
+ #日常操作就3个:build,up,push,其他用户:pull,up
183
+ #注意:这里是自动获得日期,如:20260324,也可以手动指定一个
184
+ #重新构建所有的镜像
185
+ $TAG=$(date +%Y%m%d) docker compose build
186
+ #apiserver,deepseek,paddle,glm
187
+ $TAG=$(date +%Y%m%d) docker compose build apiserver
188
+
189
+ #注意切换TAG为指定日前
190
+ #推送到hub
191
+ $TAG=20260324 docker compose push apiserver deepseek
192
+
193
+ #其他用户需要先pull
194
+ $TAG=20260324 docker compose pull apiserver deepseek
195
+
196
+ #启动apiserver
197
+ #注意:需要指定具体的版本(日期),否则会自动build
198
+ $TAG=20260324 docker compose up apiserver
199
+ #启动apiserver+deepseek
200
+ $TAG=20260324 docker compose up apiserver deepseek
201
+
202
+ #可以通过".env"修改设置,如果使用其它的文件名,需要--env-file ./.env.my
203
+ $cp .env.sample .env
204
+ ```
205
+
206
+ ## Docker Build
207
+
208
+ 如果想单独操作单个docker的,通过"-t"可以指定名字,也可以使用和docker compose中的一致,
209
+ 这里就使用简单的名字了,因为主要是本地测试,通过tag也可以方便修改
210
+
211
+ ```bash
212
+ #docker>=23 如果是<23,使用docker buildx build
213
+ $docker build --target apiserver -t x2x-apiserver .
214
+ #后面这些是可选择的,使用其它方式部署模型也可以,如果是使用docker compose,使用这些会更好
215
+ $docker build --target deepseek -t x2x-deepseek .
216
+ $docker build --target paddle -t x2x-paddle .
217
+ $docker build --target glm -t x2x-glm .
218
+
219
+ $docker build --target llm -t x2x-llm .
220
+
221
+ ```
222
+
223
+ ## Docker Run
224
+
225
+ ```bash
226
+ #使用docker run 启动单个服务,可以把"--it"替换为"-d"
227
+ #--gpus "device=0" => 容器仅仅可以看到0这个gpu,也就是nvidia-smi只看到0
228
+ #-e NVIDIA_VISIBLE_DEVICES=0 => 在容器限制,仅仅在docker下可用
229
+ #-e CUDA_VISIBLE_DEVICES=0 => 在应用层限制,实际使用上两张并没有什么区别,个人建议还是使用这个
230
+
231
+
232
+ #启动apiserver,有内部模型,可以指定使用gpu或者cpu
233
+ #默认的配置都是使用127.0.0.1
234
+ #方案1,使用host网络,不需要修改任何配置
235
+ #--network host
236
+ #方案2,创建网络,对于这种,建议使用docker compose完成了
237
+
238
+ $docker run --gpus all -it --rm -p 9527:9527 x2x-apiserver
239
+
240
+ #使用cpu
241
+ $docker run -it --rm -p 9527:9527 x2x-apiserver
242
+
243
+ #启动大模型,可以通过环境变量控制gpu的映射
244
+ #常用的命令参数,如:控制显存,同时启动多个实体
245
+ #--gpu-memory-utilization 0.5 -dp 2
246
+ $docker run --gpus all -it --rm -p 4000:4000 x2x-deepseek
247
+ $docker run --gpus all -it --rm -p 4001:4001 x2x-paddle
248
+ $docker run --gpus all -it --rm -p 4002:4002 x2x-glm
249
+ #可以把模型下载在外部,然后启动
250
+ $docker run --gpus all -it --rm -p 4003:4003 -v ./hub:/apps/llm/hub x2x-llm vllm serve ...
251
+
252
+ ```
253
+
254
+ ## 启动模型
255
+
256
+ ```bash
257
+
258
+ #常用环境变量,可以附加在命令前面
259
+ $export CUDA_VISIBLE_DEVICES=0
260
+
261
+ #需要大概20G
262
+ $vllm serve ./hub/deepseek-ai/DeepSeek-OCR-2 --served-model-name deepseek-ocr-2 \
263
+ --logits-processors vllm.model_executor.models.deepseek_ocr:NGramPerReqLogitsProcessor \
264
+ --mm-processor-cache-gb 0 \
265
+ --no-enable-prefix-caching \
266
+ --port 4000 \
267
+ --gpu-memory-utilization 0.8
268
+
269
+
270
+ #需要10G
271
+ $vllm serve ./hub/PaddlePaddle/PaddleOCR-VL \
272
+ --served-model-name paddleocr-vl \
273
+ --trust-remote-code \
274
+ --max-num-batched-tokens 16384 \
275
+ --no-enable-prefix-caching \
276
+ --mm-processor-cache-gb 0 \
277
+ --gpu-memory-utilization 0.5\
278
+ --port 4001
279
+
280
+ #需要10G
281
+ #也可以启动1.5版本,模型名字,端口号等都一样,配置等就都不需要改变
282
+ $vllm serve ./hub/PaddlePaddle/PaddleOCR-VL-1.5 \
283
+ --served-model-name paddleocr-vl \
284
+ --trust-remote-code \
285
+ --max-num-batched-tokens 16384 \
286
+ --no-enable-prefix-caching \
287
+ --mm-processor-cache-gb 0 \
288
+ --gpu-memory-utilization 0.5\
289
+ --port 4001
290
+
291
+ #https://modelscope.cn/models/ZhipuAI/GLM-OCR
292
+ #需要手动更新为这个,以后vllm的依赖大于这个就不需要手动了
293
+ $uv pip install "transformers>=5.3.0"
294
+ $vllm serve ./hub/ZhipuAI/GLM-OCR \
295
+ --served-model-name glmocr \
296
+ --max-num-batched-tokens 16384 \
297
+ --max-model-len 16384 \
298
+ --speculative-config '{"method": "mtp", "num_speculative_tokens": 1}' \
299
+ --gpu-memory-utilization 0.5 \
300
+ --port 4002
301
+ ```