최적화된 TensorFlow 런타임

최적화된 TensorFlow 런타임은 오픈소스 기반의 사전 빌드된 TensorFlow Serving 컨테이너보다 빠르고 저렴한 비용 추론을 위해 모델을 최적화합니다. 최적화된 TensorFlow 런타임은 Google의 독점적인 오픈소스 기술을 활용하여 이를 수행합니다.

머신러닝(ML) 모델이 클수록 서비스를 제공하기 위한 비용이 더 증가할 수 있습니다. 최적화된 TensorFlow 런타임을 사용하면 오픈소스 기반 TensorFlow 런타임을 사용할 때보다 ML 모델 제공 비용과 추론 속도가 낮아질 수 있습니다. Vertex AI Prediction을 사용할 때 최적화된 TensorFlow 런타임을 활용하기 위해 코드를 수정할 필요가 없습니다. 대신 이를 사용하는 제공 컨테이너 이미지를 선택합니다.

최적화된 TensorFlow 런타임은 사전 빌드된 TensorFlow Serving 컨테이너와 하위 호환됩니다. 사전 빌드된 컨테이너를 사용하여 TensorFlow 모델을 실행하는 경우 최소한의 노력으로 최적화된 TensorFlow 런타임 컨테이너로 전환할 수 있습니다.

최적화된 TensorFlow 런타임을 사용하면 모델 성능이 향상되지만 모델 유형에 따라 성능 영향이 달라질 수 있습니다.

최적화된 TensorFlow 런타임 개요

최적화된 TensorFlow 런타임은 모델 최적화 및 새로운 독점 Google 기술을 사용하여 오픈소스 기반의 사전 빌드된 TensorFlow Serving 컨테이너에 비해 속도를 향상시키고 추론 비용을 절감합니다.

최적화는 Vertex AI 실행 전 모델을 업로드할 때 발생합니다. 엔드포인트에 모델을 배포한 후에는 최적화 로그가 예측 로그에 추가됩니다. 이러한 로그를 사용하여 최적화 중에 발생할 수 있는 문제를 해결할 수 있습니다.

다음 주제에서는 최적화된 TensorFlow 런타임의 최적화 개선 사항을 설명합니다.

모델 최적화

다음 세 가지 모델 최적화가 최적화된 TensorFlow 런타임에 포함되어 있습니다.

모델 XLA 사전 컴파일

TensorFlow 모델이 실행되면 모든 작업이 개별적으로 실행됩니다. 개별 작업을 실행하면 약간의 오버헤드가 발생합니다. 최적화된 TensorFlow 런타임은 XLA를 활용하여 TensorFlow 그래프의 전체 또는 일부를 더 큰 커널로 사전 컴파일하여 이러한 오버헤드 일부를 제거할 수 있습니다.

모델 XLA 사전 컴파일은 선택사항이며 기본적으로 중지되어 있습니다. 배포 중에 모델 XLA 사전 컴파일을 사용 설정하는 방법은 모델 XLA 사전 컴파일 사용 설정을 참조하세요.

모델 압축 최적화

최적화된 TensorFlow 런타임은 모델 압축 최적화를 사용 설정하여 모델 정밀도에 약간의 영향을 미치면서 일부 모델을 빠르게 실행할 수 있습니다. 모델 압축 최적화가 사용 설정되면 최적화된 TensorFlow 런타임은 양자화 및 가중치 가지치기와 같은 기술을 활용하여 모델을 더 빠르게 실행합니다.

모델 압축 최적화 기능은 기본적으로 사용 중지되어 있습니다. 배포 중에 모델 압축 최적화를 사용 설정하는 방법은 모델 압축 최적화 사용 설정을 참조하세요.

GPU에서 테이블 형식 모델 성능 향상

TensorFlow 테이블 형식 모델은 가속기를 효과적으로 활용할 수 없으므로 일반적으로 CPU에서 제공됩니다. 최적화된 TensorFlow 런타임은 GPU에서 모델의 상당 부분을 계산적으로 실행하여 이를 해결합니다. 나머지 모델은 호스트와 가속기 간의 통신을 최소화하여 CPU에서 실행됩니다. 모델의 비용이 많이 드는 부분은 GPU에서 실행하고 나머지 부분은 CPU에서 실행하면 테이블 형식 모델을 더 빠르고 저렴하게 제공할 수 있습니다.

최적화된 TensorFlow 런타임은 다음과 같은 테이블 형식 모델 유형 제공을 최적화합니다.

Cloud TPU의 자동 모델 최적화

