최신 LLM 서비스에서 모델 서버는 다양한 목적을 위해 여러 추론 경로를 구현하고 지원합니다. 이러한 사용 사례의 경우 Vertex Inference에서는 invoke
메서드를 사용하여 단일 배포에서 여러 경로에 액세스하는 것이 좋습니다.
invokeRoutePrefix
를 "/*"
로 설정하여 Model
를 업로드할 때 invoke
메서드를 사용 설정할 수 있습니다. 모델이 엔드포인트에 배포되면 모델 서버의 루트가 아닌 모든 경로에 HTTP 호출을 호출하여 액세스할 수 있습니다.
예를 들어 '/invoke/foo/bar'는 모델 서버에 '/foo/bar'로 전달됩니다.
이 기능은 공개 미리보기 단계에 있으며 다음과 같은 제한사항이 있습니다.
- 사용 설정된 모델 호출은 전용 엔드포인트에만 배포할 수 있습니다.
- 호출 지원 모델의 경우 HTTP 호출만 지원되며 RPC는 지원되지 않습니다.
- 모델을 업로드할 때는
predictRoute
또는invokeRoutePrefix
중 하나만 설정할 수 있습니다. 기본값은predictRoute
입니다. 모델에invokeRoutePrefix
필드가 설정된 경우 배포되면invoke
을 제외한 다른 모든 Vertex 경로 (예::predict
,:rawPredict
)가 사용 중지됩니다. "/*"
는invokeRoutePrefix
에 허용되는 유일한 값이며 모든 비루트 경로를 노출합니다. 노출하고 싶지 않은 경로에 대해서는 신중하게 처리하는 것이 좋습니다.
호출 사용 설정 모델 업로드
from google.cloud import aiplatform
invoke_enabled_model = aiplatform.Model.upload(
display_name="invoke-enabled-model",
serving_container_image_uri=IMAGE_URI,
serving_container_invoke_route_prefix="/*",
serving_container_health_route=HEALTH_ROUTE,
serving_container_environment_variables={"KEY": "VALUE"},
serving_container_args=[],
sync=True,
)
호출 지원 모델 배포
dedicated_endpoint = aiplatform.Endpoint.create(
display_name="dedicated-endpoint-for-invoke-enabled-model",
dedicated_endpoint_enabled=True,
sync=True,
)
dedicated_endpoint.deploy(
model=model,
traffic_percentage=100,
machine_type=MACHINE_TYPE,
accelerator_type=ACCELERATOR_TYPE,
accelerator_count=1,
max_replica_count=1,
)
임의의 맞춤 경로에서 추론 요청하기
호출 경로를 사용하면 배포의 모든 비루트 요청 경로에 액세스할 수 있습니다.
예를 들어 /invoke/foo/bar
은 모델 서버에 /foo/bar
으로 전달됩니다. 경로에 액세스하는 방법에는 두 가지가 있습니다.
전용 엔드포인트에 대한 맞춤 경로 요청
전용 엔드포인트에 대한 호출 요청은 트래픽 분할 구성에 따라 배포된 모델 중 하나로 라우팅됩니다.
def invoke_tabular_sample(
project: str,
location: str,
endpoint_id: str,
request_path: str,
http_request_body: Dict[str, Any],
stream: bool = False,
):
aiplatform.init(project=project, location=location)
dedicated_endpoint = aiplatform.Endpoint(endpoint_id)
if stream:
for chunk in dedicated_endpoint.invoke(
request_path=request_path,
body=json.dumps(http_request_body).encode("utf-8"),
headers={"Content-Type": "application/json"},
stream=True,
):
print(chunk)
else:
response = dedicated_endpoint.invoke(
request_path=request_path,
body=json.dumps(http_request_body).encode("utf-8"),
headers={"Content-Type": "application/json"},
)
print(response)
배포된 모델에 대한 맞춤 경로 요청
특정 배포된 모델을 타겟팅하도록 호출 요청을 할 수 있습니다. 테스트 및 디버깅에 유용할 수 있습니다.
def invoke_direct_deployed_model_inference_tabular_sample(
project: str,
location: str,
endpoint_id: str,
request_path: str,
http_request_body: Dict[str, Any],
deployed_model_id: str,
stream: bool = False,
):
aiplatform.init(project=project, location=location)
dedicated_endpoint = aiplatform.Endpoint(endpoint_id)
if stream:
for chunk in dedicated_endpoint.invoke(
request_path=request_path,
body=json.dumps(http_request_body).encode("utf-8"),
headers={"Content-Type": "application/json"},
deployed_model_id=deployed_model_id,
stream=True,
):
print(chunk)
else:
response = dedicated_endpoint.invoke(
request_path=request_path,
body=json.dumps(http_request_body).encode("utf-8"),
headers={"Content-Type": "application/json"},
deployed_model_id=deployed_model_id,
)
print(response)