Kubernetes 클러스터 사전 훈련 자습서(GPU) - Amazon SageMaker AI

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Kubernetes 클러스터 사전 훈련 자습서(GPU)

GPU Kubernetes 클러스터에서 훈련 작업을 시작하는 방법에는 두 가지가 있습니다.

사전 조건

환경 설정을 시작하기 전에 다음 사항을 확인해야 합니다.

  • HyperPod GPU Kubernetes 클러스터가 올바르게 설정되었습니다.

  • 공유 스토리지 위치입니다. 클러스터 노드에서 액세스할 수 있는 Amazon FSx 파일 시스템 또는 NFS 시스템일 수 있습니다.

  • 다음 형식 중 하나의 데이터:

    • JSON

    • JSONGZ(압축 JSON)

    • 화살표

  • (선택 사항) 사전 훈련 또는 미세 조정에 HuggingFace의 모델 가중치를 사용하는 경우 HuggingFace 토큰을 받아야 합니다. 토큰 가져오기에 대한 자세한 내용은 사용자 액세스 토큰을 참조하세요.

GPU Kubernetes 환경 설정

GPU Kubernetes 환경을 설정하려면 다음을 수행합니다.

  • 가상 환경을 설정합니다. Python 3.9 이상을 사용하고 있는지 확인합니다.

    python3 -m venv ${PWD}/venv source venv/bin/activate
  • 다음 방법 중 하나를 사용하여 종속성을 설치합니다.

    • (권장): HyperPod 명령줄 도구 방법:

      # install HyperPod command line tools git clone https://github.com/aws/sagemaker-hyperpod-cli cd sagemaker-hyperpod-cli pip3 install .
    • SageMaker HyperPod 레시피 방법:

      # install SageMaker HyperPod Recipes. git clone --recursive git@github.com:aws/sagemaker-hyperpod-recipes.git cd sagemaker-hyperpod-recipes pip3 install -r requirements.txt
  • kubectl 및 eksctl 설정

  • Helm 설치

  • Kubernetes 클러스터에 연결

    aws eks update-kubeconfig --region "${CLUSTER_REGION}" --name "${CLUSTER_NAME}" hyperpod connect-cluster --cluster-name "${CLUSTER_NAME}" [--region "${CLUSTER_REGION}"] [--namespace <namespace>]

SageMaker HyperPod CLI를 사용하여 훈련 작업 시작

SageMaker HyperPod 명령줄 인터페이스(CLI) 도구를 사용하여 구성으로 훈련 작업을 제출하는 것이 좋습니다. 다음 예제에서는 hf_llama3_8b_seq16k_gpu_p5x16_pretrain 모델에 대한 훈련 작업을 제출합니다.

  • your_training_container: 딥 러닝 컨테이너입니다. SMP 컨테이너의 최신 릴리스를 찾으려면 섹션을 참조하세요SageMaker 모델 병렬 처리 라이브러리 릴리스 노트.

  • (선택 사항) 다음 키-값 페어를 설정하여 HuggingFace에서 사전 훈련된 가중치가 필요한 경우 HuggingFace 토큰을 제공할 수 있습니다.

    "recipes.model.hf_access_token": "<your_hf_token>"
hyperpod start-job --recipe training/llama/hf_llama3_8b_seq16k_gpu_p5x16_pretrain \ --persistent-volume-claims fsx-claim:data \ --override-parameters \ '{ "recipes.run.name": "hf-llama3-8b", "recipes.exp_manager.exp_dir": "/data/<your_exp_dir>", "container": "658645717510.dkr.ecr.<region>.amazonaws.com/smdistributed-modelparallel:2.4.1-gpu-py311-cu121", "recipes.model.data.train_dir": "<your_train_data_dir>", "recipes.model.data.val_dir": "<your_val_data_dir>", "cluster": "k8s", "cluster_type": "k8s" }'

훈련 작업을 제출한 후 다음 명령을 사용하여 성공적으로 제출했는지 확인할 수 있습니다.

kubectl get pods NAME READY STATUS RESTARTS AGE hf-llama3-<your-alias>-worker-0 0/1 running 0 36s