Cloud TPU를 지원하는 사전 빌드된 최적화 TensorFlow 런타임 컨테이너는 TPU에서 실행되도록 모델을 자동으로 분할하고 최적화할 수 있습니다. 자세한 내용은 Cloud TPU에 배포를 참조하세요.

TensorFlow 런타임(TFRT) 사용

최적화된 TensorFlow 런타임은 TensorFlow 런타임(TFRT)을 사용할 수 있습니다. TFRT는 멀티스레드 호스트 CPU를 효율적으로 사용하고 비동기 프로그래밍 모델을 지원하며 저수준 효율에 최적화되어 있습니다.

TFRT CPU는 버전 2.8을 제외한 모든 최적화된 TensorFlow 런타임 CPU 컨테이너 이미지에서 사용 설정됩니다. TFRT CPU를 중지하려면 use_tfrt 플래그를 false로 설정합니다.

TFRT GPU는 야간 최적화된 TensorFlow 런타임 GPU 컨테이너 이미지 및 안정적으로 최적화된 TensorFlow 런타임 GPU 컨테이너 이미지 버전 2.13 이상에서 사용할 수 있습니다. TFRT GPU를 사용 설정하려면 use_tfrtallow_precompilation 플래그를 true로 설정합니다. GPU 컨테이너 이미지에서 TFRT는 호스트 CPU와 GPU 간의 데이터 전송 오버헤드를 최소화합니다. TFRT를 사용 설정하면 XLA 컴파일과 함께 작동합니다. XLA 사전 컴파일이 사용 설정되었기 때문에 첫 번째 요청에서 지연 시간이 증가하는 등 몇 가지 부작용이 발생할 수 있습니다. 자세한 내용은 모델 XLA 사전 컴파일 사용 설정을 참조하세요.

Google 런타임 사용

최적화된 TensorFlow 런타임은 Google의 내부 스택을 통해 빌드되므로 Google의 독점 런타임 환경에서 실행될 수 있습니다.

최적화된 TensorFlow 런타임 컨테이너 이미지

Vertex AI 예측은 안정적 및 나이틀리 등 두 가지 유형의 최적화된 TensorFlow 런타임 컨테이너 이미지를 제공합니다.

안정적인 컨테이너 이미지

안정적이고 최적화된 TensorFlow 런타임 컨테이너는 오픈소스 기반의 사전 빌드된 TensorFlow Serving 컨테이너와 마찬가지로 특정 TensorFlow 버전에 결합됩니다. 특정 버전에 바인딩된 최적화된 TensorFlow 런타임 컨테이너는 동일한 버전에 바인딩된 오픈소스 빌드와 동일한 기간 동안 유지보수됩니다. 최적화된 TensorFlow 런타임 빌드 속성은 빠른 추론을 제외하고 오픈소스 TensorFlow 빌드와 동일합니다.

빌드는 이전 버전과 호환됩니다. 즉, 최신 컨테이너를 사용하여 이전 TensorFlow 버전에서 학습된 모델을 실행할 수 있어야 합니다. 최근 컨테이너는 이전 컨테이너보다 우수하게 수행됩니다. 드물지만 이전 TensorFlow 버전에서 학습된 모델은 최신 컨테이너에서 작동하지 않을 수 있습니다.

나이틀리 컨테이너 이미지

나이틀리 최적화된 TensorFlow 런타임 빌드에는 최신 개선 사항과 최적화가 포함되어 있지만 안정적인 빌드만큼 안정적이지는 않습니다. 주로 실험용으로 사용됩니다. 나이틀리 빌드 이름에는 nightly 라벨이 포함됩니다. 안정적인 컨테이너 이미지와 달리 나이틀리 컨테이너에는 Vertex AI 서비스수준계약(SLA)이 적용되지 않습니다.

사용 가능한 컨테이너 이미지

다음과 같이 나이틀리 및 안정적인 최적화된 TensorFlow 런타임 Docker 컨테이너 이미지를 사용할 수 있습니다.

