Accelerate documentation

Intel CPU에서 학습

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v1.15.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Intel CPU에서 학습

CPU에서 학습 최적화가 작동하는 방식

Accelerate는 Intel CPU를 완전히 지원합니다. 설정을 통해 활성화하기만 하면 됩니다.

시나리오 1: 분산 CPU 학습 가속

컴퓨터에서 accelerate config를 실행합니다:

$ accelerate config
-----------------------------------------------------------------------------------------------------------------------------------------------------------
In which compute environment are you running?
This machine
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Which type of machine are you using?
No distributed training
Do you want to run your training on CPU only (even if a GPU / Apple Silicon device is available)? [yes/NO]:yes
Do you wish to optimize your script with torch dynamo?[yes/NO]:NO
Do you want to use DeepSpeed? [yes/NO]: NO
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Do you wish to use FP16 or BF16 (mixed precision)?
bf16

이것은 …을(를) 수행할 때 기본 옵션을 올바르게 설정하는 데 자동으로 사용되는 설정 파일을 생성합니다

accelerate launch my_script.py --args_to_my_script

예를 들어, accelerate config로 생성된 default_config.yaml을 사용하여 NLP 예제 examples/nlp_example.py를 실행하는 방법은 다음과 같습니다(레포지토리의 루트에서).

compute_environment: LOCAL_MACHINE
distributed_type: 'NO'
downcast_bf16: 'no'
machine_rank: 0
main_training_function: main
mixed_precision: bf16
num_machines: 1
num_processes: 1
rdzv_backend: static
same_network: true
tpu_env: []
tpu_use_cluster: false
tpu_use_sudo: false
use_cpu: true
accelerate launch examples/nlp_example.py

accelerator.prepare는 현재 여러 모델을 동시에 준비하는 경우(옵티마이저 없음) 또는 학습을 위한 단일 모델-옵티마이저 쌍만 처리할 수 있습니다. 다른 시도(예: 두 개의 모델-옵티마이저 쌍)는 상세한 오류를 발생시킵니다. 이 제한을 우회하려면 각 모델-옵티마이저 쌍에 대해 accelerator.prepare를 별도로 사용하는 것을 고려해 보세요.

시나리오 2: 분산 CPU 학습 가속화 Intel oneCCL을 통신에 사용하고, Intel® MPI 라이브러리를 결합하여 Intel® 아키텍처에서 유연하고 효율적이며 확장 가능한 클러스터 메시징을 제공합니다. 설치 가이드는 여기를 참고하세요.

머신(node0)에서 accelerate config를 실행합니다:

$ accelerate config
-----------------------------------------------------------------------------------------------------------------------------------------------------------
In which compute environment are you running?
This machine
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Which type of machine are you using?
multi-CPU
How many different machines will you use (use more than 1 for multi-node training)? [1]: 4
-----------------------------------------------------------------------------------------------------------------------------------------------------------
What is the rank of this machine?
0
What is the IP address of the machine that will host the main process? 36.112.23.24
What is the port you will use to communicate with the main process? 29500
Are all the machines on the same local network? Answer `no` if nodes are on the cloud and/or on different network hosts [YES/no]: yes
Do you want accelerate to launch mpirun? [yes/NO]: yes
Please enter the path to the hostfile to use with mpirun [~/hostfile]: ~/hostfile
Enter the number of oneCCL worker threads [1]: 1
Do you wish to optimize your script with torch dynamo?[yes/NO]:NO
How many processes should be used for distributed training? [1]:16
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Do you wish to use FP16 or BF16 (mixed precision)?
bf16

예를 들어, 저장소 루트에서 분산 CPU 학습을 위해 NLP 예제 examples/nlp_example.py를 실행하는 방법은 다음과 같습니다.

accelerate config에 의해 생성되는 default_config.yaml

compute_environment: LOCAL_MACHINE
distributed_type: MULTI_CPU
downcast_bf16: 'no'
machine_rank: 0
main_process_ip: 36.112.23.24
main_process_port: 29500
main_training_function: main
mixed_precision: bf16
mpirun_config:
  mpirun_hostfile: /home/user/hostfile
num_machines: 4
num_processes: 16
rdzv_backend: static
same_network: true
tpu_env: []
tpu_use_cluster: false
tpu_use_sudo: false
use_cpu: true

다음 환경 변수를 설정하고 intel MPI를 사용하여 학습을 시작합니다

node0에서 각 노드의 IP 주소를 포함하는 구성 파일(예: hostfile)을 생성하고, 해당 구성 파일의 경로를 인자로 전달해야 합니다.

mpirun을 Accelerate가 시작하도록 선택한 경우, hostfile의 위치가 설정 파일의 경로와 일치하는지 확인하세요.

$ cat hostfile
xxx.xxx.xxx.xxx #node0 ip
xxx.xxx.xxx.xxx #node1 ip
xxx.xxx.xxx.xxx #node2 ip
xxx.xxx.xxx.xxx #node3 ip
accelerate launch examples/nlp_example.py

mpirun 명령을 사용하여 분산 학습을 직접 시작할 수도 있습니다. node0에서 다음 명령을 실행하면 node0, node1, node2, node3에서 BF16 혼합 정밀도로 16DDP가 활성화됩니다. 이 방법을 사용할 경우, 다중 CPU 학습에 사용되는 모든 머신에서 Python 스크립트, Python 환경, accelerate 설정 파일이 사용 가능해야 합니다.

export MASTER_ADDR=xxx.xxx.xxx.xxx #node0 ip
mpirun -f hostfile -n 16 -ppn 4 accelerate launch examples/nlp_example.py
Update on GitHub