

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

# HyperPod Slurm 클러스터 사전 훈련 자습서(GPU)
<a name="hyperpod-gpu-slurm-pretrain-tutorial"></a>

다음 자습서에서는 Slurm 환경을 설정하고 Llama 80억 파라미터 모델에서 훈련 작업을 시작합니다.

**사전 조건**  
레시피를 실행하도록 환경을 설정하기 전에 다음 조건을 충족해야 합니다.  
HyperPod GPU Slurm 클러스터를 설정합니다.  
HyperPod Slurm 클러스터에는 Nvidia Enroot 및 Pyxis가 활성화되어 있어야 합니다(기본적으로 활성화되어 있음).
공유 스토리지 위치가 있어야 합니다. Amazon FSx 파일 시스템 또는 클러스터 노드에서 액세스할 수 있는 NFS 시스템일 수 있습니다.
다음 형식 중 하나의 데이터가 있어야 합니다.  
JSON
JSONGZ(압축된 JSON)
ARROW
(선택 사항) 사전 훈련 또는 미세 조정에 HuggingFace의 모델 가중치를 사용하는 경우 HuggingFace 토큰을 받아야 합니다. 토큰 가져오기에 대한 자세한 내용은 [User access tokens](https://huggingface.co/docs/hub/en/security-tokens) 섹션을 참조하세요.

## HyperPod GPU Slurm 환경 설정
<a name="hyperpod-gpu-slurm-environment-setup"></a>

HyperPod GPU Slurm 클러스터에서 훈련 작업을 시작하려면 다음을 수행합니다.

1. Slurm 클러스터의 헤드 노드에 SSH로 연결합니다.

1. 로그인한 후 가상 환경을 설정합니다. Python 3.9 이상을 사용하고 있는지 확인합니다.

   ```
   #set up a virtual environment
   python3 -m venv ${PWD}/venv
   source venv/bin/activate
   ```

1. SageMaker HyperPod 레시피와 SageMaker HyperPod 어댑터 리포지토리를 공유 스토리지 위치에 복제합니다.

   ```
   git clone https://github.com/aws/sagemaker-hyperpod-training-adapter-for-nemo.git
   git clone --recursive https://github.com/aws/sagemaker-hyperpod-recipes.git
   cd sagemaker-hyperpod-recipes
   pip3 install -r requirements.txt
   ```

1. Enroot를 사용하여 스쿼시 파일을 생성합니다. SMP 컨테이너의 최신 릴리스를 찾으려면 [SageMaker 모델 병렬 처리 라이브러리 릴리스 노트](model-parallel-release-notes.md) 섹션을 참조하세요. Enroot 파일 사용 방법을 더 깊이 이해하려면 [빌드 AWS최적화 Nemo-Launcher 이미지를](https://github.com/aws-samples/awsome-distributed-training/tree/main/3.test_cases/2.nemo-launcher#2-build-aws-optimized-nemo-launcher-image) 참조하세요.

   ```
   REGION="<region>"
   IMAGE="658645717510.dkr.ecr.${REGION}.amazonaws.com/smdistributed-modelparallel:2.4.1-gpu-py311-cu121"
   aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin 658645717510.dkr.ecr.${REGION}.amazonaws.com
   enroot import -o $PWD/smdistributed-modelparallel.sqsh dockerd://${IMAGE}
   mv $PWD/smdistributed-modelparallel.sqsh "/fsx/<any-path-in-the-shared-filesystem>"
   ```

1. Enroot 스쿼시 파일을 사용하여 훈련을 시작하려면 다음 예시를 사용하여 `recipes_collection/config.yaml` 파일을 수정합니다.

   ```
   container: /fsx/path/to/your/smdistributed-modelparallel.sqsh
   ```

## 훈련 작업 시작
<a name="hyperpod-gpu-slurm-launch-training-job"></a>

종속성을 설치한 후 `sagemaker-hyperpod-recipes/launcher_scripts` 디렉터리에서 훈련 작업을 시작합니다. [SageMaker HyperPod recipes repository](https://github.com/aws/sagemaker-hyperpod-recipes)를 복제하여 종속성을 가져올 수 있습니다.

먼저 Github에서 훈련 레시피를 선택합니다. 모델 이름은 레시피의 일부로 지정됩니다. 다음 예시에서는 `launcher_scripts/llama/run_hf_llama3_8b_seq16k_gpu_p5x16_pretrain.sh` 스크립트를 사용하여 시퀀스 길이가 8,192인 사전 훈련 레시피인 `llama/hf_llama3_8b_seq16k_gpu_p5x16_pretrain`으로 Llama 8b를 시작합니다.
+ `IMAGE`: 환경 설정 섹션의 컨테이너입니다.
+ (선택 사항) HuggingFace에서 사전 훈련된 가중치가 필요한 경우 다음 키-값 페어를 설정하여 HuggingFace 토큰을 제공할 수 있습니다.

  ```
  recipes.model.hf_access_token=<your_hf_token>
  ```

```
#!/bin/bash
IMAGE="${YOUR_IMAGE}"
SAGEMAKER_TRAINING_LAUNCHER_DIR="${SAGEMAKER_TRAINING_LAUNCHER_DIR:-${PWD}}"

TRAIN_DIR="${YOUR_TRAIN_DIR}" # Location of training dataset
VAL_DIR="${YOUR_VAL_DIR}" # Location of validation dataset

# experiment ouput directory
EXP_DIR="${YOUR_EXP_DIR}"

HYDRA_FULL_ERROR=1 python3 "${SAGEMAKER_TRAINING_LAUNCHER_DIR}/main.py" \
  recipes=training/llama/hf_llama3_8b_seq16k_gpu_p5x16_pretrain \
  base_results_dir="${SAGEMAKER_TRAINING_LAUNCHER_DIR}/results" \
  recipes.run.name="hf_llama3_8b" \
  recipes.exp_manager.exp_dir="$EXP_DIR" \
  recipes.model.data.train_dir="$TRAIN_DIR" \
  recipes.model.data.val_dir="$VAL_DIR" \
  container="${IMAGE}" \
  +cluster.container_mounts.0="/fsx:/fsx"
```

런처 스크립트에서 필요한 모든 파라미터를 구성한 후 다음 명령을 사용하여 스크립트를 실행할 수 있습니다.

```
bash launcher_scripts/llama/run_hf_llama3_8b_seq16k_gpu_p5x16_pretrain.sh
```

Slurm 클러스터 구성에 대한 자세한 정보는 [HyperPod Slurm에서 훈련 작업 실행](cluster-specific-configurations-run-training-job-hyperpod-slurm.md) 섹션을 참조하세요.