λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
1️⃣ AI•DS/πŸ“’ Deep learning

[인곡지λŠ₯] Federated Learning , Distributed Learning

by isdawell 2022. 6. 15.
728x90

Summary 


 

✨ Federated learning 

 

β—Ύ Exploits huge amount of data across clients 

β—Ύ data is non-IID 

β—Ύ Brief indroduction of FedAvg

 

 

✨ Distributed learning 

 

β—Ύ Make training Faster 

β—Ύ Data evenly distributed 

 

β—Ύ data parallel : Forward pass, Backward pass , Weight update 

   πŸ‘‰ Communication : Allreduce - ring reduction, One-host reduction 

 

β—Ύ Model parallel  

   πŸ‘‰  inter-layer parallel (pipeline) : sub-minibatches, interleaved layers 

   πŸ‘‰  intra-layer parallel : row-wise partitioning , column-wise partitioning , Alternating partitioning 

 

 

 

 

 

 

1️⃣  Federated learning


β‘   Decentralized data 

 

πŸ”˜ Data is born at the Edge 

 

β—Ύ λ°μ΄ν„°λŠ” edge μ—μ„œ μƒμ‚°λœλ‹€. 

β—Ύ μˆ˜λ§Žμ€ 슀마트폰과 IoT κΈ°κΈ°λ‘œλΆ€ν„° 데이터가 계속 μƒμ‚°λœλ‹€. 

β—Ύ λ°μ΄ν„°λ‘œλΆ€ν„° ν•™μŠ΅μ„ μ§„ν–‰ν•˜μ—¬ μ–‘μ§ˆμ˜ μ„œλΉ„μŠ€λ₯Ό λ§Œλ“ λ‹€. 

 

 

 

 

πŸ”˜ νƒˆμ€‘μ•™ν™”λœ data 

 

πŸ‘€ Centralized dataset  processed in integrated system 

 

β—Ύ λ¨Έμ‹ λŸ¬λ‹μ˜ ν‘œμ€€μ μΈ ν™˜κ²½μ€ μ€‘μ•™ν™”λœ 데이터셋이 있고 그것을 κΈ΄λ°€ν•˜κ²Œ μ—°κ²°λœ λŒ€κ·œλͺ¨ μ„œλ²„λ‘œ ν•™μŠ΅ν•˜κ²Œ λœλ‹€.

 

 

πŸ‘€ Often decentralized 

 

β—Ύ μ‹€μ„Έκ³„μ—μ„œλŠ” λ°μ΄ν„°λŠ” 일반적으둜 IoT κΈ°κΈ°, μ—¬λŸ¬ κΈ°κ΄€ λ“± λ‹€μ–‘ν•œ κ³³μ—μ„œ μƒμ‚°λ˜κΈ° λ•Œλ¬Έμ— 데이터가 λΆ„μ‚°ν™” λ˜μ–΄ μžˆλŠ” κ²½μš°κ°€ λ§Žλ‹€.

 

 

 

 

 

πŸ”˜ μ€‘μ•™ν™”λœ data λ°©μ‹μ˜ ν•œκ³„μ  

 

πŸ‘€ Sending the data is too costly 

 

β—Ύ edge device λ‘œλΆ€ν„° 쀑앙 μ„œλ²„λ‘œκΉŒμ§€ 데이터λ₯Ό λ³΄λ‚΄λŠ” κ³Όμ • μžμ²΄κ°€ 맀우 λ§Žμ€ λΉ„μš©μ„ μ†Œλͺ¨ν•œλ‹€. 

 

β—Ύ μžμœ¨μ£Όν–‰ μžλ™μ°¨λŠ” ν•˜λ£¨μ— Tera byte λ‹¨μœ„μ˜ 데이터λ₯Ό 맀일 μƒμ‚°ν•˜λŠ”λ°, μ΄λ ‡κ²Œ 큰 λ‹¨μœ„μ˜ 데이터λ₯Ό λ„€νŠΈμ›Œν¬λ₯Ό 톡해 μ„œλ²„λ‘œ λ³΄λ‚΄λŠ” 과정을 μˆ˜λ°˜ν•΄μ•Ό ν•˜λ©΄ 맀우 였랜 μ‹œκ°„ + μ—λ„ˆμ§€ + μ „λ ₯μ†Œλͺ¨κ°€ λ°œμƒν•œλ‹€. 

 

β—Ύ 무선 기기듀은 bandwidth λ‚˜ power κ°€ μ œν•œλ˜μ–΄ 있기 λ•Œλ¬Έμ— λ„€νŠΈμ›Œν¬λ‘œ 데이터λ₯Ό λ³΄λ‚΄λŠ”λ° λΉ„μš©μ΄ 많이 λ“ λ‹€. 

 

πŸ‘€ Data may be considered too sensitive : privacy 

 

