Vertex AI 텐서보드 프로파일러를 사용한 모델 학습 성능 프로파일링

이 페이지에서는 커스텀 학습 작업을 위해 모델 학습 성능을 디버그할 수 있도록 Vertex AI 텐서보드 프로파일러를 사용 설정하는 방법을 보여줍니다.

학습 모델은 컴퓨팅 비용이 높을 수 있습니다. Vertex AI 텐서보드 프로파일러는 학습 운영에 대한 리소스 소비를 이해할 수 있게 도와줌으로써 모델 학습 성능을 모니터링하고 최적화할 수 있게 해줍니다. 이 정보를 사용하면 성능 병목 현상을 파악하고 해결함으로써 모델을 더 빠르고 저렴하게 학습시킬 수 있습니다.

시작하기 전에

Vertex AI 텐서보드 프로파일러 사용 설정

학습 작업에 대해 Vertex AI 텐서보드 프로파일러를 사용 설정하려면 다음을 학습 스크립트에 추가합니다.

  1. 최상위 가져오기에 cloud_profiler 가져오기를 추가합니다.

    from google.cloud.aiplatform.training_utils import cloud_profiler
    
  2. 다음을 추가하여 cloud_profiler 플러그인을 초기화합니다.

    cloud_profiler.init()
    

예시

다음은 샘플 학습 스크립트입니다.

#!/usr/bin/env python

import tensorflow as tf
import argparse
import os
from google.cloud.aiplatform.training_utils import cloud_profiler
import time

"""Train an mnist model and use cloud_profiler for profiling."""

def _create_model():
    model = tf.keras.models.Sequential(
        [
            tf.keras.layers.Flatten(input_shape=(28, 28)),
            tf.keras.layers.Dense(128, activation="relu"),
            tf.keras.layers.Dropout(0.2),
            tf.keras.layers.Dense(10),
        ]
    )
    return model

def main(args):
    strategy = None
    if args.distributed:
        strategy = tf.distribute.MultiWorkerMirroredStrategy()

    mnist = tf.keras.datasets.mnist

    (x_train, y_train), (x_test, y_test) = mnist.load_data()
    x_train, x_test = x_train / 255.0, x_test / 255.0

    if args.distributed:
        strategy = tf.distribute.MultiWorkerMirroredStrategy()
        with strategy.scope():
            model = _create_model()
            model.compile(
                optimizer="adam",
                loss=tf.keras.losses.sparse_categorical_crossentropy,
                metrics=["accuracy"],
            )
    else:
        model = _create_model()
        model.compile(
            optimizer="adam",
            loss=tf.keras.losses.sparse_categorical_crossentropy,
            metrics=["accuracy"],
        )

    # Initialize the profiler.
    cloud_profiler.init()

    # Use AIP_TENSORBOARD_LOG_DIR to update where logs are written to.
    tensorboard_callback = tf.keras.callbacks.TensorBoard(
        log_dir=os.environ["AIP_TENSORBOARD_LOG_DIR"], histogram_freq=1
    )

    model.fit(
        x_train,
        y_train,
        epochs=args.epochs,
        verbose=0,
        callbacks=[tensorboard_callback],
    )
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--epochs", type=int, default=100, help="Number of epochs to run model."
    )
    parser.add_argument(
        "--distributed", action="store_true", help="Use MultiWorkerMirroredStrategy"
    )
    args = parser.parse_args()
    main(args)

Vertex AI 텐서보드 프로파일러 대시보드 액세스

Vertex AI 텐서보드 프로파일러를 사용 설정하도록 학습 스크립트를 구성한 다음 Vertex AI 텐서보드 인스턴스를 사용하여 학습 스크립트를 실행합니다.

학습 스크립트에서 다음 구성을 확인합니다.

  • BASE_OUTPUT_DIR:을 학습 스크립트로 생성된 Vertex AI 텐서보드 로그를 저장하려는 Cloud Storage 버킷으로 설정합니다.
  • 'serviceAccount':roles/storage.adminroles/aiplatform.user 역할로 만든 서비스 계정으로 설정합니다.
  • 'tensorboard':를 이 학습 작업에 사용하려는 Vertex AI 텐서보드 인스턴스의 정규화된 이름으로 설정합니다. 정규화된 이름의 형식은 다음과 같습니다.

    projects/PROJECT_NUMBER_OR_ID/locations/REGION/tensorboards/TENSORBOARD_INSTANCE_ID
    

Google Cloud 콘솔에서 Vertex AI 텐서보드 프로파일러 대시보드에 액세스하는 방법은 두 가지입니다.

  • 커스텀 작업 페이지에서
  • 실험 페이지에서

커스텀 작업 페이지를 통해 프로파일러 대시보드 액세스

학습 작업이 완료됨 상태인 경우에도 이 방법을 사용하여 Vertex AI 텐서보드 프로파일러에 액세스할 수 있습니다.

  1. Google Cloud 콘솔에서 학습 페이지의 커스텀 작업 탭으로 이동합니다.

    커스텀 작업으로 이동

  2. 바로 전에 만든 학습 작업 이름을 클릭하여 작업 세부정보 페이지로 이동합니다.

  3. 텐서보드 열기를 클릭합니다.

  4. 프로필 탭을 클릭합니다.

실험 페이지를 통해 프로파일러 대시보드 액세스

학습 작업이 실행 중 상태인 경우에만 이 방법을 사용하여 Vertex AI 텐서보드 프로파일러 대시보드에 액세스할 수 있습니다.

  1. Google Cloud 콘솔에서 Vertex AI Experiments 페이지로 이동합니다.

    Vertex AI 실험으로 이동

  2. 방금 만든 학습 작업의 리전을 선택합니다.

  3. 학습 작업 이름 옆에 있는 텐서보드 열기를 클릭합니다.

  4. 프로필 탭을 클릭합니다.

프로파일링 세션 캡처

프로파일링 세션을 캡처하려면 학습 작업이 실행 중 상태여야 합니다. Vertex AI 텐서보드 인스턴스의 프로필 탭에서 다음 단계를 수행합니다.

  1. 프로필 캡처를 클릭합니다.
  2. 프로필 서비스 URL 또는 TPU 이름 필드에서 다음을 입력합니다.

    workerpool0-0
    
  3. 주소 유형으로 IP 주소를 선택합니다.

  4. 캡처를 클릭합니다.

노트북

다음 단계

  • Tensorflow Profiler 문서를 참조하여 Profiler 도구 및 이 도구를 사용하여 모델 성능을 최적화하는 방법 알아보기