配置推理流水线
用途
本技能用于围绕 InferenceModel 配置预处理器(preprocessors)、后处理器(postprocessors)和 runner,通过 manifest 规格与 ComponentRegistry 完成组装。适用于编辑推理流水线配置时使用。
流水线顺序为:观测(observation)→ 预处理器(preprocessors)→ runner → 后处理器(postprocessors)→ 动作输出(action output)。相关说明见 docs/how-to/inference/configure-pre-post-processing.md。
核心代码
src/physicalai/inference/component_factory.py— 包含ComponentRegistry、instantiate_component、_MAX_COMPONENT_DEPTH。src/physicalai/inference/model.py— 依据 manifest 规格构建处理器链。- 内置组件位于
preprocessors/和postprocessors/目录下;runner 位于runners/目录下。
使用方式
工作流程
- 阅读 manifest 中关于 preprocessors、postprocessors 和
model.runner的部分。 完成标志:明确规格使用的是type(注册表短名)还是class_path。 - 对于
component_factory中注册的内置组件,优先使用type(例如文档中的 normalize/denormalize 模式)。 - 对于显式指定的类,使用
class_path+init_args:
preprocessors:
- class_path: physicalai.inference.preprocessors.StatsNormalizer
init_args:
artifact: stats.safetensors
完成标志:init_args 中的路径通过 resolve_artifact 相对于导出目录解析。
新增内置处理器
- 在相应包中实现
Preprocessor/Postprocessor的子类。 - 如需 manifest 友好的别名,在
component_factory中注册一个短类型名。 - 在
tests/unit/inference/preprocessors/或postprocessors/下添加单元测试。
完成标志:使用 type 或 class_path 的 manifest 能在最小化的 InferenceModel 测试中完成实例化。
init_args 中的嵌套组件必须保持在 _MAX_COMPONENT_DEPTH 之内;避免出现循环规格。
验证循环
uv run pytest tests/unit/inference/preprocessors tests/unit/inference/postprocessors tests/unit/inference/test_manifest.py -q
必需检查
- 处理器顺序与训练/导出语义一致(归一化在 runner 之前,反归一化在 runner 之后)。
- manifest 中的产物文件名不得进行路径穿越(
..、绝对路径)。 - 新增的公开处理器在用户可见时需出现在
docs/reference/inference-api.md或 how-to 文档中。 - runner 选择(SinglePass、chunking runner 等)需与
predict_action_chunk及select_action文档保持一致。
参考
docs/reference/manifest-schema.mddocs/how-to/inference/use-manifest.md
限制
本技能专注于推理流水线的配置与校验,关于支持的模型类型、硬件平台、收费与价格等信息,暂未提供。