β—Ύ  데이터 μ‚¬μƒν™œ λ¬Έμ œμ— λŒ€ν•œ 규제/μš°λ €μ§€μ  : λΆ„μ‚°ν™”λœ 데이터λ₯Ό 가지고 있으면 각 μ†Œμœ μžκ°€ 데이터λ₯Ό μ†Œμœ ν•˜κ³  μžˆλŠ”λ° λ°˜ν•˜μ—¬, μ€‘μ•™μ„œλ²„λ‘œ 데이터λ₯Ό λ³΄λ‚΄λŠ” μˆœκ°„, λ°μ΄ν„°μ˜ μ†Œμœ κ°€ 뢈λͺ…확해지며 데이터가 뢄싀될 μˆ˜λ„ 있음

 

β—Ύ  ν˜„λŒ€μ—λŠ” 데이터가 곧 ꢌλ ₯이기 λ•Œλ¬Έμ— 데이터λ₯Ό 가지고 μžˆλŠ” 것이 λΉ„μ¦ˆλ‹ˆμŠ€λ‚˜ 연ꡬλ₯Ό ν•˜λŠ”λ° μžˆμ–΄ 경쟁λ ₯을 λΆˆμ–΄μΌμœΌν‚€κ²Œ λœλ‹€. λ•Œλ¬Έμ— 데이터λ₯Ό 쀑앙 μ„œλ²„λ‘œ λ³΄λ‚Έλ‹€λŠ” 것은 데이터λ₯Ό λΉΌμ•—κΈ°λŠ” 것과 κ°™λ‹€. λ‹€λ₯Έ party μ—κ²Œ 데이터λ₯Ό μ „μ†‘ν•˜λŠ” 격이기 λ•Œλ¬Έμ— 데이터 μ†Œμœ  μΈ‘λ©΄μ—μ„œ 경쟁λ ₯을 μžƒκ²Œ λœλ‹€. 

 

 

 

β‘‘ On Device 

 

πŸ”˜ Data processing 

 

πŸ‘€ edge computing 

 

β—Ύ λ””λ°”μ΄μŠ€μ— λΆ„μ‚°ν™”λœ 데이터 ν˜•μ‹μœΌλ‘œ λ°”λ€Œκ³  있고, 데이터λ₯Ό μ²˜λ¦¬ν•˜λŠ” 것쑰차 μ„œλ²„μ—μ„œ μ²˜λ¦¬ν•˜λŠ” 것이 μ•„λ‹Œ, λ””λ°”μ΄μŠ€ λ‹¨μ—μ„œ μ²˜λ¦¬ν•˜λŠ” κ²ƒμœΌλ‘œ λ°”λ€Œκ³  μžˆλ‹€.

 

 

πŸ‘€ μž₯점 

 

 

β—Ύ Improved latency : 속도 지연에 κ°œμ„ μ„ κ°€μ Έμ˜¨λ‹€ → edge μ—μ„œ λ°”λ‘œ 데이터λ₯Ό μ²˜λ¦¬ν•˜λ―€λ‘œ 속도가 빠름

 

β—Ύ Works offline : λ„€νŠΈμ›Œν¬μ— μ—°κ²°λ˜μ–΄ μžˆμ§€ μ•Šμ•„λ„ μ˜€ν”„λΌμΈμ—μ„œ λ™μž‘ν•  수 있게 λœλ‹€.

 

β—Ύ Better battery life : 배터리 μ†Œλͺ¨λŸ‰μ„ 쀄일 수 있게 λœλ‹€.

 

β—Ύ Privacy advantages : 데이터λ₯Ό μ„œλ²„λ‘œ 보내지 μ•Šμ•„λ„ λ˜λ―€λ‘œ 전솑 쀑간에 데이터가 κ°ˆμ·¨λ˜κ±°λ‚˜ 쀑앙 μ„œλ²„κ°€ 해킹될 걱정이 μ—†μŒ (λ‹€λ₯Έ μ‚¬λžŒκ³Ό 데이터λ₯Ό κ³΅μœ ν•˜μ§€ μ•ŠκΈ° λ•Œλ¬Έμ— λ³΄μ•ˆμœ μ§€κ°€ κ°€λŠ₯함)

 

 

 

 

 

πŸ”˜ On-Device Training 

 

β—Ύ λ””λ°”μ΄μŠ€μ—μ„œ ν•™μŠ΅μ„ 진행 : Perform ML learning on devices with its own data

 

 

πŸ‘€ 단점 

 

β—Ύ local dataset may be too small : λ””λ°”μ΄μŠ€μ—μ„œ μˆ˜μ§‘λœ λ°μ΄ν„°μ˜ 크기가 μž‘κΈ° λ•Œλ¬Έμ— μ˜€λ²„ν”ΌνŒ…μ΄ 일어날 κ°€λŠ₯성이 λ†’μ•„ 예츑 μ„±λŠ₯이 쒋지 μ•Šμ„ 수 μžˆλ‹€.

 