ML 프레임워크 버전 지원되는 가속기(해당하는 경우 CUDA 버전) 패치 및 지원 종료일 지원 종료 지원되는 이미지
nightly CPU만 해당 없음 해당 없음
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.nightly:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.nightly:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.nightly:latest
nightly GPU(CUDA 12.x) 해당 없음 해당 없음
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.nightly:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.nightly:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.nightly:latest
nightly Cloud TPU 해당 없음 해당 없음
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-tpu.nightly:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-tpu.nightly:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-tpu.nightly:latest
2.15 CPU만 2024년 8월 15일 2025년 8월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-15:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-15:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-15:latest
2.15 GPU(CUDA 12.x) 2024년 8월 15일 2025년 8월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-15:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-15:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-15:latest
2.15 Cloud TPU 2024년 8월 15일 2025년 8월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-tpu.2-15:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-tpu.2-15:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-tpu.2-15:latest
2.14 CPU만 2024년 8월 15일 2025년 8월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-14:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-14:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-14:latest
2.14 GPU(CUDA 12.x) 2024년 8월 15일 2025년 8월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-14:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-14:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-14:latest
2.13 CPU만 2024년 8월 15일 2025년 8월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-13:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-13:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-13:latest
2.13 GPU(CUDA 11.x) 2024년 8월 15일 2025년 8월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-13:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-13:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-13:latest
2.12 CPU만 2024년 5월 15일 2025년 5월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-12:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-12:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-12:latest
2.12 GPU(CUDA 11.x) 2024년 5월 15일 2025년 5월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-12:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-12:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-12:latest
2.11 CPU만 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-11:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-11:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-11:latest
2.11 GPU(CUDA 11.x) 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-11:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-11:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-11:latest
2.10 CPU만 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-10:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-10:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-10:latest
2.10 GPU(CUDA 11.x) 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-10:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-10:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-10:latest
2.9 CPU만 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-9:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-9:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-9:latest
2.9 GPU(CUDA 11.x) 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-9:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-9:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-9:latest
2.8 CPU만 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-8:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-8:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-8:latest
2.8 GPU(CUDA 11.x) 2023년 11월 15일 2024년 11월 15일
  • us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-8:latest
  • europe-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-8:latest
  • asia-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-gpu.2-8:latest

비공개 엔드포인트로 최적화된 TensorFlow 런타임 사용

비공개 엔드포인트를 사용하여 Vertex AI로 온라인 예측을 제공하면 공개 엔드포인트를 사용하는 것보다 더 빠른 Vertex AI 온라인 예측 서비스에 대한 지연 시간이 짧은 보안 연결이 제공됩니다. 최적화된 TensorFlow 런타임은 지연 시간에 민감한 모델을 제공할 가능성이 높으므로 비공개 엔드포인트와 함께 사용하는 것이 좋습니다. 자세한 내용은 온라인 예측에 비공개 엔드포인트 사용을 참조하세요.

최적화된 TensorFlow 런타임을 사용하여 모델 배포

최적화된 TensorFlow 런타임을 사용하여 예측 모델을 배포하는 프로세스는 오픈소스 기반의 사전 빌드된 TensorFlow Serving 컨테이너를 사용하여 모델을 배포하는 프로세스와 거의 동일합니다. 유일한 차이는 모델을 만들 때 최적화된 TensorFlow 런타임을 사용하는 컨테이너 이미지를 지정하고 이 주제 앞부분에서 설명한 최적화 플래그를 사용 설정할 수 있다는 점입니다. 예를 들어 us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-8:latest 컨테이너로 모델을 배포한 경우 us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.2-8:latest 컨테이너를 사용하여 최적화된 TensorFlow 런타임으로 동일한 모델을 제공할 수 있습니다.

다음 코드 샘플에서는 us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.nightly:latest에 최적화된 TensorFlow 런타임 컨테이너를 사용하여 모델을 만드는 방법을 보여줍니다. 이 모델을 배포하려면 다른 사전 빌드된 TensorFlow Serving 컨테이너를 사용하여 모델을 배포하는 프로세스와 동일한 프로세스를 사용합니다.

이 샘플에 사용된 ModelServiceClient에 대한 자세한 내용은 Class ModelServiceClient를 참조하세요. Vertex AI를 사용하여 모델을 배포하는 방법에 대한 자세한 내용은 Vertex AI API를 사용하여 모델 배포를 참조하세요. allow_precompilationallow_compression 설정에 대한 자세한 내용은 이 주제 앞부분에서 설명한 모델 최적화를 참조하세요.

    from google.cloud.aiplatform import gapic as aip
    PROJECT_ID = PROJECT_ID
    REGION = LOCATION
    API_ENDPOINT = f"{REGION}-aiplatform.googleapis.com"
    PARENT = f"projects/{PROJECT_ID}/locations/{REGION}"

    client_options = {"api_endpoint": API_ENDPOINT}
    model_service_client = aip.ModelServiceClient(client_options=client_options)
    tf_opt_model_dict = {
        "display_name": "DISPLAY_NAME",
        "metadata_schema_uri": "",
        "artifact_uri": "MODEL_URI",
        "container_spec": {
            "image_uri": "us-docker.pkg.dev/vertex-ai-restricted/prediction/tf_opt-cpu.nightly:latest",
            "args": [
                # The optimized TensorFlow runtime includes the following
                # options that can be set here.
                # "--allow_precompilation=true" - enable XLA precompilation
                # "--allow_compression=true" - enable
                #    model compression optimization
            ],
        },
    }
    tf_opt_model = model_service_client.upload_model(
        parent=PARENT,
        model=tf_opt_model_dict).result(timeout=180).model

