Ray Tutorial Builds an End-to-End AI Pipeline
A Juejin AI tutorial presents a runnable mini-ray example spanning data preparation, batch inference, training, online serving, observability, and fault-tolerance exercises. The article says the code requires only Python and NumPy without a GPU, then maps its components to production Ray libraries including Ray Data, Ray Train, Ray Serve, Ray Tune, and KubeRay; no independent runtime verification is provided.
The tutorial consolidates Ray’s core distributed-computing primitives into a single AI engineering workflow and identifies the production libraries that correspond to each stage.
把整本书的能力拼成一条真实流水线:数据准备 → 批量推理 → 训练 → 在线服务 → 可观测性 → 容错。 配套代码
mini-ray/examples/11_end_to_end.py,可以直接运行(纯 Python + NumPy,无需 GPU)。 每一节都给出「真实 Ray 里对应哪个组件」,所以这份案例可以直接迁移到生产栈。
E.1 案例全景
① 数据准备 4 个分片 → 清洗/特征化(任务链,依赖自动并行)
│
② 批量推理 ActorPool + 常驻模型(模型只加载一次)
│
③ 训练 放置组 + 参数服务器 + 数据并行 worker(资源原子性预留)
│
④ 在线服务 有状态推理端点(真实场景 = Ray Serve)
│
⑤ 可观测性 State API + timeline 甘特图
│
⑥ 容错演练 注入 worker 崩溃 + 丢弃全部对象,验证重试与 lineage 重建
| 阶段 | 真实 Ray 对应 | 本文用到的 Ray Core API |
|---|---|---|
| ① 数据准备 | Ray Data(read_* + map_batches) | @ray.remote、ObjectRef 依赖 |
| ② 批量推理 | Ray Data LLM:vLLMEngineProcessorConfig + build_processor | util.ActorPool、actor 常驻 |
| ③ 训练 | Ray Train(+ Ray Tune 调参) | 放置组、PlacementGroupSchedulingStrategy |
| ④ 在线服务 | Ray Serve / Ray Serve LLM | actor 方法调用 |
| ⑤ 可观测性 | ray.util.state + Dashboard + ray.timeline(⚠️ 真实 Ray 的 timeline(filename) 不接受 html=,见 E.6) | state.*、timeline()、timeline(..., html=)(后者是 mini-ray 专有) |
| ⑥ 容错 | 同样的机制(重试 / lineage 重建 / actor 重启) | max_retries、故障注入 |
#Ray#mini-ray#Ray Data#Ray Train#Ray Serve#Ray Tune#KubeRay#NumPy