Accelerate documentation

التدريب على معالج إنتل

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

التدريب على معالج إنتل

كيف يعمل للتحسين أثناء التدريب على وحدة المعالجة المركزية

يدعم Accelerate معالجات Intel بشكل كامل، وكل ما عليك فعله هو تفعيله من خلال ملف الإعدادات.

السيناريو 1: تسريع تدريب المعالج المركزي دون توزيع

شغّل 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

على سبيل المثال، إليك كيفية تشغيل مثال معالجة اللغة الطبيعية examples/nlp_example.py (من جذر المستودع) باستخدام default_config.yaml الذي يتم إنشاؤه بواسطة accelerate config

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: تسريع التدريب الموزّع على المعالجات المركزية نستخدم Intel oneCCL للتواصل، مع دمج مكتبة Intel® MPI لتقديم رسائل عناقيد مرنة وفعالة وقابلة للتوسع على معمارية Intel®. يمكنك الرجوع إلى هنا لدليل التثبيت

شغّل accelerate config على جهازك (node0):

$ 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

على سبيل المثال، إليك كيفية تشغيل مثال معالجة اللغة الطبيعية examples/nlp_example.py (من جذر المستودع) للتدريب الموزّع على المعالجات المركزية.

default_config.yaml الذي يتم إنشاؤه بواسطة accelerate config

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) ثم تمرير مسار ملف الإعدادات هذا كحجة.

إذا اخترتَ أن يُطلق Accelerate الأمر mpirun، فتأكد من أن موقع ملف المضيف الخاص بك يطابق المسار الموجود في ملف الإعداد.

$ 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، وسيتم تفعيل 16DDP في node0 وnode1 وnode2 وnode3 مع دقة مختلطة BF16. عند استخدام هذه الطريقة، يجب أن يكون سكربت بايثون، وبيئة بايثون، وملف إعدادات 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