β—Ύ local dataset may be biased : local dataset 이 편ν–₯λ˜μ–΄ training ν•˜κ³ μž ν•˜λŠ” target distribution 을 λŒ€λ³€ν•˜μ§€ μ•ŠλŠ” 데이터셋일 수 μžˆλ‹€. 

 

 

πŸ‘€ personalization

 

β—Ύ μœ„μ™€κ°™μ€ 단점을 λ•Œλ¬Έμ— on-device training 은 주둜 κ°œμΈν™”μ— 많이 μ‚¬μš©λœλ‹€. 

 

πŸ‘‰ ex. 손글씨 인식 μ–΄ν”Œ  : device λ‹¨μ—μ„œ 개인의 손글씨 데이터λ₯Ό μΆ•μ ν•˜κ³  μ„œλ²„μ—μ„œ 사전 ν›ˆλ ¨λœ λͺ¨λΈμ„ 가져와 fine tuning ν•˜λŠ” 과정을 톡해 μœ μ € 손글씨에 인식λ₯ μ„ 높인 μ„œλΉ„μŠ€λ₯Ό μ œκ³΅ν•  수 μžˆλ‹€. 

 

 

 

 

β‘’ Federated learning 

 

πŸ”˜ Federated learning 

 

πŸ‘€ collaboratively train a ML model while keeping the data decentralized

 

β—Ύ 데이터가 λΆ„μ‚° μ €μž₯ λ˜μ–΄ μžˆμ„ λ•Œ λ¨Έμ‹ λŸ¬λ‹ λͺ¨λΈμ„ μ—°ν•©ν•΄μ„œ 같이 ν›ˆλ ¨ ν•˜λŠ” 방식

 

β—Ύ μ΄μƒμ μœΌλ‘œλŠ”, μ΅œμ’… λͺ¨λΈμ΄ on-device ν›ˆλ ¨μœΌλ‘œ 얻어진 λͺ¨λΈλ³΄λ‹€ 더 쒋은 μ„±λŠ₯으둜 ν˜Ήμ€ μ€‘μ•™ν™”λœ μ„œλ²„μ—μ„œ ν›ˆλ ¨ν•œ λͺ¨λΈκ³Ό λΉ„μŠ·ν•œ κ²°κ³Όλ₯Ό μ–»κ²Œλ” ν•˜λŠ” 것

 

 

πŸ‘€ ν•™μŠ΅ κ³Όμ • 

 

 

1. Model initialization : μ„œλ²„μ—μ„œ neural network model 을 μƒμ„±ν•œλ‹€. 

2. μ„œλ²„μ—μ„œ μƒμ„±ν•œ 초기 λͺ¨λΈμ„ μ—°ν•©ν•™μŠ΅μ— μ°Έμ—¬ν•˜λŠ” device μ—κ²Œ μ „λ‹¬ν•œλ‹€.
  πŸ‘‰ 각 device λŠ” λ™μΌν•œ neural network model 을 ν• λ‹Ήλ°›μŒ

3. 각 device λŠ” 할당받은 초기 λͺ¨λΈλ‘œ 각자 ν›ˆλ ¨μ„ μ§„ν–‰ν•œλ‹€. 

4. 각 device μ—μ„œ ν›ˆλ ¨μ„ 톡해 얻은 weight gradient (dW) λ“€λ§Œ μ„œλ²„λ‘œ λ³΄λ‚΄μ„œ μ„œλ²„μ˜ λͺ¨λΈμ„ μ—…λ°μ΄νŠΈ ν•œλ‹€. 

 

⭐ 데이터λ₯Ό 직접 λ³΄λ‚΄λŠ” 것이 μ•„λ‹ˆλΌ weight  gradient λ₯Ό 보내기 λ•Œλ¬Έμ— data privacy κ°€ μœ μ§€λœλ‹€.

 

 

 

 

πŸ”˜ νŠΉμ§•

 

1. λ°μ΄ν„°λŠ” local μ—μ„œ μƒμ„±λœλ©° λ°μ΄ν„°λŠ” μ„œλ²„μ— λͺ¨μ΄μ§€ μ•Šκ³ , λΆ„μ‚°ν™”λœ μ±„λ‘œ μ‘΄μž¬ν•œλ‹€.

2. 각 client (device) κ°€ 본인의 데이터λ₯Ό 가지고 있고, λ‹€λ₯Έ client 의 데이터에 μ ‘κ·Όν•  수 μ—†λ‹€.
   πŸ‘‰ privacy κ°€ λ³΄μ‘΄λœλ‹€. 

3. client λŠ” weight gradient κ°’λ§Œ μ„œλ²„λ‘œ 보낸닀. 

4. Data λŠ” non-IID νŠΉμ§•μ„ 가진닀 : 데이터가 λΉ„ 독립적이고 λ™μΌν•˜κ²Œ λΆ„μ‚°λ˜μ–΄ μžˆμ§€ μ•Šλ‹€.

