Trainium Kubernetes 叢集訓練前教學課程 - Amazon SageMaker AI

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Trainium Kubernetes 叢集訓練前教學課程

您可以使用下列其中一種方法,在 Trainium Kubernetes 叢集中啟動訓練任務。

必要條件

開始設定環境之前,請確定您已:

  • 設定 HyperPod Trainium Kubernetes 叢集

  • 共用儲存位置,可以是可從叢集節點存取的 Amazon FSx 檔案系統或 NFS 系統。

  • 下列其中一個格式的資料:

    • JSON

    • JSONGZ (壓縮 JSON)

    • ARROW

  • (選用) 如果您使用 HuggingFace 的模型權重進行預先訓練或微調,則必須取得 HuggingFace 權杖。如需取得字符的詳細資訊,請參閱使用者存取字符

設定您的 Trainium Kubernetes 環境

若要設定 Trainium Kubernetes 環境,請執行下列動作:

  1. 完成下列教學課程中的步驟:從下載資料集開始的 HuggingFace Llama3-8B 預先訓練

  2. 準備模型組態。它們可在 Neuron 儲存庫中使用。在本教學課程中,您可以使用 llama3 8b 模型組態。

  3. 虛擬環境設定。確定您使用 Python 3.9 或更新版本。

    python3 -m venv ${PWD}/venv source venv/bin/activate
  4. 安裝相依性

    • (建議) 使用下列 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
  5. 設定 kubectl 和 eksctl

  6. 安裝 Helm

  7. 連線至 Kubernetes 叢集

    aws eks update-kubeconfig --region "${CLUSTER_REGION}" --name "${CLUSTER_NAME}" hyperpod connect-cluster --cluster-name "${CLUSTER_NAME}" [--region "${CLUSTER_REGION}"] [--namespace <namespace>]
  8. 容器:Neuron 容器

使用 SageMaker HyperPod CLI 啟動訓練任務

我們建議您使用 SageMaker HyperPod 命令列界面 (CLI) 工具,以您的組態提交訓練任務。下列範例會提交 hf_llama3_8b_seq8k_trn1x4_pretrain Trainium 模型的訓練任務。

  • your_neuron_containerNeuron 容器

  • your_model_config:環境設定區段中的模型組態

  • (選用) 如果您需要從 HuggingFace 預先訓練的權重,您可以設定下列鍵值對,以提供 HuggingFace 權杖:

    "recipes.model.hf_access_token": "<your_hf_token>"
hyperpod start-job --recipe training/llama/hf_llama3_8b_seq8k_trn1x4_pretrain \ --persistent-volume-claims fsx-claim:data \ --override-parameters \ '{ "cluster": "k8s", "cluster_type": "k8s", "container": "<your_neuron_contrainer>", "recipes.run.name": "hf-llama3", "recipes.run.compile": 0, "recipes.model.model_config": "<your_model_config>", "instance_type": "trn1.32xlarge", "recipes.data.train_dir": "<your_train_data_dir>" }'

提交訓練任務之後,您可以使用下列命令來驗證是否已成功提交。

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

如果 STATUSPENDINGContainerCreating,請執行下列命令以取得更多詳細資訊。

kubectl describe pod <name of pod>

任務STATUS變更為 後Running,您可以使用下列命令來檢查日誌。

kubectl logs <name of pod>

當您執行 Completed時, STATUS會變成 kubectl get pods

使用配方啟動器啟動訓練任務

或者,使用 SageMaker HyperPod 配方來提交您的訓練任務。若要使用配方提交訓練任務,請更新 k8s.yamlconfig.yaml。為模型執行 bash 指令碼以啟動該模型。

  • 在 中k8s.yaml,更新 persistent_volume_claims,將 Amazon FSx 宣告掛載到運算節點中的 /data 目錄

    persistent_volume_claims: - claimName: fsx-claim mountPath: data
  • 更新 launcher_scripts/llama/run_hf_llama3_8b_seq8k_trn1x4_pretrain.sh

    • your_neuron_contrainer:環境設定區段中的容器

    • your_model_config:環境設定區段中的模型組態

    (選用) 如果您需要從 HuggingFace 預先訓練的權重,您可以設定下列鍵值對,以提供 HuggingFace 權杖:

    recipes.model.hf_access_token=<your_hf_token>
    #!/bin/bash #Users should set up their cluster type in /recipes_collection/config.yaml IMAGE="<your_neuron_contrainer>" MODEL_CONFIG="<your_model_config>" SAGEMAKER_TRAINING_LAUNCHER_DIR=${SAGEMAKER_TRAINING_LAUNCHER_DIR:-"$(pwd)"} 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_trn1x4_pretrain \ base_results_dir="${SAGEMAKER_TRAINING_LAUNCHER_DIR}/results" \ recipes.run.name="hf-llama3-8b" \ instance_type=trn1.32xlarge \ recipes.model.model_config="$MODEL_CONFIG" \ cluster=k8s \ cluster_type=k8s \ container="${IMAGE}" \ recipes.data.train_dir=$TRAIN_DIR \ recipes.data.val_dir=$VAL_DIR
  • 啟動任務

    bash launcher_scripts/llama/run_hf_llama3_8b_seq8k_trn1x4_pretrain.sh

提交訓練任務之後,您可以使用下列命令來驗證是否已成功提交。

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

如果 STATUS位於 PENDINGContainerCreating,請執行下列命令以取得更多詳細資訊。

kubectl describe pod <name of pod>

任務 STATUS 變更為執行後,您可以使用下列命令來檢查日誌。

kubectl logs <name of pod>

當您執行 Completed時, STATUS會變成 kubectl get pods

如需 k8s 叢集組態的詳細資訊,請參閱 Trainium Kubernetes 叢集訓練前教學課程