droboticflow/scripts/generate_operator_images.py
2026-07-06 20:07:20 +08:00

568 lines
32 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
from __future__ import annotations
import argparse
import importlib.util
import json
import pathlib
import sys
from typing import Any
ROOT = pathlib.Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
from operator_release_manifest import release_image_reference
CATALOG_PATH = ROOT / "internal" / "api" / "builtin_operators_catalog.json"
OPERATOR_ROOT = ROOT / "backend" / "operators" / "builtin"
OPERATOR_REPO_ROOT = ROOT / "operator-repos" / "builtin"
IMAGE_ROOT = ROOT / "operator-images" / "builtin"
MANIFEST_PATH = IMAGE_ROOT / "operator-images.json"
DEFAULT_REGISTRY = "ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc"
IMAGE_TAG = "builtin"
DEFAULT_OPERATOR_BASE_IMAGE = f"{DEFAULT_REGISTRY}/droboticflow-operator-runner:{IMAGE_TAG}"
DEFAULT_GPU_BASE_IMAGE = f"{DEFAULT_REGISTRY}/droboticflow-operator-gpu-base:{IMAGE_TAG}"
DEFAULT_HOLOBRAIN_BASE_IMAGE = f"{DEFAULT_REGISTRY}/droboticflow-operator-holobrain-base:{IMAGE_TAG}"
DEFAULT_YOLO_BASE_IMAGE = f"{DEFAULT_REGISTRY}/droboticflow-operator-yolo-base:{IMAGE_TAG}"
COMMAND_ENTRYPOINT = ["python", "/app/backend/operator-runner/main.py"]
GPU_SLUGS = {
"act_policy_train",
"diffusion_policy_train",
"holobrain_export",
"holobrain_inference_test",
"holobrain_robotwin_eval",
"holobrain_train",
"openvla_finetune",
"openvla_inference",
"yolo_embodied_detection_train",
"yolo_video_target_clip",
}
HOLOBRAIN_SLUGS = {
"holobrain_export",
"holobrain_inference_test",
"holobrain_robotwin_eval",
"holobrain_train",
}
REMOTE_GPU_SERVICE_SLUGS = {
"wilor_hand_pose",
}
COMMAND_WRAPPER_ALLOWED: set[str] = set()
CONTAINER_HANDLER_ALIASES = {
"builtin_source": "source",
"builtin_sim3d_asset_generate": "sim3d_asset_generate",
"builtin_vla_model_evaluate": "vla_model_evaluate",
"builtin_vla_model_inference": "vla_model_inference",
"builtin_vla_model_train": "vla_model_train",
"builtin_vla_sample_manifest_validate": "vla_sample_manifest_validate",
"builtin_lerobot_summary": "lerobot",
"builtin_rosbag_summary": "rosbag",
}
STRUCTURED_OPERATOR_OVERRIDES: dict[str, dict[str, Any]] = {
"operator-builtin-model-inference": {
"skillDefinition": "执行结构化模型推理节点;读取 MODEL_JSON 或 MODEL_PATH,支持 rule、linear、nearest_centroid 三类可解释模型;自定义命令请使用 Shell 命令算子,constant 等硬编码输出模型会被拒绝。",
},
"operator-builtin-act-policy-train": {
"skillDefinition": "ACT 策略训练算子;生产默认使用 Hugging Face LeRobot ACT 训练入口,读取 DATASET_REPO_ID 或 DATASET_PATH 指向的真实 LeRobot 数据集并输出 checkpoint 与 metrics。推荐 1 张 A800 80GB;仅本地单元测试可显式设置 TRAINING_BACKEND=torch_mlp。",
"hyperparams": [
{"key": "TRAINING_BACKEND", "value": "lerobot", "description": "生产训练后端;默认 lerobot,测试 fallback 才允许 torch_mlp", "type": "string"},
{"key": "DATASET_REPO_ID", "value": "", "description": "Hugging Face LeRobot 数据集 repo_id,例如 org/robot_dataset", "type": "string"},
{"key": "DATASET_PATH", "value": "", "description": "POC/PVC 中的真实 LeRobot 数据集根目录;与 DATASET_REPO_ID 至少提供一个", "type": "string"},
{"key": "POLICY_REPO_ID", "value": "", "description": "可选的 LeRobot policy repo_id,用于后续发布或复现实验", "type": "string"},
{"key": "MAX_STEPS", "value": "1000", "description": "短训最大 step 数,生产长训按数据规模调大", "type": "number"},
{"key": "BATCH_SIZE", "value": "8", "description": "训练 batch size", "type": "number"},
{"key": "LEARNING_RATE", "value": "0.0001", "description": "LeRobot optimizer.lr", "type": "number"},
{"key": "CHUNK_SIZE", "value": "100", "description": "ACT action chunk size", "type": "number"},
{"key": "LEROBOT_OVERRIDES_JSON", "value": "[]", "description": "额外 Hydra override 字符串数组,不允许 shell 命令", "type": "json"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-diffusion-policy-train": {
"skillDefinition": "Diffusion Policy 训练算子;生产默认使用 real-stanford/diffusion_policy 的 Hydra train.py,读取真实 Zarr/轨迹数据并输出 .ckpt、logs 和 metrics。推荐 1 张 A800 80GB;仅本地单元测试可显式设置 TRAINING_BACKEND=torch_mlp。",
"hyperparams": [
{"key": "TRAINING_BACKEND", "value": "diffusion_policy", "description": "生产训练后端;默认 diffusion_policy,测试 fallback 才允许 torch_mlp", "type": "string"},
{"key": "DIFFUSION_POLICY_ROOT", "value": "/opt/diffusion_policy", "description": "real-stanford/diffusion_policy 仓库路径", "type": "string"},
{"key": "DATASET_PATH", "value": "", "description": "真实 Zarr/轨迹数据路径,会作为 task.dataset.zarr_path 传入", "type": "string"},
{"key": "CONFIG_NAME", "value": "image_pusht_diffusion_policy_cnn", "description": "Hydra config name 或 config yaml 名称", "type": "string"},
{"key": "TASK_NAME", "value": "", "description": "可选 task override", "type": "string"},
{"key": "EPOCHS", "value": "1", "description": "短训 epoch 数,生产长训按数据规模调大", "type": "number"},
{"key": "BATCH_SIZE", "value": "8", "description": "训练 batch size", "type": "number"},
{"key": "LEARNING_RATE", "value": "0.0001", "description": "optimizer.lr", "type": "number"},
{"key": "HORIZON", "value": "16", "description": "预测 horizon", "type": "number"},
{"key": "DIFFUSION_STEPS", "value": "32", "description": "扩散步数配置,用于训练记录和下游复现", "type": "number"},
{"key": "HYDRA_OVERRIDES_JSON", "value": "[]", "description": "额外 Hydra override 字符串数组,不允许 shell 命令", "type": "json"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-openvla-finetune": {
"skillDefinition": "OpenVLA 微调算子;生产默认使用 OpenVLA 官方 vla-scripts/finetune.py 的 PEFT/LoRA 路径,读取真实 RLDS 数据集并输出 LoRA adapter artifact 与 metrics。推荐 1 张 A800 80GB。",
"hyperparams": [
{"key": "TRAINING_BACKEND", "value": "openvla_lora", "description": "生产训练后端;默认 openvla_lora,兼容测试可显式 transformers_text", "type": "string"},
{"key": "OPENVLA_ROOT", "value": "/opt/openvla", "description": "OpenVLA 仓库路径", "type": "string"},
{"key": "BASE_MODEL", "value": "openvla/openvla-7b", "description": "OpenVLA 基础模型路径或 HF 模型名", "type": "string"},
{"key": "DATA_ROOT_DIR", "value": "", "description": "真实 RLDS 数据集根目录", "type": "string"},
{"key": "DATASET_NAME", "value": "", "description": "RLDS 数据集名称,例如 droid_wipe", "type": "string"},
{"key": "MAX_STEPS", "value": "1000", "description": "短训最大 step 数,生产长训按数据规模调大", "type": "number"},
{"key": "SAVE_STEPS", "value": "500", "description": "checkpoint 保存间隔", "type": "number"},
{"key": "BATCH_SIZE", "value": "8", "description": "LoRA fine-tune batch size", "type": "number"},
{"key": "LEARNING_RATE", "value": "0.0005", "description": "LoRA 学习率", "type": "number"},
{"key": "LORA_RANK", "value": "32", "description": "LoRA rank", "type": "number"},
{"key": "USE_QUANTIZATION", "value": "false", "description": "是否启用 4-bit quantization", "type": "boolean"},
{"key": "PRECISION", "value": "bf16", "description": "推荐精度配置", "type": "string"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-openvla-inference": {
"skillDefinition": "OpenVLA 推理算子;使用 MODEL_PATH 或 BASE_MODEL 加载真实 Transformers 权重,读取 PROMPT 或上游样本 instruction,并输出 inference-result.json。推荐 1 张 A800,量化模型可降低显存。",
"hyperparams": [
{"key": "INFERENCE_BACKEND", "value": "openvla_transformers", "description": "推理后端;默认从 MODEL_PATH 或上游 fine-tune artifact 加载 OpenVLA/Transformers 权重", "type": "string"},
{"key": "MODEL_PATH", "value": "", "description": "本地模型目录或 Hugging Face 模型名;为空时自动消费上游模型 artifact", "type": "string"},
{"key": "BASE_MODEL", "value": "", "description": "未提供 MODEL_PATH 时使用的基础模型", "type": "string"},
{"key": "PROMPT", "value": "", "description": "推理 prompt;为空则从上游样本读取 TEXT_FIELD", "type": "string"},
{"key": "TEXT_FIELD", "value": "instruction", "description": "上游样本指令字段名", "type": "string"},
{"key": "MAX_NEW_TOKENS", "value": "64", "description": "生成 token 数", "type": "number"},
{"key": "PRECISION", "value": "bf16", "description": "推荐精度配置", "type": "string"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-holobrain-data-prepare": {
"skillDefinition": "HoloBrain 数据准备算子;下载或校验官方 RoboTwin 2.0 真实数据,将其映射为 RoboOrchardLab HoloBrain 训练期望的数据目录并输出 manifest。",
"hyperparams": [
{"key": "DATA_SOURCE", "value": "hf_snapshot", "description": "数据来源:hf_snapshot 或 local", "type": "string"},
{"key": "ROBOTWIN_HF_REPO", "value": "TianxingChen/RoboTwin2.0", "description": "官方 RoboTwin 2.0 Hugging Face dataset repo", "type": "string"},
{"key": "ALLOW_DOWNLOAD", "value": "true", "description": "允许从 Hugging Face 下载真实数据;关闭时仅校验本地路径", "type": "boolean"},
{"key": "ROBOTWIN_SOURCE_PATH", "value": "", "description": "本地 RoboTwin/HoloBrain 数据根目录;DATA_SOURCE=local 时必填", "type": "string"},
{"key": "EXPECTED_DATASETS_JSON", "value": "[\"aloha_agilex_demo_clean\",\"aloha_agilex_demo_randomized\",\"ur5_wsg_demo_clean\"]", "description": "期望发现的数据集目录名", "type": "json"},
{"key": "HF_ALLOW_PATTERNS_JSON", "value": "[]", "description": "可选 Hugging Face snapshot allow_patterns,空数组表示不过滤", "type": "json"},
{"key": "HF_IGNORE_PATTERNS_JSON", "value": "[]", "description": "可选 Hugging Face snapshot ignore_patterns", "type": "json"},
{"key": "HF_TOKEN", "value": "", "description": "可选 Hugging Face token", "type": "string"},
],
},
"operator-builtin-holobrain-train": {
"skillDefinition": "HoloBrain 完整训练算子;使用 RoboOrchardLab 官方 projects/holobrain/scripts/train.py 和 config_holobrain_qwen_common.py,默认执行 100000 step 全量训练并输出训练报告。",
"hyperparams": [
{"key": "ROBOORCHARDLAB_ROOT", "value": "/opt/RoboOrchardLab", "description": "RoboOrchardLab 仓库路径;不存在时可克隆", "type": "string"},
{"key": "ROBOORCHARDLAB_REF", "value": "master", "description": "克隆 RoboOrchardLab 时使用的分支或 tag", "type": "string"},
{"key": "CLONE_ROBOORCHARDLAB", "value": "true", "description": "容器内缺少仓库时是否自动 clone", "type": "boolean"},
{"key": "CONFIG_PATH", "value": "projects/holobrain/configs/config_holobrain_qwen_common.py", "description": "HoloBrain Qwen 训练配置", "type": "string"},
{"key": "ROBOTWIN_DATA_ROOT", "value": "", "description": "RoboTwin 数据根目录;为空时消费上游数据准备 manifest", "type": "string"},
{"key": "WORKSPACE", "value": "", "description": "训练 workspace;为空时使用节点输出目录下 holobrain-workspace", "type": "string"},
{"key": "LAUNCH_MODE", "value": "single", "description": "single 或 accelerate", "type": "string"},
{"key": "GPU_COUNT", "value": "1", "description": "accelerate 模式使用的进程/GPU 数", "type": "number"},
{"key": "CONFIG_KWARGS_JSON", "value": "{}", "description": "传给 train.py --kwargs 的 JSON;默认不覆盖 max_step=100000", "type": "json"},
{"key": "WANDB_MODE", "value": "offline", "description": "训练日志模式", "type": "string"},
{"key": "HF_TOKEN", "value": "", "description": "可选 Hugging Face token,用于模型/权重下载", "type": "string"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-holobrain-export": {
"skillDefinition": "HoloBrain 模型导出算子;消费训练 workspace/checkpoint,调用 RoboOrchardLab 官方 export.py 输出可部署模型目录和处理器配置。",
"hyperparams": [
{"key": "ROBOORCHARDLAB_ROOT", "value": "/opt/RoboOrchardLab", "description": "RoboOrchardLab 仓库路径", "type": "string"},
{"key": "CONFIG_PATH", "value": "projects/holobrain/configs/config_holobrain_qwen_common.py", "description": "HoloBrain Qwen 导出配置", "type": "string"},
{"key": "TRAINING_WORKSPACE", "value": "", "description": "训练 workspace;为空时消费上游训练报告", "type": "string"},
{"key": "CHECKPOINT_PATH", "value": "", "description": "显式 checkpoint 路径;为空时使用最新训练 checkpoint", "type": "string"},
{"key": "EXPORT_WORKSPACE", "value": "", "description": "导出目录;为空时使用节点输出目录下 holobrain-export", "type": "string"},
{"key": "CONFIG_KWARGS_JSON", "value": "{}", "description": "额外 export.py --kwargs JSON", "type": "json"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "export reload-test 使用 CUDA", "type": "string"},
],
},
"operator-builtin-holobrain-robotwin-eval": {
"skillDefinition": "HoloBrain RoboTwin 评测算子;消费导出的 HoloBrain 模型,调用官方 robotwin_eval.py 输出评测指标。",
"hyperparams": [
{"key": "ROBOORCHARDLAB_ROOT", "value": "/opt/RoboOrchardLab", "description": "RoboOrchardLab 仓库路径", "type": "string"},
{"key": "MODEL_DIR", "value": "", "description": "导出模型目录;为空时消费上游导出 manifest", "type": "string"},
{"key": "INFERENCE_PREFIX", "value": "robotwin2_0", "description": "导出 pipeline config prefix", "type": "string"},
{"key": "EVAL_MODE", "value": "ray", "description": "official eval mode:ray 或 local", "type": "string"},
{"key": "TASK_NAMES_JSON", "value": "[]", "description": "评测任务名数组;空数组使用官方默认 SEM_TASKS_16", "type": "json"},
{"key": "EPISODE_NUM", "value": "100", "description": "每任务 episode 数", "type": "number"},
{"key": "GPU_IDS_JSON", "value": "[0]", "description": "Ray 评测 GPU id 数组", "type": "json"},
{"key": "WORKERS_PER_GPU", "value": "1", "description": "每张 GPU 的并发 worker 数", "type": "number"},
{"key": "SAVE_VIDEO", "value": "false", "description": "是否保存评测视频", "type": "boolean"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-holobrain-inference-test": {
"skillDefinition": "HoloBrain 模型测试算子;消费导出模型和真实样本路径,校验导出 pipeline 文件和样本绑定,作为训练后推理烟测入口。",
"hyperparams": [
{"key": "MODEL_DIR", "value": "", "description": "导出模型目录;为空时消费上游导出 manifest", "type": "string"},
{"key": "SAMPLE_INPUT_PATH", "value": "", "description": "真实样本文件路径;为空时消费上游数据 manifest 的 sampleCandidates", "type": "string"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "完整推理测试推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-yolo-embodied-detection-train": {
"skillDefinition": "YOLO 具身目标检测训练算子;使用 Ultralytics API 读取真实 YOLO/COCO data.yaml,输出 best/last checkpoint 与 metrics.json。A800 对 YOLOv8/YOLOv10/YOLO11 中大模型训练充足,默认请求 1 卡。",
"hyperparams": [
{"key": "DATA_YAML", "value": "", "description": "真实 YOLO/COCO data.yaml 路径", "type": "string"},
{"key": "MODEL_SIZE", "value": "yolo11n.pt", "description": "Ultralytics 模型名或权重路径", "type": "string"},
{"key": "EPOCHS", "value": "10", "description": "训练轮数", "type": "number"},
{"key": "IMAGE_SIZE", "value": "640", "description": "输入图片尺寸", "type": "number"},
{"key": "BATCH_SIZE", "value": "8", "description": "训练 batch size", "type": "number"},
{"key": "WORKERS", "value": "0", "description": "数据加载 worker 数;K8s 默认共享内存较小时建议为 0", "type": "number"},
{"key": "CONF", "value": "0.25", "description": "后续检测推荐置信度", "type": "number"},
{"key": "TARGET_LABELS", "value": "", "description": "关注类别,逗号分隔", "type": "string"},
{"key": "RECOMMENDED_GPU", "value": "1x NVIDIA A800 80GB", "description": "推荐 GPU 配置", "type": "string"},
],
},
"operator-builtin-shell-command": {
"skillDefinition": "受控脚本算子;只允许执行算子目录 approved_scripts 中登记的生产验收脚本,不接受自由 COMMAND/SCRIPT。",
"hyperparams": [
{"key": "SCRIPT_ID", "value": "fixture_report", "description": "白名单脚本 ID", "type": "string"},
{"key": "SCRIPT_ARGS_JSON", "value": "{}", "description": "传给脚本的结构化 JSON 参数", "type": "json"},
{"key": "INPUT_PATHS_JSON", "value": "[]", "description": "允许脚本读取的输入路径 JSON 数组", "type": "json"},
{"key": "OUTPUT_CONTRACT_JSON", "value": "{}", "description": "脚本输出 artifact 契约", "type": "json"},
],
},
}
def load_repository_generator() -> Any:
path = ROOT / "scripts" / "generate_operator_repository_manifests.py"
spec = importlib.util.spec_from_file_location("operator_repository_generator", path)
if spec is None or spec.loader is None:
raise RuntimeError(f"cannot load {path}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
REPOSITORY_GENERATOR = load_repository_generator()
RUNTIME_DEPENDENCIES: dict[str, list[str]] = REPOSITORY_GENERATOR.RUNTIME_DEPENDENCIES
def load_json(path: pathlib.Path) -> Any:
return json.loads(path.read_text(encoding="utf-8"))
def dump_json(payload: Any) -> str:
return json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
def operator_slug(operator_id: str) -> str:
return operator_id.removeprefix("operator-builtin-").replace("-", "_")
def container_handler(item: dict[str, Any], slug: str) -> str:
handler = item.get("runtimeHandler") or slug
return str(handler)
def image_name(slug: str, registry: str = DEFAULT_REGISTRY) -> str:
return f"{registry}/droboticflow-operator-{slug.replace('_', '-')}:{IMAGE_TAG}"
def docker_base(slug: str) -> str:
if slug in HOLOBRAIN_SLUGS:
return "${OPERATOR_HOLOBRAIN_BASE_IMAGE}"
if slug.startswith("yolo_"):
return "${OPERATOR_YOLO_BASE_IMAGE}"
if slug in GPU_SLUGS:
return "${OPERATOR_GPU_BASE_IMAGE}"
return "${OPERATOR_BASE_IMAGE}"
def dockerfile(slug: str, operator_id: str, handler: str) -> str:
if slug not in GPU_SLUGS and not slug.startswith("yolo_"):
return f"""# Generated by scripts/generate_operator_images.py. Do not edit by hand.
ARG OPERATOR_BASE_IMAGE={DEFAULT_OPERATOR_BASE_IMAGE}
FROM ${{OPERATOR_BASE_IMAGE}}
ENV DROBOTICFLOW_OPERATOR_ID={operator_id} \\
DROBOTICFLOW_OPERATOR_SLUG={slug} \\
DROBOTICFLOW_OPERATOR_SOURCE=/app/operator-repos/builtin/{slug}/src/operator.py \\
DROBOTICFLOW_OPERATOR_REPOSITORY=/app/operator-repos/builtin/{slug} \\
DROBOTICFLOW_OPERATOR_HANDLER={handler}
COPY operator-repos/builtin/{slug} ./operator-repos/builtin/{slug}
ENTRYPOINT ["python", "/app/backend/operator-runner/main.py"]
"""
if slug in HOLOBRAIN_SLUGS:
base_arg = f"ARG OPERATOR_HOLOBRAIN_BASE_IMAGE={DEFAULT_HOLOBRAIN_BASE_IMAGE}"
elif slug.startswith("yolo_"):
base_arg = f"ARG OPERATOR_YOLO_BASE_IMAGE={DEFAULT_YOLO_BASE_IMAGE}"
else:
base_arg = f"ARG OPERATOR_GPU_BASE_IMAGE={DEFAULT_GPU_BASE_IMAGE}"
return f"""# Generated by scripts/generate_operator_images.py. Do not edit by hand.
{base_arg}
FROM {docker_base(slug)}
WORKDIR /app
ENV PYTHONUNBUFFERED=1 \\
PYTHONPATH=/app \\
DROBOTICFLOW_OPERATOR_ID={operator_id} \\
DROBOTICFLOW_OPERATOR_SLUG={slug} \\
DROBOTICFLOW_OPERATOR_SOURCE=/app/operator-repos/builtin/{slug}/src/operator.py \\
DROBOTICFLOW_OPERATOR_REPOSITORY=/app/operator-repos/builtin/{slug} \\
DROBOTICFLOW_OPERATOR_HANDLER={handler} \\
USER=droboticflow \\
LOGNAME=droboticflow \\
HOME=/tmp/droboticflow-home
RUN mkdir -p /tmp/droboticflow-home /workspace /outputs
COPY backend ./backend
COPY operator-repos/builtin/{slug} ./operator-repos/builtin/{slug}
ENTRYPOINT ["python", "/app/backend/operator-runner/main.py"]
"""
def gpu_base_dockerfile() -> str:
return """# Generated by scripts/generate_operator_images.py. Do not edit by hand.
FROM pytorch/pytorch:2.6.0-cuda12.4-cudnn9-runtime
WORKDIR /app
ENV PYTHONUNBUFFERED=1 \\
PYTHONPATH=/app \\
USER=droboticflow \\
LOGNAME=droboticflow \\
HOME=/tmp/droboticflow-home
RUN apt-get update && apt-get install -y --no-install-recommends \\
build-essential \\
ffmpeg \\
git \\
libglib2.0-0 \\
libgl1 \\
linux-libc-dev \\
python3-dev \\
&& rm -rf /var/lib/apt/lists/*
RUN printf 'torch==2.6.0\\ntorchvision==0.21.0\\n' > /tmp/gpu-constraints.txt
RUN python -m pip install --no-cache-dir -c /tmp/gpu-constraints.txt transformers accelerate safetensors nvidia-ml-py
RUN python -m pip install --no-cache-dir -c /tmp/gpu-constraints.txt lerobot peft draccus wandb hydra-core omegaconf zarr numcodecs dill einops diffusers
RUN git clone --depth=1 https://github.com/openvla/openvla.git /opt/openvla && \
git clone --depth=1 https://github.com/real-stanford/diffusion_policy.git /opt/diffusion_policy
RUN mkdir -p /tmp/droboticflow-home /workspace /outputs
"""
def holobrain_base_dockerfile() -> str:
return """# Generated by scripts/generate_operator_images.py. Do not edit by hand.
FROM pytorch/pytorch:2.6.0-cuda12.4-cudnn9-runtime
WORKDIR /app
ENV PYTHONUNBUFFERED=1 \\
PYTHONPATH=/app:/opt/RoboOrchardLab \\
USER=droboticflow \\
LOGNAME=droboticflow \\
HOME=/tmp/droboticflow-home \\
ROBOORCHARDLAB_ROOT=/opt/RoboOrchardLab
RUN apt-get update && apt-get install -y --no-install-recommends \\
build-essential \\
ffmpeg \\
git \\
libglib2.0-0 \\
libgl1 \\
linux-libc-dev \\
python3-dev \\
&& rm -rf /var/lib/apt/lists/*
RUN printf 'torch==2.6.0\\ntorchvision==0.21.0\\n' > /tmp/holobrain-constraints.txt
RUN python -m pip install --no-cache-dir -c /tmp/holobrain-constraints.txt \\
accelerate \\
diffusers \\
flask \\
gevent \\
h5py \\
huggingface_hub \\
imageio[ffmpeg] \\
lmdb \\
nvidia-ml-py \\
peft \\
safetensors \\
tensorboard \\
terminaltables \\
transformers
RUN git clone --depth=1 https://github.com/HorizonRobotics/RoboOrchardLab.git /opt/RoboOrchardLab && \\
cd /opt/RoboOrchardLab && \\
python -m pip install --no-cache-dir -c /tmp/holobrain-constraints.txt -e .
RUN mkdir -p /tmp/droboticflow-home /workspace /outputs
"""
def yolo_base_dockerfile() -> str:
return """# Generated by scripts/generate_operator_images.py. Do not edit by hand.
FROM ultralytics/ultralytics:latest
WORKDIR /app
ENV PYTHONUNBUFFERED=1 \\
PYTHONPATH=/app \\
USER=droboticflow \\
LOGNAME=droboticflow \\
HOME=/tmp/droboticflow-home
RUN python -m pip install --no-cache-dir nvidia-ml-py
RUN mkdir -p /tmp/droboticflow-home /workspace /outputs
"""
def contract_for(item: dict[str, Any], slug: str) -> dict[str, Any]:
dependencies = RUNTIME_DEPENDENCIES.get(slug, [])
gpu = slug in GPU_SLUGS
remote_gpu_service = slug in REMOTE_GPU_SERVICE_SLUGS
handler = container_handler(item, slug)
resource_contract: dict[str, Any] = {
"requiresGpu": gpu,
"recommendedGpuType": "NVIDIA A800 80GB" if gpu or remote_gpu_service else "",
"minGpuCount": 1 if gpu else 0,
}
if remote_gpu_service:
resource_contract["externalGpuService"] = True
contract = {
"schemaVersion": "droboticflow.operator.runtime/v1",
"operatorId": item["id"],
"operatorSlug": slug,
"handler": handler,
"entrypoint": "/app/backend/operator-runner/main.py",
"imagePolicy": {
"independentFinalImage": True,
"allowsSharedBaseLayer": True,
"forbidsSharedOperatorRunnerFinalImage": True,
},
"runtimeDependencies": dependencies,
"resources": resource_contract,
"parameters": {
"source": "hyperparams",
"structured": True,
"commandWrapperAllowed": False,
"controlledScriptAllowed": item["id"] == "operator-builtin-shell-command",
},
"artifacts": {
"requiresManifest": True,
"requiresChecksum": True,
"requiresLineage": True,
},
"acceptance": {
"requiresRealFixture": True,
"requiresFixtureChecksum": True,
"requiresArtifactChecksum": True,
"requiresWorkflowTransfer": True,
"requiresGpuEvidence": gpu or remote_gpu_service,
},
}
if slug == "holobrain_train":
contract["longRunning"] = True
return contract
def strip_disallowed_command_params(item: dict[str, Any]) -> dict[str, Any]:
if item["id"] in COMMAND_WRAPPER_ALLOWED:
return item
hyperparams = [
param
for param in item.get("hyperparams", [])
if str(param.get("key", "")).strip().upper() not in {"COMMAND", "SCRIPT"}
]
if len(hyperparams) != len(item.get("hyperparams", [])):
item = {**item, "hyperparams": hyperparams}
return item
def expected_catalog() -> list[dict[str, Any]]:
items = load_json(CATALOG_PATH)
next_items: list[dict[str, Any]] = []
for item in items:
if item.get("type") != "builtin":
next_items.append(item)
continue
slug = operator_slug(item["id"])
handler = item.get("runtimeHandler") or slug
next_item = strip_disallowed_command_params(dict(item))
overrides = STRUCTURED_OPERATOR_OVERRIDES.get(next_item["id"], {})
if "skillDefinition" in overrides:
next_item["skillDefinition"] = overrides["skillDefinition"]
if "hyperparams" in overrides:
next_item["hyperparams"] = overrides["hyperparams"]
next_item["image"], next_item["imageId"] = release_image_reference(slug)
next_item["containerCommand"] = COMMAND_ENTRYPOINT
next_item["containerArgs"] = []
next_item["runtimeSource"] = f"operator-repos/builtin/{slug}/src/operator.py"
next_item["runtimeContract"] = contract_for(next_item, slug)
next_items.append(next_item)
return next_items
def expected_files(catalog_items: list[dict[str, Any]]) -> dict[pathlib.Path, str]:
files: dict[pathlib.Path, str] = {}
manifest_items: list[dict[str, Any]] = []
files[IMAGE_ROOT / "gpu-base.Dockerfile"] = gpu_base_dockerfile()
files[IMAGE_ROOT / "holobrain-base.Dockerfile"] = holobrain_base_dockerfile()
files[IMAGE_ROOT / "yolo-base.Dockerfile"] = yolo_base_dockerfile()
for item in catalog_items:
if item.get("type") != "builtin":
continue
slug = operator_slug(item["id"])
metadata_path = OPERATOR_REPO_ROOT / slug / "operator.json"
if not metadata_path.exists():
raise RuntimeError(f"missing operator metadata for {item['id']}: {metadata_path.relative_to(ROOT)}")
handler = container_handler(item, slug)
files[OPERATOR_REPO_ROOT / slug / "Dockerfile"] = dockerfile(slug, item["id"], handler)
manifest_items.append(
{
"operatorId": item["id"],
"operatorSlug": slug,
"image": item["image"],
"imageId": item["imageId"],
"dockerfile": f"operator-repos/builtin/{slug}/Dockerfile",
"sourceRoot": f"operator-repos/builtin/{slug}",
"runtimeSource": f"operator-repos/builtin/{slug}/src/operator.py",
"runtimeHandler": handler,
"baseImage": docker_base(slug),
"dependencyProfile": RUNTIME_DEPENDENCIES.get(slug, []),
"requiresGpu": slug in GPU_SLUGS,
"containerCommand": COMMAND_ENTRYPOINT,
"containerArgs": [],
}
)
files[MANIFEST_PATH] = dump_json(
{
"schemaVersion": "droboticflow.operator-images/v1",
"registry": DEFAULT_REGISTRY,
"tag": IMAGE_TAG,
"items": sorted(manifest_items, key=lambda item: item["operatorId"]),
}
)
return files
def write_files(catalog_items: list[dict[str, Any]], files: dict[pathlib.Path, str]) -> None:
CATALOG_PATH.write_text(dump_json(catalog_items), encoding="utf-8")
for path, content in files.items():
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content, encoding="utf-8")
def check_files(catalog_items: list[dict[str, Any]], files: dict[pathlib.Path, str]) -> int:
mismatches: list[str] = []
expected_catalog_text = dump_json(catalog_items)
if CATALOG_PATH.read_text(encoding="utf-8") != expected_catalog_text:
mismatches.append(f"outdated {CATALOG_PATH.relative_to(ROOT)}")
for path, content in files.items():
if not path.exists():
mismatches.append(f"missing {path.relative_to(ROOT)}")
continue
if path.read_text(encoding="utf-8") != content:
mismatches.append(f"outdated {path.relative_to(ROOT)}")
if mismatches:
for mismatch in mismatches:
print(mismatch, file=sys.stderr)
return 1
return 0
def main() -> int:
parser = argparse.ArgumentParser(description="Generate or check independent builtin operator images.")
mode = parser.add_mutually_exclusive_group()
mode.add_argument("--write", action="store_true", help="write catalog image contracts and Dockerfiles")
mode.add_argument("--check", action="store_true", help="check generated catalog image contracts and Dockerfiles")
args = parser.parse_args()
catalog_items = expected_catalog()
files = expected_files(catalog_items)
if args.check:
return check_files(catalog_items, files)
write_files(catalog_items, files)
return 0
if __name__ == "__main__":
raise SystemExit(main())