not identically distributed
  : data distribution 이 client data λ§ˆλ‹€ λ‹€λ₯΄κΈ° λ•Œλ¬Έμ— ν•™μŠ΅μ΄ μ „ν˜€ λ‹€λ₯Έ μ–‘μƒμœΌλ‘œ 이루어짐

not independently
 : 데이터가 λΉ„λ…λ¦½μ μ΄λ‹€λΌλŠ” 것은 ν•œ 데이터가 λ‹€λ₯Έ 데이터에 쒅속적 일 수 μžˆλ‹€λŠ” 것

⭐ μ΄λŸ¬ν•œ νŠΉμ§•μœΌλ‘œ 인해 μ—°ν•©ν•™μŠ΅μ€  global ν•˜κ²Œ μ΅œμ ν™”λœ λͺ¨λΈμ„ λ§Œλ“€κΈ° μ–΄λ ΅λ‹€. λ”°λΌμ„œ μ—°ν•©ν•™μŠ΅ μ—°κ΅¬μ˜ μ΅œμ‹  흐름은 non-IID μƒν™©μ—μ„œλ„ ν›ˆλ ¨μ΄ global ν•˜κ²Œ 이루어지도둝 ν•˜λŠ” 것에 μ§‘μ€‘λ˜μ–΄ μžˆλ‹€. 


5. μ—°ν•©ν•™μŠ΅μ˜ baseline μ•Œκ³ λ¦¬μ¦˜ : FedAvg


 

Data 의 non-IID μ„±μ§ˆ example

 

 

 

 

β‘£ FedAvg 

 

πŸ‘‰ FedAvg λŠ” strong non-IIDμ—μ„œ 잘 λ™μž‘ν•˜μ§€ μ•ŠλŠ”λ‹€.

πŸ‘‰ FedAvgκ°€ 졜초의 μ—°ν•©ν•™μŠ΅ μ•Œκ³ λ¦¬μ¦˜μ΄λΌ non-IID λ™μž‘ μ—¬λΆ€κ°€ λΆˆμ•ˆμ •ν•˜λ‹€.

 

 

πŸ”˜ Notations 

 

β—Ύ K clients 

 

β—Ύ Each client k holds dataset Dk of nk samples 

 

β—Ύ D : joint dataset 

 

β—Ύ n : total number of samples

 

 

πŸ‘€ loss λ₯Ό μ΅œμ†Œν™”ν•˜λŠ” νŒŒλΌλ―Έν„° θ λ₯Ό μ°ΎκΈ° 

 

πŸ‘‰ F(θ ; D)  : loss function

 

 

 

πŸ‘‰ 즉, 각 client κ°€ 각각의 λ°μ΄ν„°μ…‹μœΌλ‘œ ν•™μŠ΅μ„ μˆ˜ν–‰ν•  것이고, 그것을 ν‰κ· ν•œ 것이 μ΅œμ’… loss function이 λœλ‹€. 이 loss function 을 μ΅œμ†Œν™”ν•˜λŠ” 것이 λͺ©ν‘œ!

 

 

 

πŸ”˜ Local SGD 

 

 

⭐ Client sampling rate ρ

⭐ ClientUpdate : λ³‘λ ¬μ μœΌλ‘œ weight update λ₯Ό μˆ˜ν–‰ 

⭐ Local step L, Batch size B 

 

 

πŸ’¨ classic parallel SGD

 

πŸ’¨ local SGD

 

 

→ local SGD 둜 ν›ˆλ ¨ν•˜λŠ” 것이 IID data ν˜•νƒœλ‘œ μˆ˜λ ΄ν•œλ‹€λŠ” 것이 증λͺ…λ˜μ–΄μžˆλ‹€

 

 

 

 

 

 

 

 

πŸ‘€ Federated learning VS  Distributed learning


β‘   Federated learning 

 

β—Ύ μ‹€μš©ν™” λ‹¨κ³„κΉŒμ§€ 가지 λͺ»ν•¨ 

β—Ύ client 둜 λΆ„μ‚°ν™”λœ 데이터λ₯Ό ν™œμš©ν•˜λŠ” 것이 μ£Ό λͺ©ν‘œ

β—Ύ 데이터가 본질적으둜 λΆ„μ‚°λ˜μ–΄μžˆκ³  κ΅­μ§€μ μœΌλ‘œ μƒμ‚°λœλ‹€.

β—Ύ data κ°€ non-IID μ„±μ§ˆμ„ 가지며 λΆˆκ· ν˜•ν•˜κ²Œ λΆ„ν¬ν•œλ‹€.

β—Ύ privacy λ₯Ό κ°•ν™”ν•œλ‹€.

β—Ύ limited reliability/availability : 각 μ°Έμ—¬μžμ˜ μ œν•œλœ reliability λ₯Ό κ³ λ €ν•΄μ•Ό ν•œλ‹€. μ—°ν•©ν•™μŠ΅μ„ ν•˜λ©΄μ„œ νŠΉμ • client κ°€ offline 이 λ˜κ±°λ‚˜, λ„€νŠΈμ›Œν¬κ°€ λΆˆμ•ˆμ •ν•΄μ§ˆ 수 μžˆλ‹€λŠ” 상황도 κ³ λ €ν•΄μ•Ό ν•œλ‹€λŠ” 뜻!

