Skip to content

Commit bf08c36

Browse files
committed
docs: align PDF example with programming model diagram
1 parent 6358d62 commit bf08c36

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

‎README-zh.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,62 @@ forward() 只会被追踪一次,用来构建静态图,不会在这里执行
9696
<img src="docs/assets/readme/paper-program-execution.svg" width="100%" alt="RayOrch 程序被编译为结构血缘和按 Call 管理的 Actor 执行" />
9797
</p>
9898

99+
可以把图从左到右对应到下面这段 PDF 解析管线:
100+
101+
```python
102+
import rayorch as ro
103+
from rayorch import F
104+
from rayorch.benchmarks.mineru.udfs import (
105+
MinerUAssembleDoc,
106+
MinerUPdfToPages,
107+
MinerUVlmOcrPage,
108+
PdfMetadata,
109+
)
110+
111+
112+
class PdfPipeline(ro.Pipeline):
113+
def __init__(self, model_path, output_dir):
114+
# Python 程序:声明阶段以及各阶段的物理执行策略。
115+
self.render = (
116+
ro.RayModule(MinerUPdfToPages)
117+
.pre_init(dpi=200)
118+
.ray_options(replicas=2, batch_size=1, num_cpus=1)
119+
)
120+
self.ocr = (
121+
ro.RayModule(MinerUVlmOcrPage)
122+
.pre_init(model=model_path, gpu_memory_utilization=0.8)
123+
.ray_options(replicas=2, batch_size=32, num_gpus=1, num_cpus=1)
124+
)
125+
self.metadata = ro.RayModule(PdfMetadata).ray_options(
126+
replicas=1, batch_size=32, num_cpus=1
127+
)
128+
self.assemble = (
129+
ro.RayModule(MinerUAssembleDoc)
130+
.pre_init(output_dir=output_dir)
131+
.ray_options(replicas=2, batch_size=4, num_cpus=1)
132+
)
133+
134+
def forward(self, pdfs):
135+
# 结构控制面:PDF -> 有序页面 Entity(1:M)。
136+
pages = F.expand(self.render(pdfs))
137+
contents = self.ocr(pages) # 物理工作在页面粒度执行(M)。
138+
stems = self.metadata(pdfs) # 元数据保持在文档粒度。
139+
140+
# 结构控制面:页面 -> 有序文档(M:1)。
141+
grouped_contents, grouped_pages = F.reduce_aligned(
142+
contents, pages, members=contents
143+
)
144+
return self.assemble(grouped_contents, grouped_pages, stems)
145+
```
146+
147+
图中的三层与代码对应如下:
148+
149+
1. **Python 程序。** `forward()` 组合普通的 `RayModule` 调用和 `F` 结构操作。它只会被追踪一次;构图期间不会执行 UDF。
150+
2. **结构控制面。** `F.expand` 记录每份 PDF 的有序页面成员关系;`F.reduce_aligned` 记录页面结果和页面记录如何回收到同一份文档。这些符号化 Port 携带血缘、顺序和就绪关系,但不会创建 Actor。
151+
3. **物理执行面。** `ray_options(...)` 配置 Actor 池。运行时,不同 PDF 中已经就绪的页面 `Grain` 可以在 OCR Actor 上共享一个执行微批次。物理批次可以变化,但控制面的血缘会保证每份文档的页面仍然独立且有序。
152+
153+
完整的 UDF 实现在 [`rayorch/benchmarks/mineru/udfs.py`](rayorch/benchmarks/mineru/udfs.py) 中;完整的可配置管线见 [`rayorch/benchmarks/mineru/pipeline.py`](rayorch/benchmarks/mineru/pipeline.py)。
154+
99155
公开模型由六部分组成:
100156

101157
| 对象 | 含义 |

‎README.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,62 @@ print(result.outputs) # [3, 4, 5]
9696
<img src="docs/assets/readme/paper-program-execution.svg" width="100%" alt="A RayOrch program lowered into structural lineage and per-Call actor execution" />
9797
</p>
9898

99+
Read the diagram from left to right through this concrete PDF parsing pipeline:
100+
101+
```python
102+
import rayorch as ro
103+
from rayorch import F
104+
from rayorch.benchmarks.mineru.udfs import (
105+
MinerUAssembleDoc,
106+
MinerUPdfToPages,
107+
MinerUVlmOcrPage,
108+
PdfMetadata,
109+
)
110+
111+
112+
class PdfPipeline(ro.Pipeline):
113+
def __init__(self, model_path, output_dir):
114+
# Python program: declare the stages and their physical policies.
115+
self.render = (
116+
ro.RayModule(MinerUPdfToPages)
117+
.pre_init(dpi=200)
118+
.ray_options(replicas=2, batch_size=1, num_cpus=1)
119+
)
120+
self.ocr = (
121+
ro.RayModule(MinerUVlmOcrPage)
122+
.pre_init(model=model_path, gpu_memory_utilization=0.8)
123+
.ray_options(replicas=2, batch_size=32, num_gpus=1, num_cpus=1)
124+
)
125+
self.metadata = ro.RayModule(PdfMetadata).ray_options(
126+
replicas=1, batch_size=32, num_cpus=1
127+
)
128+
self.assemble = (
129+
ro.RayModule(MinerUAssembleDoc)
130+
.pre_init(output_dir=output_dir)
131+
.ray_options(replicas=2, batch_size=4, num_cpus=1)
132+
)
133+
134+
def forward(self, pdfs):
135+
# Structural control plane: PDF -> ordered page Entities (1:M).
136+
pages = F.expand(self.render(pdfs))
137+
contents = self.ocr(pages) # Physical work is page-level (M).
138+
stems = self.metadata(pdfs) # Metadata stays at document scope.
139+
140+
# Structural control plane: pages -> ordered documents (M:1).
141+
grouped_contents, grouped_pages = F.reduce_aligned(
142+
contents, pages, members=contents
143+
)
144+
return self.assemble(grouped_contents, grouped_pages, stems)
145+
```
146+
147+
The three layers in the figure correspond to this code:
148+
149+
1. **Python program.** `forward()` composes ordinary `RayModule` calls and `F` operations. It is traced once; the UDFs do not run while the graph is being built.
150+
2. **Structural control plane.** `F.expand` records each PDF's ordered page membership. `F.reduce_aligned` records how page outputs and page records close back into the same document. These symbolic Ports carry lineage, order, and readiness; they do not create actors.
151+
3. **Physical execution plane.** The `ray_options(...)` values create the actor pools. At runtime, ready page `Grain`s from different PDFs can share one execution microbatch on the OCR actors. The physical batch may change, while the control-plane lineage keeps each document's pages separate and ordered.
152+
153+
The complete UDF implementations live in [`rayorch/benchmarks/mineru/udfs.py`](rayorch/benchmarks/mineru/udfs.py); the full configurable pipeline is [`rayorch/benchmarks/mineru/pipeline.py`](rayorch/benchmarks/mineru/pipeline.py).
154+
99155
The public model has six pieces:
100156

101157
| Object | Meaning |

0 commit comments

Comments
 (0)