You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure ML SDK V2中如何将管道发布为可调用端点?

在Azure ML SDK V2中发布管道为可调用端点

SDK V2确实没有直接对应V1的pipeline.publish()方法,但可以通过创建管道作业并部署为批量端点实现按需调用、无需调度的需求,具体操作步骤如下:

步骤1:定义并验证管道

先构建并验证你的管道结构(以组件组合为例):

from azure.ai.ml import Pipeline, Input
from azure.ai.ml.components import load_component

# 加载自定义组件
prep_component = load_component(source="./prep_component.yml")
train_component = load_component(source="./train_component.yml")

# 构建管道逻辑
@pipeline()
def my_pipeline(input_data: Input(type="uri_folder")):
    prep_step = prep_component(input_data=input_data)
    train_step = train_component(input_data=prep_step.outputs.output_data)
    return {"model_output": train_step.outputs.model_output}

# 创建管道实例并验证
pipeline_instance = my_pipeline(input_data=Input(path="./data"))

步骤2:创建批量端点

批量端点是SDK V2中实现管道按需调用的核心载体,先创建端点:

from azure.ai.ml.entities import BatchEndpoint

# 初始化批量端点
endpoint = BatchEndpoint(
    name="my-pipeline-batch-endpoint",
    description="用于按需触发的管道批量端点",
)
# 创建/更新端点
ml_client.batch_endpoints.begin_create_or_update(endpoint).result()

步骤3:部署管道到批量端点

将定义好的管道关联到批量端点完成部署:

from azure.ai.ml.entities import BatchDeployment, PipelineComponent

# 将管道转为可部署的组件
pipeline_component = PipelineComponent(
    name="my-pipeline-component",
    pipeline=pipeline_instance,
    description="自定义训练推理管道",
)
ml_client.components.create_or_update(pipeline_component)

# 创建部署配置
deployment = BatchDeployment(
    name="my-pipeline-deployment",
    endpoint_name="my-pipeline-batch-endpoint",
    component=pipeline_component,
    compute="cpu-cluster",  # 指定运行管道的计算集群
    instance_count=2,
)
# 完成部署
ml_client.batch_deployments.begin_create_or_update(deployment).result()

步骤4:按需调用端点

部署完成后,即可在需要时触发管道执行:

# 触发管道作业
job = ml_client.batch_endpoints.invoke(
    endpoint_name="my-pipeline-batch-endpoint",
    deployment_name="my-pipeline-deployment",
    inputs={"input_data": Input(path="./new_input_data")},
)

# 查看作业状态
print(f"作业ID: {job.name}")
print(f"当前状态: {job.status}")

关键说明

  • 批量端点默认支持按需触发,完全满足“无需调度、按需调用”的需求,后续也可按需添加调度规则。
  • 若需实时推理场景,可将管道包装为在线端点,但批量端点更适配批量处理类的管道作业。

内容的提问来源于stack exchange,提问作者ashwar hussain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 20:34:58