physicalai-runtime-configuring-inference-pipeline

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Configuring the Inference Pipeline

配置推理管道

Pipeline order: observation → preprocessors → runner → postprocessors → action output. See
docs/how-to/inference/configure-pre-post-processing.md
.
Core code:
  • src/physicalai/inference/component_factory.py
    ComponentRegistry
    ,
    instantiate_component
    ,
    _MAX_COMPONENT_DEPTH
    .
  • src/physicalai/inference/model.py
    — builds processor chains from manifest specs.
  • Built-ins under
    preprocessors/
    and
    postprocessors/
    ; runners under
    runners/
    .
管道顺序:observation → 预处理器 → runner → 后处理器 → 动作输出。详见
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
    — 从清单规范构建处理器链。
  • 内置处理器位于
    preprocessors/
    postprocessors/
    目录下;运行器位于
    runners/
    目录下。

Workflow

工作流程

  1. Read the manifest slice for
    preprocessors
    ,
    postprocessors
    , and
    model.runner
    .
    • Done when: you know whether specs use
      type
      (registry short name) or
      class_path
      .
  2. Prefer
    type
    for built-ins
    registered in
    component_factory
    (e.g. normalize/denormalize patterns in docs).
  3. Use
    class_path
    +
    init_args
    for explicit classes:
    yaml
    preprocessors:
      - class_path: physicalai.inference.preprocessors.StatsNormalizer
        init_args:
          artifact: stats.safetensors
    • Done when:
      init_args
      paths resolve relative to the export directory via
      resolve_artifact
      .
  4. Add a new built-in processor:
    • Implement subclass of
      Preprocessor
      /
      Postprocessor
      in the appropriate package.
    • Register a short
      type
      name in
      component_factory
      if manifest-friendly aliases are needed.
    • Add unit tests under
      tests/unit/inference/preprocessors/
      or
      postprocessors/
      .
    • Done when: manifest using
      type
      or
      class_path
      instantiates in a minimal
      InferenceModel
      test.
  5. Nested components in
    init_args
    must stay within
    _MAX_COMPONENT_DEPTH
    ; avoid cyclic specs.
  1. 读取清单中
    preprocessors
    postprocessors
    model.runner
    的片段
    • 完成标志:明确规范是使用
      type
      (注册表简称)还是
      class_path
  2. 对于在
    component_factory
    中注册的内置处理器,优先使用
    type
    (例如文档中的归一化/反归一化模式)。
  3. 对于显式类,使用
    class_path
    +
    init_args
    yaml
    preprocessors:
      - class_path: physicalai.inference.preprocessors.StatsNormalizer
        init_args:
          artifact: stats.safetensors
    • 完成标志:
      init_args
      中的路径可通过
      resolve_artifact
      相对于导出目录解析。
  4. 添加新的内置处理器
    • 在对应包中实现
      Preprocessor
      /
      Postprocessor
      的子类。
    • 如果需要便于在清单中使用的别名,在
      component_factory
      中注册一个简短的
      type
      名称。
    • tests/unit/inference/preprocessors/
      postprocessors/
      目录下添加单元测试。
    • 完成标志:使用
      type
      class_path
      的清单可在最小化
      InferenceModel
      测试中实例化。
  5. init_args
    中的嵌套组件必须保持在
    _MAX_COMPONENT_DEPTH
    范围内;避免循环规范。

Validation loop

验证循环

bash
uv run pytest tests/unit/inference/preprocessors tests/unit/inference/postprocessors tests/unit/inference/test_manifest.py -q
bash
uv run pytest tests/unit/inference/preprocessors tests/unit/inference/postprocessors tests/unit/inference/test_manifest.py -q

Required checks

必要检查

  • Processor order matches training/export semantics (normalization before runner, denormalization after).
  • Artifact file names in manifests do not traverse paths (
    ..
    , absolute paths).
  • New public processors appear in
    docs/reference/inference-api.md
    or how-to docs when user-visible.
  • Runner choice (
    SinglePass
    , chunking runners) stays consistent with
    predict_action_chunk
    vs
    select_action
    docs.
  • 处理器顺序需与训练/导出语义一致(归一化在runner之前,反归一化在runner之后)。
  • 清单中的 artifact 文件名不得包含路径遍历(
    ..
    、绝对路径)。
  • 新的公共处理器若对用户可见,需添加到
    docs/reference/inference-api.md
    或操作指南文档中。
  • 运行器的选择(
    SinglePass
    、分块运行器)需与
    predict_action_chunk
    select_action
    文档保持一致。

References

参考资料

  • docs/reference/manifest-schema.md
  • docs/how-to/inference/use-manifest.md
  • docs/reference/manifest-schema.md
  • docs/how-to/inference/use-manifest.md