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

如何为Vertex AI的PipelineJob任务开启Web访问或交互式Shell?

解决Vertex AI PipelineJob组件开启Web Access的方法

要在Vertex AI Pipeline的组件中开启Web Access(用于SSH调试),可以通过以下两种方式实现——由于Pipeline组件本身不直接支持enable_web_access参数,需要借助CustomJob的配置来实现需求:

方法一:组件内部创建CustomJob并启用Web Access

直接在组件函数中调用aiplatform.CustomJob,显式设置enable_web_access=True,让组件以CustomJob形式运行,自动开启Web Access:

修改后的组件代码如下:

@component(
    packages_to_install=['google-cloud-aiplatform']
)
def hello_world():
    from google.cloud import aiplatform
    import time

    # 定义CustomJob配置并启用web access
    job = aiplatform.CustomJob(
        display_name="hello-world-debug-job",
        worker_pool_specs=[
            {
                "machine_spec": {
                    "machine_type": "n1-standard-4"
                },
                "replica_count": 1,
                "container_spec": {
                    "image_uri": "python:3.9",
                    "command": ["python", "-c"],
                    "args": [
                        "import time; print('Hello world'); time.sleep(300)"
                    ]
                }
            }
        ],
        enable_web_access=True
    )

    job.run()

方法二:通过KFP Vertex CustomJob Op配置Web Access

如果希望保持组件逻辑简洁,可以使用KFP提供的VertexCustomJobOp,直接配置CustomJob参数并启用Web Access:

首先添加对应导入:

from kfp.v2.google import vertex_experimental

然后在流水线中替换原有组件调用:

@dsl.pipeline(
    name = "dataprep"
)
def train_model_pipeline(style: int):
    # 创建带Web Access的CustomJob任务
    hello_op = vertex_experimental.VertexCustomJobOp(
        display_name="hello-world-debug-job",
        worker_pool_specs=[
            {
                "machine_spec": {
                    "machine_type": "n1-standard-4"
                },
                "replica_count": 1,
                "container_spec": {
                    "image_uri": "python:3.9",
                    "command": ["python", "-c"],
                    "args": [
                        "import time; print('Hello world'); time.sleep(300)"
                    ]
                }
            }
        ],
        enable_web_access=True
    )

注意事项

  • 启用Web Access后,可在Vertex AI控制台的对应任务详情页找到SSH连接入口,获取连接命令。
  • 确保你的GCP账号拥有aiplatform.jobs.get、aiplatform.jobs.update等相关权限,才能正常访问Web Access功能。
  • 调试完成后建议关闭Web Access,避免不必要的安全风险。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 01:36:30