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

在Vertex AI在线预测时遭遇ModelNotFoundException问题求助

问题描述

我正尝试把微调后的GPT-2(PyTorch)模型部署到Vertex AI。导入模型时没设置任何预测schema,这个模型应该接受张量输入,返回张量或字符串(还没验证)。用官方示例代码运行时出现了如下错误:

NotFound: 404 {
  "code": 404,
  "type": "ModelNotFoundException",
  "message": "Model not found: model"
}

我已经确认项目和端点ID是对的,但怀疑部署流程里出了问题导致找不到模型,想知道有没有类似问题和解决办法。

代码示例
from typing import Dict, List, Union

from google.cloud import aiplatform
from google.protobuf import json_format
from google.protobuf.struct_pb2 import Value


def predict_custom_trained_model_sample(
    project: str,
    endpoint_id: str,
    instances: Union[Dict, List[Dict]],
    location: str = $REGION,
    api_endpoint: str = $API-ENDPOINT,
):
    """
    `instances` can be either single instance of type dict or a list
    of instances.
    """
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.PredictionServiceClient(client_options=client_options)
    # The format of each instance should conform to the deployed model's prediction input schema.
    instances = instances if isinstance(instances, list) else [instances]
    instances = [
        json_format.ParseDict(instance_dict, Value()) for instance_dict in instances
    ]
    parameters_dict = {}
    parameters = json_format.ParseDict(parameters_dict, Value())
    endpoint = client.endpoint_path(
        project=project, location=location, endpoint=endpoint_id
    )
    response = client.predict(
        endpoint=endpoint, instances=instances, parameters=parameters
    )
    print("response")
    print(" deployed_model_id:", response.deployed_model_id)
    # The predictions are a google.protobuf.Value representation of the model's predictions.
    predictions = response.predictions
    for prediction in predictions:
        print(" prediction:", dict(prediction))


# [END aiplatform_predict_custom_trained_model_sample]

predict_custom_trained_model_sample(
    project=$PROJECT,
    endpoint_id=$ENDPOINT_ID,
    location=$REGION,
    instances={"tensor": "[1024, 2059, 23, 4829]"}
)
可能的解决方案
  • 确认模型是否成功部署到端点:去Vertex AI控制台的端点页面检查,确保目标模型已经成功部署到指定端点,且状态是“活跃”。如果模型部署失败或者没关联到端点,就会触发这个错误。
  • 检查API端点和区域匹配:确保api_endpoint参数和location对应(比如us-central1对应的api_endpoint是us-central1-aiplatform.googleapis.com),区域不匹配会导致请求路由到错误的资源池,自然找不到模型。
  • 验证模型导入流程:导入PyTorch模型到Vertex AI时,没设置预测schema的话,要保证模型的推理代码(predict.py)能正确解析输入格式。如果推理代码期望的输入键名和你传的"tensor"不匹配,可能会导致内部找不到模型对应的处理逻辑,间接触发这个错误。建议检查自定义预测路由的代码,确保输入输出格式一致。
  • 检查权限配置:确认执行预测的账号有aiplatform.endpoints.predict权限,以及对目标模型和端点的访问权限。权限不足有时会被包装成资源未找到的错误返回。
  • 排查实例输入格式:你现在传的"[1024, 2059, 23, 4829]"是字符串格式的张量,而模型可能需要实际的数组类型。试试把实例改成{"tensor": [1024, 2059, 23, 4829]},避免字符串解析错误导致模型无法正常加载处理。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 15:30:02