β—Ύ robustness against malicious clients : μ•…μ˜μ μΈ client 에 λŒ€μ‘ν•˜μ—¬ 잘 λ™μž‘ν•΄μ•Ό ν•œλ‹€.

 

 

β‘‘ Distributed learning 

 

β—Ύ 주된 λͺ©ν‘œ : ν•™μŠ΅μ„ λΆ„μ‚°ν•΄μ„œ μ²˜λ¦¬ν•˜κ² λ‹€ (데이터 κ΄€μ μ—μ„œμ˜ 뢄산이 μ•„λ‹˜) πŸ‘‰ ν•™μŠ΅μ„ μ—¬λŸ¬ μ»΄ν“¨ν„°λ‘œ λΆ„μ‚°ν•΄μ„œ μˆ˜ν–‰ πŸ‘‰  병렬성을 μ΄μš©ν•΄ 더 λΉ λ₯Έ ν•™μŠ΅μ„ ν•˜λ„λ‘ 함 

β—Ύ client (worker) 듀이 데이터λ₯Ό 직접 λΆ„μ‚°μ‹œμΌœμ€Œ

β—Ύ 일반적으둜 λžœλ€ν•˜κ²Œ uniform 뢄포λ₯Ό 가지고 λΆ„μ‚°λœλ‹€. 

 

 

 

 

 

 

 

 

 

4️⃣  Distributed learning


β‘   Parallelism Taxonomy

 

πŸ”˜ 병렬 ν•™μŠ΅μ˜ μ’…λ₯˜ 

 

⭐ 병렬성을 μ΄μš©ν•΄ μ—¬λŸ¬ μ»΄ν“¨ν„°λ‘œ ν›ˆλ ¨μ„ μ§„ν–‰ν•œλ‹€.

 

 

 

 

πŸ”˜ ν•™μŠ΅ κ³Όμ •μ—μ„œμ˜ μ—°μ‚° 단계 

 

πŸ’¨ Forward pass : W•X = Y 

 

 

πŸ’¨ Backward pass (weight gradients) : dY•X' = dW

 

 

 

πŸ’¨ Backward pass (activation gradients) : W'•dY = dX

 

 

 

πŸ’¨ Weight update 

 

 

 

 

β‘‘ Data parallel 

 

πŸ”˜ μ—°μ‚°κ°œμš”  

 

 

πŸ‘€ Each worker 

 

β—Ύ 전체 entire neural network model 의 볡사본을 가지고 μžˆλ‹€. 

β—Ύ μ „체 neural network 을 톡해 data 의 일뢀λ₯Ό κ³„μ‚°ν•˜κ²Œ λœλ‹€ → training minibatch

 

 

πŸ‘€ Forward pass 

 

β—Ύ 각 worker κ°€ 각자 λ‹΄λ‹Ήν•œ λ―Έλ‹ˆλ°°μΉ˜ 데이터셋 만큼의 output activation 을 κ³„μ‚°ν•œλ‹€. 

⭐ No communication is needed

 

 

 

πŸ‘€ Backward pass 

 

β—Ύ 각 worker κ°€ 각자 λ‹΄λ‹Ήν•œ λ―Έλ‹ˆλ°°μΉ˜ 데이터셋 만큼의 activation gradient 을 κ³„μ‚°ν•œλ‹€. 

⭐ communication is needed

 

: Computes contribution to the weight gradient based on its portion of minibatch →  weight gradient λŠ”  (λ―Έλ‹ˆλ°°μΉ˜μ— λŒ€ν•΄ μ—…λ°μ΄νŠΈ ν•˜μ§€ μ•Šκ³ ) μ „체 batch 에 λŒ€ν•΄μ„œ μ—…λ°μ΄νŠΈλ₯Ό ν•΄μ£ΌκΈ° λ•Œλ¬Έμ—μžκΈ°κ°€ 맑은 λΆ€λΆ„μ˜ gradient 값을 전체 λͺ¨λΈμ— κ³΅μœ ν•œλ‹€.

 

 

 

πŸ‘€ Weight update

 

β—Ύ Each worker updates its copy of the model with combined gradients → 각 worker κ°€ 가지고 μžˆλŠ” λͺ¨λΈμ— λŒ€ν•΄ 전체 weight μ—…λ°μ΄νŠΈλ₯Ό μ‹œμΌœμ€Œ

 

 

 

 

 

πŸ”˜ Multi-GPU

 

 

β—Ύ 각 GPU λŠ” model 의 볡사본을 가지고 μžˆλ‹€. 

 

 

 

πŸ”˜ Forward Pass

 

 