모델 최적화 플래그

최적화된 TensorFlow 런타임을 사용하여 모델을 배포할 때 제공하는 TensorFlow 모델을 더욱 최적화할 수 있는 두 가지 기능을 사용 설정할 수 있습니다.

  1. 모델 XLA 사전 컴파일
  2. 모델 압축에 영향을 미치는 최적화

모델 XLA 사전 컴파일과 모델 압축 최적화를 동시에 사용 설정할 수 있습니다. 다음 주제에서는 배포 중에 플래그를 사용하여 이러한 옵션을 사용 설정하는 방법을 설명합니다.

모델 XLA 사전 컴파일 사용 설정

모델을 사전 컴파일하도록 최적화된 TensorFlow 런타임을 구성하려면 allow_precompilation 플래그를 true로 설정합니다. 모델 XLA 사전 컴파일은 다양한 종류의 모델에서 작동하며 대부분의 경우에서 성능을 향상시킵니다. XLA 사전 컴파일은 배치 크기가 큰 요청에 가장 적합합니다.

모델 XLA 사전 컴파일은 새 배치 크기가 포함된 첫 번째 요청이 도착하면 발생합니다. 첫 번째 요청 전에 런타임이 초기화됐는지 확인하려면 준비 요청 파일을 포함하면 됩니다. 자세한 내용은 TensorFlow 웹사이트의 SavedModel 준비를 참조하세요.

XLA 사전 컴파일은 모델 복잡성에 따라 완료하는 데 몇 초에서 몇 분까지 걸립니다. 모델 XLA 사전 컴파일을 사용하는 경우 다음 사항을 고려해야 합니다.

  • 준비 파일을 사용하는 경우 모델이 수신할 것으로 예상되는 배치 크기를 나타내는 배치 크기가 포함된 요청을 포함하세요. 준비 파일에서 많은 요청을 제공하면 모델 서버 시작 속도가 느려집니다.

  • 모델이 배치 크기가 다른 요청을 수신할 것으로 예상되는 경우 allow_batch_sizes에 일련의 고정 값을 사용하여 서버 측 일괄 처리를 사용 설정하는 것이 좋습니다. 서버 측 일괄 처리를 사용 설정하는 방법에 대한 자세한 내용은

    TensorFlow 웹사이트의 TensorFlow용 서버 측 요청 일괄 처리 사용 설정을 참조하세요.

  • XLA 사전 컴파일은 메모리 오버헤드를 추가하므로 일부 대형 모델이 GPU의 메모리 부족 오류로 실패할 수 있습니다.

프로덕션에서 이 특성을 사용 설정하기 전에 모델에서 XLA 사전 컴파일을 테스트하는 것이 좋습니다.

모델 압축 최적화 사용 설정

모델 압축 최적화를 사용하도록 최적화된 TensorFlow 런타임을 구성하려면 allow_compression 플래그를 true로 설정합니다. 이 플래그를 사용 설정하여 모델 정밀도가 어떠한 영향을 받는지 테스트한 후 프로덕션에서 사용 설정 여부를 결정합니다.

최적화 사용 중지

최적화 없이 모델을 실행하도록 최적화된 TensorFlow 런타임을 구성하려면 disable_optimizer 플래그를 true로 설정합니다.

최적화된 TensorFlow 런타임 한도

최적화된 TensorFlow 런타임에는 다음과 같은 제한사항이 있습니다.

  • 최적화된 TensorFlow 런타임은 Tesla K80, Tesla P4, Tesla P100과 같은 이전 NVIDIA GPU와 호환되지 않습니다.
  • 최적화된 TensorFlow 런타임은 현재 샘플링된 Shapley 설명 기능만 지원합니다.

가격 책정

최적화된 TensorFlow 런타임을 사용하여 모델을 배포하는 경우 추가 요금이 발생하지 않습니다. 이 비용은 사용되는 VM과 가속기의 수를 기준으로 요금이 청구되는 다른 예측 배포와 동일합니다. 자세한 내용은 Vertex AI 가격 책정을 참조하세요.