使用Google Vertex AI多模态嵌入模型处理视频时遇Deadline错误
Vertex AI多模态嵌入模型视频嵌入请求超时问题
我正在使用Google Vertex AI的多模态嵌入模型,已经通过Python SDK和POST请求成功运行图片与文本嵌入示例,但运行视频示例时出现了与Deadline相关的错误。
示例代码
import vertexai from vertexai.vision_models import MultiModalEmbeddingModel, Video project_id = 'project_name' location = 'us-central1' vertexai.init(project=project_id, location=location) # 文档元数据 video_path = 'gs://test-public-bucket-123/dog_jumping_short.mp4' # 公开的1MB、7秒短视频文件 description = 'dogs jumping' model = MultiModalEmbeddingModel.from_pretrained("multimodalembedding@001") video = Video.load_from_file(video_path) embeddings = model.get_embeddings( video=video ) # 视频嵌入会根据video_segment_config进行分段 print("视频嵌入结果:") for video_embedding in embeddings.video_embeddings: print( f"视频片段: {video_embedding.start_offset_sec} - {video_embedding.end_offset_sec}" ) print(f"嵌入向量: {video_embedding.embedding}") print(f"文本嵌入向量: {embeddings.text_embedding}")
错误信息
Traceback (most recent call last): File "/Users/me/Code/multi-modal-test/multi-modal/lib/python3.12/site-packages/google/api_core/grpc_helpers.py", line 76, in error_remapped_callable return callable_(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/me/Code/multi-modal-test/multi-modal/lib/python3.12/site-packages/grpc/_channel.py", line 1181, in __call__ return _end_unary_response_blocking(state, call, False, None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/me/Code/multi-modal-test/multi-modal/lib/python3.12/site-packages/grpc/_channel.py", line 1006, in _end_unary_response_blocking raise _InactiveRpcError(state) # pytype: disable=not-instantiable ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAUTHENTICATED details = "Video embedding failed with the following error: Deadline" debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.81.234:443 {grpc_message:"Video embedding failed with the following error: Deadline", grpc_status:16, created_time:"2024-05-23T15:53:15.429704-04:00"}"
已排查情况
- 相同认证方式可正常执行文本和图片嵌入,排除认证问题
- 尝试使用cURL请求,仍得到相同的Deadline错误:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://us-central1-aiplatform.googleapis.com/v1/projects/multi/locations/us-central1/publishers/google/models/multimodalembedding@001:predict"
- 已启用Vertex AI API,且拥有以下IAM权限:
- members: - user:me@gmail.com role: roles/aiplatform.admin - members: - user:me@gmail.com role: roles/aiplatform.user - members: - user:me@gmail.com role: roles/ml.admin - members: - user:me@gmail.com role: roles/owner - members: - user:me@gmail.com role: roles/storage.admin - members: - user:me@gmail.com role: roles/visionai.admin etag: BwYaJsGtzOk= version: 1
- 使用用户账号而非服务账号
问题
请问该如何解决此问题?
解决方案建议
延长请求超时时间
视频处理比文本/图片耗时更长,默认超时时间可能不足以完成处理。在Python SDK中可以直接设置超时参数:embeddings = model.get_embeddings( video=video, timeout=120 # 设置为120秒,可根据实际情况调整 )使用cURL时,添加
--max-time参数:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ --max-time 120 \ "https://us-central1-aiplatform.googleapis.com/v1/projects/multi/locations/us-central1/publishers/google/models/multimodalembedding@001:predict"检查视频文件兼容性
确认视频编码、格式是否符合模型要求。即使是MP4格式,也建议重新编码为标准H.264格式后再测试,避免因编码异常导致处理超时。切换区域测试
部分区域可能存在临时资源紧张情况,尝试切换到其他支持多模态嵌入模型的区域(如europe-west4),修改代码中的location参数后重新运行。查看详细日志
进入Google Cloud控制台的Vertex AI日志页面,筛选相关请求日志,查看是否有更具体的错误细节,定位视频处理过程中的超时环节。改用异步预测方式
对于视频这类耗时任务,推荐使用批量异步预测,避免同步请求的超时限制。可以在控制台创建批量预测任务来处理视频嵌入需求。
内容的提问来源于stack exchange,提问作者theGreenCabbage
相关产品推荐
相关产品推荐