β—Ύ 각 worker λŠ” λ™μΌν•œ weight matrix W λ₯Ό 가지고  λ‚˜λˆ λ°›μ€ input X 의 일뢀뢄을 가지고 output activation Y λ₯Ό κ΅¬ν•œλ‹€. 

 

β—Ύ κ° worker 에 λŒ€ν•΄ output 만 κ³„μ‚°ν•˜λ©΄ λ˜λ―€λ‘œ worker λ“€ 사이에 communication 은 ν•„μš”ν•˜μ§€ μ•Šλ‹€. 

 

 

 

πŸ”˜ Backward Pass

 

 

 

 

β—Ύ 각 worker λŠ” μ„œλ‘œ λ‹€λ₯Έ weight gradient dW λ₯Ό κ³„μ‚°ν•˜κ²Œ λœλ‹€. 

 

β—Ύ 각 worker λŠ” entire model ꡬ쑰λ₯Ό 가지고 있기 λ•Œλ¬Έμ— entire weight update λ₯Ό μœ„ν•΄μ„œλŠ” 각자 μ—°μ‚°ν•œ dW λ₯Ό κ³΅μœ ν•΄μ•Ό ν•œλ‹€. λ”°λΌμ„œ worker 사이에 communication 이 λ°œμƒν•œλ‹€. 

 

 

 

 

πŸ”˜ Communication 

 

 

πŸ‘€ communication 을 μž˜ν• μˆ˜λ‘ 속도가 빨라진닀.

πŸ‘€ communication 을 μ–΄λ–»κ²Œ ν•˜λŠλƒμ— 따라 data parallel 의 effciency κ°€ 달라진닀.

 

 

⭐ Allreduce 

 

β—Ύ Sum : 각 worker λ“€μ˜ gradient 값을 λͺ¨λ‘ 더해쀀닀. 

β—Ύ Distribute : 더해진 gradient λ₯Ό 각 worker μ—κ²Œ λΆ„λ°°μ‹œν‚¨λ‹€. 

 

β—Ύ After Allreduce : allreduce κ°€ λλ‚˜λ©΄ 각 worker λŠ” λ™μΌν•œ global gradient 값을 κ°€μ§€κ²Œ 됨 → 각 worker 듀이 λ‹€μŒ step 의 ν›ˆλ ¨μ„ ν•˜κΈ° μœ„ν•΄μ„  같은 copy 의 weight λ₯Ό 가지고 μžˆμ–΄μ•Όν•¨

 

β—Ύ dWλ₯Ό λ¨Όμ € κ³„μ‚°ν•˜κ³  μ„œλ‘œ κ³΅μœ ν•˜λŠ” 과정이 이루어지기 λ•Œλ¬Έμ— communication overhead κ°€ λΆˆκ°€ν”Όν•˜κ²Œ λ°œμƒν•œλ‹€

 

dW λ₯Ό κ³„μ‚°ν•˜λŠ” κ³Όμ •κ³Ό, dW λ₯Ό κ³΅μœ ν•˜λŠ” 과정이 λ™μ‹œμ— λ³‘λ ¬μ μœΌλ‘œ λ°œμƒν•˜λŠ” 것이 κ°€μž₯ 이상적인 λͺ¨μŠ΅

 

 

πŸ”˜ Allreduce

 

πŸ‘€ Allreduce = reduce + broadcast 

 

β—Ύ reduce  = (N-1) 개의 μ£Όλ³€ worker λ‘œλΆ€ν„° 1/N 만큼의 gradient 듀을 λ°›μ•„ λͺ¨λ‘ λ”ν•œλ‹€. 

β—Ύ broadcast = 더해진 값을 λ‹€μ‹œ (N-1) 개의 μ£Όλ³€ worker λ“€μ—κ²Œ λΆ„λ°°μ‹œν‚¨λ‹€. 

β—Ύ reduce 와 broadcast λ₯Ό μ–΄λ–€ λ°©μ‹μœΌλ‘œ ν•˜λŠλƒμ— 따라 2개둜 λ‚˜λ‰œλ‹€. 

 

 

πŸ‘€ Ring reduction 

 

β—Ύ ring ν˜•νƒœμ˜ topology λ₯Ό 가진 경우

 

β—Ύ 각 worker κ°€ μ–‘μ˜†μ˜ 2개의 이웃과 톡신함

 

β—Ύ 총 2(N-1) 단계가 μ†Œμš”λ˜κ³ , 각 worker λŠ” 총 λ°μ΄ν„°μ˜ 1/N 만큼의 양을 λ³΄λ‚΄κ±°λ‚˜ λ°›λŠ”λ‹€. 

 

 

πŸ‘€ One-shot reduction 

 

β—Ύ  fully-connected ν˜•νƒœμ˜ topology λ₯Ό 가진 경우

 

 

β—Ύ κ° worker λŠ” μ„œλ‘œ ν•œλ²ˆμ”© μ—°κ²°λ˜μ–΄ μžˆλŠ” ν˜•νƒœμ΄κΈ° λ•Œλ¬Έμ— (N-1) 개의 이웃 worker λ“€κ³Ό ν†΅μ‹ ν•˜κ²Œ λœλ‹€

 

