ๅฏนไบ Column-wise TP๏ผ
๐[๐1๐2โฏ๐๐]=[๐๐1๐๐2โฏ๐๐๐]
ๅๅไผ ๆญ็ๆถๅ๏ผไปค ๐๐=๐๐๐๏ผ
๐L๐๐๐=๐โค๐L๐๐๐,๐L๐๐=๐โ๐=1๐๐ฟ๐๐๐๐โค๐
ๅฏนไบ Row-wise TP๏ผ
[๐1๐2โฏ๐๐]โกโข
โข
โข
โขโฃ๐1๐2โฎ๐๐โคโฅ
โฅ
โฅ
โฅโฆ=๐โ๐=1๐๐๐๐
ๅๅไผ ๆญ็ๆถๅ๏ผไปคๆฑๅ็ปๆไธบ ๐๏ผ
๐L๐๐๐=๐โค๐๐L๐๐,๐L๐๐๐=๐L๐๐๐โค๐
ๅฏนไบไธไธช MLP
MLP(๐ฅ)=๐(๐๐1)๐2
ๆไปฌๅฏไปฅๅฐ ๐1 ๅ Column-wise ๆๅ๏ผ๐2 ๅ Row-wise ๆๅ๏ผ่ฟๆ ทๅญๅๅฎ ๐๐1 ไนๅไธ้่ฆๅ All-Gather๏ผๅๅไผ ๆญ่ฟๅฎ ๐2 ไนๅไนไธ้่ฆ All-Gather ๅฎๆดๆขฏๅบฆใ
ๅฏนไบ attention๏ผ่่ๅฐ Megatron (Shoeybi et al., 2020) ้ๆฒกๆ่่ number of attention heads ๅคงไบ TP ็ๆ
ๅต๏ผไปฃ็ ไฝ็ฝฎ๏ผ๏ผๆไปฌไนๅช่ฎจ่ฎบ่ฟไธ็น
if self.num_attention_heads % self.tensor_model_parallel_size != 0:
raise ValueError(
f"num_attention_heads ({self.num_attention_heads}) must be a multiple of "
f"tensor_model_parallel_size ({self.tensor_model_parallel_size})."
)
ๅฏนไบ MHA ๅฐฑ้ๅธธๅฅฝๅไบ๏ผๅฏนไบ
๐=[๐1๐2โฏ๐โ]๐๐๐๐ก=Attention(๐๐(๐ก)๐,๐๐(๐ก)๐,๐๐(๐ก)๐ฃ)
ๆไปฌๅฐ ๐๐ ่ฟ่ก Row-wise ๅๅใ็ถๅๆฏๅผ ๅกๅ็ฌ่ฎก็ฎไธๅฎ้็ heads๏ผ่ฟๆ ทๅญๅคฉ็ถๆฏไธไธช Column-wise ๅๅ็็ถๆใ
References
Shoeybi, M., Patwary, M., Puri, R., LeGresley, P., Casper, J., & Catanzaro, B. (2020).
Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism.
arxiv.org