SuperAPI AI 工具集

physicalai-runtime-configuring-inference-pipeline

智能体与模型

查看项目

更新于 10-16 11:49

技能介绍

配置推理流水线

用途

本技能用于围绕 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/ 目录下。

使用方式

工作流程

  1. 阅读 manifest 中关于 preprocessors、postprocessors 和 model.runner 的部分。 完成标志:明确规格使用的是 type(注册表短名)还是 class_path。
  2. 对于 component_factory 中注册的内置组件,优先使用 type(例如文档中的 normalize/denormalize 模式)。
  3. 对于显式指定的类,使用 class_path + init_args:
preprocessors:
  - class_path: physicalai.inference.preprocessors.StatsNormalizer
    init_args:
      artifact: stats.safetensors

完成标志:init_args 中的路径通过 resolve_artifact 相对于导出目录解析。

新增内置处理器

  1. 在相应包中实现 Preprocessor / Postprocessor 的子类。
  2. 如需 manifest 友好的别名,在 component_factory 中注册一个短类型名。
  3. 在 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.md
  • docs/how-to/inference/use-manifest.md

限制

本技能专注于推理流水线的配置与校验,关于支持的模型类型、硬件平台、收费与价格等信息,暂未提供。