β—Ύ 각 worker κΈ°μ€€μœΌλ‘œ, μ£Όλ³€ worker λ“€λ‘œλΆ€ν„° λ°›κ³ , worker λ“€μ—κ²Œ μ „λ‹¬ν•˜λŠ” 총 2 λ‹¨κ³„μ˜ 과정이 μ†Œμš”λœλ‹€ (each with (N-1) substeps)

 

 

 

 

πŸ”˜ Rring allreduce example 

 

β—Ύ weight gradient λ₯Ό ring tolopgy μ—μ„œ κ³΅μœ ν•˜λŠ” κ³Όμ • 

 

πŸ‘€ Reduce

 

step1

 

step2

 

step3

 

 

 

πŸ‘€ Broadcast

 

step1,2,3 단계가 μ†Œμš”

 

πŸ‘‰ 2*(N-1) = 2*3 = 6 단계가 μ†Œμš”λ¨ 

 

 

πŸ”˜ API 

 

β—Ύ API λ₯Ό 톡해 λΆ„μ‚° μ»΄ν“¨νŒ…μ„ 진행할 수 μžˆλ‹€. 

 

 

 

 

 

β‘’ Model parallel 

 

πŸ”˜ model parallel

 

πŸ’¨ Inter layer parallel = pipeline parallel 

 

portion of ✨ the layer

 

πŸ’¨ Intra layer parallel

 

portion of  ✨each layer

 

 

 

πŸ”˜ Pipeline parallel 

 

πŸ’¨ Idle bubbles 

 

πŸ“Œ N 개의 worker 듀에 λŒ€ν•΄ (N-1)/N λΉ„μœ¨ 만큼의 idle slot 이 μ‘΄μž¬ν•¨ → λΉ„νš¨μœ¨μ  

 

 

 

 

πŸ’¨ Sub-minibatches 

 

πŸ“Œ λΉ„νš¨μœ¨μ„±μ„ 쀄이기 μœ„ν•΄ ν•˜λ‚˜μ˜ minibatch λ₯Ό k개의 subminibatch 둜 λ‚˜λˆˆλ‹€

 

μ •λ³΄ν†΅μ‹ κ³΅ν•™μ—μ„œ packet 을 λ‚˜λˆ μ„œ μ²˜λ¦¬ν•˜λŠ” κ³Όμ •κ³Ό λΉ„μŠ·

 

 

πŸ“Œ N 이 컀질수둝 idel slot 의 κ°œμˆ˜κ°€ 쀄어든닀 

 

 

 

πŸ’¨ Interleaved Layers

 

πŸ“Œ κ° worker κ°€ layer λ₯Ό λΆˆμ—°μ†μ μœΌλ‘œ λ‹΄λ‹Ήν•˜μ—¬ ν›ˆλ ¨ν•œλ‹€. 

 

 

 

β—Ύ μž₯점 : worker κ°€ μΌν•˜λŠ” μ‹œκ°„μ΄ μ¦κ°€ν•œλ‹€. 

 

πŸ‘‰ worker0 의 κ΄€μ μ—μ„œ 보면 forward λ‹¨κ³„μ—μ„œ 6개의 step 쀑에 4개의 time step λ™μ•ˆ μΌν•˜κ³  있음 (효율적)

 

 

β—Ύ 단점 

 

πŸ‘‰ communication νšŸμˆ˜κ°€ 증가함 : worker κ°€ μ—¬λŸ¬ layer λ₯Ό μ—°μ†μ μœΌλ‘œ λ‹΄λ‹Ήν•˜μ—¬ ν›ˆλ ¨μ„ μ§„ν–‰ν•˜λŠ” 것이 μ•„λ‹ˆκΈ° λ•Œλ¬Έμ—, weight gradient 의 전달 νšŸμˆ˜κ°€ μ¦κ°€ν•˜κ²Œ λœλ‹€. 

 

πŸ‘‰ skip connection cross worker 이 λ³΅μž‘ν•˜κ²Œ λ°œμƒν•œλ‹€ : worker0 이 가진 κ²°κ³Όλ₯Ό worker2 와 κ²°ν•©ν•˜λŠ” κ³Όμ •μ—μ„œ worker1 을 κ±΄λ„ˆ λ›°κ³  값을 μ „λ‹¬ν•΄μ•Όν•˜λŠ”λ° 이 κ³Όμ •μ—μ„œ λ°œμƒν•˜λŠ” communication 이 λ³΅μž‘ν•˜λ‹€. 

 

 

 

πŸ’¨ Communication in Inter-layer parellel

 

β—Ύ  2개의 neighbor 와 톡신 → worker1 을 κΈ°μ€€μœΌλ‘œ worker0 μœΌλ‘œλΆ€ν„° 데이터λ₯Ό λ°›κ³ , worker2 μ—κ²Œ 데이터λ₯Ό μ „λ‹¬ν•˜λŠ” κ³Όμ • 

 

