SageMaker 엔트리포인트

SageMaker 엔트리포인트 (Sagemaker-Entrypoint)

SageMaker 추론 컨테이너용 엔트리포인트 셸 스크립트입니다. SM_VLLM_ 프리픽스로 시작하는 환경변수들을 읽어 vllm serve의 커맨드라인 인자로 변환해 전달합니다. SageMaker가 요구하는 포트 8080이 기본으로 설정됩니다.

출처: 문서

본문

소스: https://github.com/vllm-project/vllm/blob/main/examples/deployment/sagemaker-entrypoint.sh

#!/bin/bash

# Define the prefix for environment variables to look for
PREFIX="SM_VLLM_"
ARG_PREFIX="--"

# Initialize an array for storing the arguments
# port 8080 required by sagemaker, https://docs.aws.amazon.com/sagemaker/latest/dg/your-algorithms-inference-code.html#your-algorithms-inference-code-container-response
ARGS=(--port 8080)

# Loop through all environment variables
while IFS='=' read -r key value; do
    # Remove the prefix from the key, convert to lowercase, and replace underscores with dashes
    arg_name=$(echo "${key#\"${PREFIX}\"}" | tr '[:upper:]' '[:lower:]' | tr '_' '-')

    # Add the argument name and value to the ARGS array
    ARGS+=("${ARG_PREFIX}${arg_name}")
    if [ -n "$value" ]; then
        ARGS+=("$value")
    fi
done < <(env | grep "^${PREFIX}")

# Pass the collected arguments to the main entrypoint
exec standard-supervisor vllm serve "${ARGS[@]}"

동작 방식:

  • PREFIX="SM_VLLM_"로 시작하는 모든 환경변수를 수집합니다.
  • 변수 이름에서 프리픽스를 제거하고 소문자로 바꾼 뒤 밑줄(_)을 하이픈(-)으로 치환해 CLI 인자 이름으로 만듭니다. 예: SM_VLLM_MODEL--model.
  • 값이 비어 있지 않으면 그 값도 인자로 추가합니다.
  • SageMaker 컨테이너 응답 규약에 따라 기본 --port 8080이 붙습니다.
  • 최종적으로 모아둔 인자들을 vllm serve에 전달합니다.

이 패턴 덕분에 SageMaker 환경변수만으로 각 vLLM 엔진 옵션을 컨테이너 외부에서 설정할 수 있습니다.

더 알아보기 (Learn more)