STATUSPENDING 또는 인 경우 다음 명령을 ContainerCreating실행하여 자세한 내용을 확인합니다.

kubectl describe pod <name of pod>

작업이 로 STATUS 변경되면 다음 명령을 사용하여 로그를 검사Running할 수 있습니다.

kubectl logs <name of pod>

를 실행Completed하면 STATUS가 됩니다kubectl get pods.

레시피 시작 관리자를 사용하여 훈련 작업 시작

또는 SageMaker HyperPod 레시피를 사용하여 훈련 작업을 제출할 수 있습니다. 레시피를 사용하려면 k8s.yaml, config.yaml를 업데이트하고 시작 스크립트를 실행해야 합니다.

  • 에서를 k8s.yaml업데이트합니다persistent_volume_claims. Amazon FSx 클레임을 각 컴퓨팅 포드의 /data 디렉터리에 탑재합니다.

    persistent_volume_claims: - claimName: fsx-claim mountPath: data
  • 의에서 config.yaml를 업데이트repo_url_or_path합니다git.

    git: repo_url_or_path: <training_adapter_repo> branch: null commit: null entry_script: null token: null
  • launcher_scripts/llama/run_hf_llama3_8b_seq16k_gpu_p5x16_pretrain.sh 업데이트

    • your_contrainer: 딥 러닝 컨테이너입니다. SMP 컨테이너의 최신 릴리스를 찾으려면 섹션을 참조하세요SageMaker 모델 병렬 처리 라이브러리 릴리스 노트.

    • (선택 사항) 다음 키-값 페어를 설정하여 HuggingFace에서 사전 훈련된 가중치가 필요한 경우 HuggingFace 토큰을 제공할 수 있습니다.

      recipes.model.hf_access_token=<your_hf_token>
    #!/bin/bash #Users should setup their cluster type in /recipes_collection/config.yaml REGION="<region>" IMAGE="658645717510.dkr.ecr.${REGION}.amazonaws.com/smdistributed-modelparallel:2.4.1-gpu-py311-cu121" SAGEMAKER_TRAINING_LAUNCHER_DIR=${SAGEMAKER_TRAINING_LAUNCHER_DIR:-"$(pwd)"} EXP_DIR="<your_exp_dir>" # Location to save experiment info including logging, checkpoints, ect TRAIN_DIR="<your_training_data_dir>" # Location of training dataset VAL_DIR="<your_val_data_dir>" # Location of talidation dataset HYDRA_FULL_ERROR=1 python3 "${SAGEMAKER_TRAINING_LAUNCHER_DIR}/main.py" \ recipes=training/llama/hf_llama3_8b_seq8k_gpu_p5x16_pretrain \ base_results_dir="${SAGEMAKER_TRAINING_LAUNCHER_DIR}/results" \ recipes.run.name="hf-llama3" \ recipes.exp_manager.exp_dir="$EXP_DIR" \ cluster=k8s \ cluster_type=k8s \ container="${IMAGE}" \ recipes.model.data.train_dir=$TRAIN_DIR \ recipes.model.data.val_dir=$VAL_DIR
  • 훈련 작업 시작

    bash launcher_scripts/llama/run_hf_llama3_8b_seq16k_gpu_p5x16_pretrain.sh

훈련 작업을 제출한 후 다음 명령을 사용하여 성공적으로 제출했는지 확인할 수 있습니다.

kubectl get pods
NAME READY STATUS RESTARTS AGE hf-llama3-<your-alias>-worker-0 0/1 running 0 36s

STATUSPENDING 또는 인 경우 다음 명령을 ContainerCreating실행하여 자세한 내용을 확인합니다.

kubectl describe pod <name-of-pod>

작업이 로 STATUS 변경되면 다음 명령을 사용하여 로그를 검사Running할 수 있습니다.

kubectl logs <name of pod>

를 실행Completed하면가 로 전환STATUS됩니다kubectl get pods.

k8s 클러스터 구성에 대한 자세한 내용은 섹션을 참조하세요HyperPod k8s에서 훈련 작업 실행.