β—Ύ  forward 와 backward step λ§ˆλ‹€ communication 이 λ°œμƒν•¨

 

β—Ύ  forward μ—μ„œλŠ” activation 을 λ„˜κ²¨μ£Όκ³  backward μ—μ„œλŠ” activation gradient λ₯Ό λ„˜κ²¨μ€Œ

 

β—Ύ  μ—°μ‚°κ³Ό 톡신을 overlap μ‹œν‚€λŠ” 것이 맀우 μ–΄λ ΅λ‹€. 연산이 λλ‚˜μ•Όλ§Œ 톡신이 κ°€λŠ₯ν•œ κ΅¬μ‘°μ΄λ―€λ‘œ 톡신뢀뢄이 μ˜¨μ „νžˆ overhead 둜 μž‘μš©ν•˜κ²Œ λœλ‹€.

 

 

 

πŸ”˜ Intra layer parallel 

 

 

β—Ύ  layer weight λ₯Ό worker 간에 μž˜λΌμ„œ μˆ˜ν–‰ν•¨

β—Ύ idle slot , load imbalance 문제λ₯Ό ν•΄κ²°ν•  수 μžˆλ‹€.

 

πŸ’¨ weight matrix λ₯Ό μ–΄λ–»κ²Œ λ‚˜λˆ„μ–΄ λ‹΄λ‹Ήν•˜λŠ”μ§€ 따라 2개둜 λ‚˜λ‰œλ‹€.

 

 

 

 

πŸ’¨ Row-Wise partitioning 

 

πŸ“Œ κ° worker κ°€ weight 의 일뢀 ν–‰ λΆ€λΆ„κ³Ό, λͺ¨λ“  input activation 을 가지고 연산을 μˆ˜ν–‰ν•˜μ—¬ output activation 값을 λ„μΆœν•œλ‹€. 

 

πŸ“Œ forward communication : Allgather → λ‹€μŒ layer μ—μ„œ ν•„μš”ν•œ activation ν˜•νƒœλ₯Ό μœ„ν•΄ λͺ¨λ‘ 더함

 

각 worker μ—μ„œ λ„μΆœν•œ output activation 을 ν•©ν•˜μ—¬ λ‹€μŒ layer 둜 전달

 

 

πŸ’¨ Column-Wise partitioning 

 

πŸ“Œ κ° worker κ°€ weight 의 일뢀 칼럼 λΆ€λΆ„κ³Ό,  input activation 의 일뢀뢄을 가지고 연산을 μˆ˜ν–‰ν•˜μ—¬ partial activation 값을 λ„μΆœν•œλ‹€.

 

πŸ“Œ forward communication : Reduce_scatter → 각 worker 의 output 에 λŒ€ν•΄ 각 μœ„μΉ˜μ— 맞게 값을 더해  partial activation 을 μ–»λŠ”λ‹€. 

 

 

πŸ’¨ Alternating partitioning 

 

πŸ“Œ row-wise 와 column wise λ₯Ό λ²ˆκ°ˆμ•„ μ‚¬μš©ν•˜λ©΄ communication 과정이 ν•„μš” μ—†μŒ

πŸ“Œ 단, col μ—μ„œ row 둜 λ‹€μ‹œ λ„˜μ–΄κ°ˆ 땐 Allreduce 과정이 ν•„μš”

 

 

 

 

β‘£ Communication pattern summary 

 

πŸ”˜ Data parallel 

 

- Allreduce of weights

- Can be overlapped with computation (overhead λ₯Ό μ‘°κΈˆμ΄λΌλ„ 쀄일 수 μžˆλ‹€) 

 

 

πŸ”˜ model Inter parallel 

 

- Point-wise communication : μ„œλ‘œλ‹€λ₯Έ neighbor 와 1:1 communication 이 λ°œμƒ

- Hard to overlap with computation (overhead κ°€ λΆˆκ°€κ²°ν•˜κ²Œ λ°œμƒ)

- Hard to load-balance (μ–΄λ–€ worker λŠ” 더 λ§Žμ€ 일을 ν•˜κ²Œ 됨)

 

 

 

πŸ”˜ model Intra parallel 

 

-  Allgather, reduce_scatter of activations and activation gradients

- row wise 와 col wise λ₯Ό λ™μ‹œμ— λ²ˆκ°ˆμ•„ μ‚¬μš©ν•˜λ©΄ Allreduce κ°€ λ°œμƒ 

- Hard to overlap with computation

 

πŸ‘‰ model parallel 은 overlap이 μ–΄λ ΅κΈ° λ•Œλ¬Έμ—  주둜 μ΄ˆκ±°λŒ€ AI 인 κ²½μš°μ—λ§Œ μ‚¬μš©ν•œλ‹€.

 

 

 

 

728x90

λŒ“κΈ€