최신 LLM 서빙 환경에서는 모델 서버가 다양한 목적에 따라 여러 추론 경로를 구현하고 지원합니다. 이러한 사용 사례의 경우 Vertex Inference는 단일 배포에서 여러 경로에 액세스하기 위해 invoke 메서드 사용을 권장합니다.
invoke 메서드는 Model 업로드 시 invokeRoutePrefix를 "/*"로 설정하여 사용 설정할 수 있습니다. 모델이 엔드포인트에 배포되면 모델 서버의 루트를 제외한 모든 경로에 invoke HTTP 호출로 액세스할 수 있습니다.
예를 들어 "/invoke/foo/bar"는 모델 서버에 "/foo/bar" 경로로 전달됩니다.
이 기능은 공개 미리보기 단계이며, 다음과 같은 제한사항이 있습니다.
- Invoke 지원 모델은 전용 엔드포인트에만 배포할 수 있습니다.
- Invoke 지원 모델은 HTTP 호출만 지원하며 RPC는 지원되지 않습니다.
- 모델을 업로드할 때
predictRoute또는invokeRoutePrefix중 하나만 설정할 수 있습니다. 기본값은predictRoute입니다. 모델에서invokeRoutePrefix필드를 설정하면, 배포 후에는invoke를 제외한 모든 Vertex 경로(예::predict,:rawPredict등)가 사용 중지됩니다. invokeRoutePrefix에 허용되는 값은"/*"하나뿐이며, 이는 루트 경로를 제외한 모든 경로를 노출합니다. 노출을 원하지 않는 경로에 대해서는 주의하여 처리해야 합니다.
Invoke 지원 모델 업로드
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,
)
Invoke 지원 모델 배포
dedicated_endpoint = aiplatform.Endpoint.create(
display_name="dedicated-endpoint-for-invoke-enabled-model",
dedicated_endpoint_enabled=True,
sync=True,
)
dedicated_endpoint.deploy(
model=invoke_enabled_model,
traffic_percentage=100,
machine_type=MACHINE_TYPE,
accelerator_type=ACCELERATOR_TYPE,
accelerator_count=1,
max_replica_count=1,
)
임의의 커스텀 경로로 추론 요청하기
Invoke 경로를 사용하면 배포의 모든 비루트 요청 경로에 액세스할 수 있습니다.
예를 들어 /invoke/foo/bar은 모델 서버에 /foo/bar으로 전달됩니다. 경로에 액세스하는 방법에는 두 가지가 있습니다.
전용 엔드포인트에 대한 커스텀 경로 요청
전용 엔드포인트에 대한 Invoke 요청은 트래픽 분할 구성에 따라 배포된 모델 중 하나로 라우팅됩니다.
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)
배포된 모델에 대한 커스텀 경로 요청
Invoke 요청은 특정 배포된 모델을 대상으로 직접 보낼 수 있습니다. 이는 테스트 및 디버깅에 유용합니다.
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)