-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathTP_tutorial.html
1054 lines (873 loc) ยท 89.4 KB
/
TP_tutorial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="ko" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="ko" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta property="og:title" content="Large Scale Transformer model training with Tensor Parallel (TP)" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://tutorials.pytorch.kr/intermediate/TP_tutorial.html" />
<meta property="og:site_name" content="PyTorch Tutorials KR" />
<meta property="og:description" content="Author: Wanchao Liang, Tianyu Liu This tutorial demonstrates how to train a large Transformer-like model across hundreds to thousands of GPUs using Tensor Parallel and Fully Sharded Data Parallel. Prerequisites: PyTorch 2.3.0 or later installed with CUDA/Linux, Tensor Parallel APIs, Getting Start..." />
<meta property="og:image" content="https://tutorials.pytorch.kr/_static/logos/logo-kr-sm-dark.png" />
<meta property="og:image:alt" content="PyTorch Tutorials KR" />
<meta name="description" content="Author: Wanchao Liang, Tianyu Liu This tutorial demonstrates how to train a large Transformer-like model across hundreds to thousands of GPUs using Tensor Parallel and Fully Sharded Data Parallel. Prerequisites: PyTorch 2.3.0 or later installed with CUDA/Linux, Tensor Parallel APIs, Getting Start..." />
<meta property="og:ignore_canonical" content="true" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Large Scale Transformer model training with Tensor Parallel (TP) — ํ์ดํ ์น ํ๊ตญ์ด ํํ ๋ฆฌ์ผ (PyTorch tutorials in Korean)</title>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<!-- <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> -->
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/copybutton.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/katex-math.css" type="text/css" />
<link rel="stylesheet" href="../_static/sg_gallery.css" type="text/css" />
<link rel="stylesheet" href="../_static/sg_gallery-binder.css" type="text/css" />
<link rel="stylesheet" href="../_static/sg_gallery-dataframe.css" type="text/css" />
<link rel="stylesheet" href="../_static/sg_gallery-rendered-html.css" type="text/css" />
<link rel="stylesheet" href="../_static/sphinx-design.5ea377869091fd0449014c60fc090103.min.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/custom2.css" type="text/css" />
<link rel="index" title="์์ธ" href="../genindex.html" />
<link rel="search" title="๊ฒ์" href="../search.html" />
<link rel="next" title="Cpp ํ์ฅ์ ์ฌ์ฉํ ํ๋ก์ธ์ค ๊ทธ๋ฃน ๋ฐฑ์๋ ์ฌ์ฉ์ ์ ์" href="process_group_cpp_extension_tutorial.html" />
<link rel="prev" title="Advanced Model Training with Fully Sharded Data Parallel (FSDP)" href="FSDP_adavnced_tutorial.html" />
<script src="../_static/js/modernizr.min.js"></script>
<!-- Preload the theme fonts -->
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<!-- Preload the katex fonts -->
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/katex@0.10.0/dist/fonts/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.2/css/all.css" integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu" crossorigin="anonymous">
</head>
<div class="container-fluid header-holder tutorials-header" id="header-holder">
<div class="container">
<div class="header-container">
<a class="header-logo" href="https://pytorch.kr/" aria-label="PyTorch"></a>
<div class="main-menu">
<ul>
<li>
<a href="https://pytorch.kr/get-started">์์ํ๊ธฐ</a>
</li>
<li class="active">
<a href="https://tutorials.pytorch.kr/">ํํ ๋ฆฌ์ผ</a>
</li>
<li>
<a href="https://pytorch.kr/hub">ํ๋ธ</a>
</li>
<li>
<a href="https://discuss.pytorch.kr/">์ปค๋ฎค๋ํฐ</a>
</li>
</ul>
</div>
<a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a>
</div>
</div>
</div>
<body class="pytorch-body">
<div class="table-of-contents-link-wrapper">
<span>Table of Contents</span>
<a href="#" class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></a>
</div>
<nav data-toggle="wy-nav-shift" class="pytorch-left-menu" id="pytorch-left-menu">
<div class="pytorch-side-scroll">
<div class="pytorch-menu pytorch-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<div class="pytorch-left-menu-search">
<div class="version">
2.3.1+cu121
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search Tutorials" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<p class="caption" role="heading"><span class="caption-text">ํ์ดํ ์น(PyTorch) ๋ ์ํผ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../recipes/recipes_index.html">๋ชจ๋ ๋ ์ํผ ๋ณด๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../prototype/prototype_index.html">๋ชจ๋ ํ๋กํ ํ์
๋ ์ํผ ๋ณด๊ธฐ</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">ํ์ดํ ์น(PyTorch) ์์ํ๊ธฐ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/intro.html">ํ์ดํ ์น(PyTorch) ๊ธฐ๋ณธ ์ตํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/quickstart_tutorial.html">๋น ๋ฅธ ์์(Quickstart)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/tensorqs_tutorial.html">ํ
์(Tensor)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/data_tutorial.html">Dataset๊ณผ DataLoader</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/transforms_tutorial.html">๋ณํ(Transform)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/buildmodel_tutorial.html">์ ๊ฒฝ๋ง ๋ชจ๋ธ ๊ตฌ์ฑํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/autogradqs_tutorial.html"><code class="docutils literal notranslate"><span class="pre">torch.autograd</span></code>๋ฅผ ์ฌ์ฉํ ์๋ ๋ฏธ๋ถ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/optimization_tutorial.html">๋ชจ๋ธ ๋งค๊ฐ๋ณ์ ์ต์ ํํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/basics/saveloadrun_tutorial.html">๋ชจ๋ธ ์ ์ฅํ๊ณ ๋ถ๋ฌ์ค๊ธฐ</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Introduction to PyTorch on YouTube</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt.html">PyTorch ์๊ฐ - YouTube ์๋ฆฌ์ฆ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/introyt1_tutorial.html">PyTorch ์๊ฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/tensors_deeper_tutorial.html">Pytorch Tensor ์๊ฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/autogradyt_tutorial.html">The Fundamentals of Autograd</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/modelsyt_tutorial.html">Building Models with PyTorch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/tensorboardyt_tutorial.html">PyTorch TensorBoard Support</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/trainingyt.html">Training with PyTorch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/captumyt.html">Model Understanding with Captum</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">ํ์ดํ ์น(PyTorch) ๋ฐฐ์ฐ๊ธฐ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/deep_learning_60min_blitz.html">PyTorch๋ก ๋ฅ๋ฌ๋ํ๊ธฐ: 60๋ถ๋ง์ ๋์ฅ๋ด๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/pytorch_with_examples.html">์์ ๋ก ๋ฐฐ์ฐ๋ ํ์ดํ ์น(PyTorch)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/nn_tutorial.html"><cite>torch.nn</cite> ์ด <em>์ค์ ๋ก</em> ๋ฌด์์ธ๊ฐ์?</a></li>
<li class="toctree-l1"><a class="reference internal" href="tensorboard_tutorial.html">TensorBoard๋ก ๋ชจ๋ธ, ๋ฐ์ดํฐ, ํ์ต ์๊ฐํํ๊ธฐ</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">์ด๋ฏธ์ง/๋น๋์ค</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="torchvision_tutorial.html">TorchVision Object Detection Finetuning Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/transfer_learning_tutorial.html">์ปดํจํฐ ๋น์ (Vision)์ ์ํ ์ ์ดํ์ต(Transfer Learning)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/fgsm_tutorial.html">์ ๋์ ์์ ์์ฑ(Adversarial Example Generation)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/dcgan_faces_tutorial.html">DCGAN ํํ ๋ฆฌ์ผ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/vt_tutorial.html">๋ฐฐํฌ๋ฅผ ์ํด ๋น์ ํธ๋์คํฌ๋จธ(Vision Transformer) ๋ชจ๋ธ ์ต์ ํํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="tiatoolbox_tutorial.html">Whole Slide Image Classification Using PyTorch and TIAToolbox</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">์ค๋์ค</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/audio_io_tutorial.html">Audio I/O</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/audio_resampling_tutorial.html">Audio Resampling</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/audio_data_augmentation_tutorial.html">Audio Data Augmentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/audio_feature_extractions_tutorial.html">Audio Feature Extractions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/audio_feature_augmentation_tutorial.html">Audio Feature Augmentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/audio_datasets_tutorial.html">Audio Datasets</a></li>
<li class="toctree-l1"><a class="reference internal" href="speech_recognition_pipeline_tutorial.html">Speech Recognition with Wav2Vec2</a></li>
<li class="toctree-l1"><a class="reference internal" href="text_to_speech_with_torchaudio.html">Text-to-speech with Tacotron2</a></li>
<li class="toctree-l1"><a class="reference internal" href="forced_alignment_with_torchaudio_tutorial.html">wav2vec2์ ์ด์ฉํ ๊ฐ์ ์ ๋ ฌ</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">ํ
์คํธ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/bettertransformer_tutorial.html">Fast Transformer Inference with Better Transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="char_rnn_classification_tutorial.html">๊ธฐ์ด๋ถํฐ ์์ํ๋ NLP: ๋ฌธ์-๋จ์ RNN์ผ๋ก ์ด๋ฆ ๋ถ๋ฅํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="char_rnn_generation_tutorial.html">๊ธฐ์ด๋ถํฐ ์์ํ๋ NLP: ๋ฌธ์-๋จ์ RNN์ผ๋ก ์ด๋ฆ ์์ฑํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="seq2seq_translation_tutorial.html">๊ธฐ์ด๋ถํฐ ์์ํ๋ NLP: Sequence to Sequence ๋คํธ์ํฌ์ Attention์ ์ด์ฉํ ๋ฒ์ญ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/text_sentiment_ngrams_tutorial.html">torchtext ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ํ
์คํธ ๋ถ๋ฅํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/translation_transformer.html"><code class="docutils literal notranslate"><span class="pre">nn.Transformer</span></code> ์ torchtext๋ก ์ธ์ด ๋ฒ์ญํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/torchtext_custom_dataset_tutorial.html">Preprocess custom text dataset using Torchtext</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">๋ฐฑ์๋</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/onnx/intro_onnx.html">Introduction to ONNX</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">๊ฐํํ์ต</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="reinforcement_q_learning.html">๊ฐํ ํ์ต (DQN) ํํ ๋ฆฌ์ผ</a></li>
<li class="toctree-l1"><a class="reference internal" href="reinforcement_ppo.html">Reinforcement Learning (PPO) with TorchRL Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="mario_rl_tutorial.html">๋ง๋ฆฌ์ค ๊ฒ์ RL ์์ด์ ํธ๋ก ํ์ตํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/pendulum.html">Pendulum: Writing your environment and transforms with TorchRL</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">PyTorch ๋ชจ๋ธ์ ํ๋ก๋์
ํ๊ฒฝ์ ๋ฐฐํฌํ๊ธฐ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/onnx/intro_onnx.html">Introduction to ONNX</a></li>
<li class="toctree-l1"><a class="reference internal" href="flask_rest_api_tutorial.html">Flask๋ฅผ ์ฌ์ฉํ์ฌ Python์์ PyTorch๋ฅผ REST API๋ก ๋ฐฐํฌํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/Intro_to_TorchScript_tutorial.html">TorchScript ์๊ฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/cpp_export.html">C++์์ TorchScript ๋ชจ๋ธ ๋ก๋ฉํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/super_resolution_with_onnxruntime.html">(์ ํ) PyTorch ๋ชจ๋ธ์ ONNX์ผ๋ก ๋ณํํ๊ณ ONNX ๋ฐํ์์์ ์คํํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="realtime_rpi.html">Raspberry Pi 4 ์์ ์ค์๊ฐ ์ถ๋ก (Inference) (30fps!)</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">PyTorch ํ๋กํ์ผ๋ง</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/profiler.html">PyTorch ๋ชจ๋ ํ๋กํ์ผ๋งํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/hta_intro_tutorial.html">Introduction to Holistic Trace Analysis</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/hta_trace_diff_tutorial.html">Trace Diff using Holistic Trace Analysis</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Code Transforms with FX</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="fx_conv_bn_fuser.html">(๋ฒ ํ) FX์์ ํฉ์ฑ๊ณฑ/๋ฐฐ์น ์ ๊ทํ(Convolution/Batch Norm) ๊ฒฐํฉ๊ธฐ(Fuser) ๋ง๋ค๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="fx_profiling_tutorial.html">(beta) Building a Simple CPU Performance Profiler with FX</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">ํ๋ก ํธ์๋ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="memory_format_tutorial.html">(๋ฒ ํ) PyTorch๋ฅผ ์ฌ์ฉํ Channels Last ๋ฉ๋ชจ๋ฆฌ ํ์</a></li>
<li class="toctree-l1"><a class="reference internal" href="forward_ad_usage.html">Forward-mode Automatic Differentiation (Beta)</a></li>
<li class="toctree-l1"><a class="reference internal" href="jacobians_hessians.html">Jacobians, Hessians, hvp, vhp, and more: composing function transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="ensembling.html">๋ชจ๋ธ ์์๋ธ</a></li>
<li class="toctree-l1"><a class="reference internal" href="per_sample_grads.html">Per-sample-gradients</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/cpp_frontend.html">PyTorch C++ ํ๋ก ํธ์๋ ์ฌ์ฉํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/torch-script-parallelism.html">TorchScript์ ๋์ ๋ณ๋ ฌ ์ฒ๋ฆฌ(Dynamic Parallelism)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/cpp_autograd.html">C++ ํ๋ก ํธ์๋์ ์๋ ๋ฏธ๋ถ (autograd)</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">PyTorch ํ์ฅํ๊ธฐ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="custom_function_double_backward_tutorial.html">Double Backward with Custom Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="custom_function_conv_bn_tutorial.html">Fusing Convolution and Batch Norm using Custom Function</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/cpp_extension.html">Custom C++ and CUDA Extensions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/torch_script_custom_ops.html">Extending TorchScript with Custom C++ Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/torch_script_custom_classes.html">์ปค์คํ
C++ ํด๋์ค๋ก TorchScript ํ์ฅํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/dispatcher.html">Registering a Dispatched Operator in C++</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/extend_dispatcher.html">Extending dispatcher for a new backend in C++</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/privateuseone.html">Facilitating New Backend Integration by PrivateUse1</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">๋ชจ๋ธ ์ต์ ํ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/profiler.html">PyTorch ๋ชจ๋ ํ๋กํ์ผ๋งํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="tensorboard_profiler_tutorial.html">ํ
์๋ณด๋๋ฅผ ์ด์ฉํ ํ์ดํ ์น ํ๋กํ์ผ๋ฌ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/hyperparameter_tuning_tutorial.html">Ray Tune์ ์ฌ์ฉํ ํ์ดํผํ๋ผ๋ฏธํฐ ํ๋</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/vt_tutorial.html">๋ฐฐํฌ๋ฅผ ์ํด ๋น์ ํธ๋์คํฌ๋จธ(Vision Transformer) ๋ชจ๋ธ ์ต์ ํํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="parametrizations.html">Parametrizations Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="pruning_tutorial.html">๊ฐ์ง์น๊ธฐ ๊ธฐ๋ฒ(Pruning) ํํ ๋ฆฌ์ผ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/dynamic_quantization_tutorial.html">(๋ฒ ํ) LSTM ๊ธฐ๋ฐ ๋จ์ด ๋จ์ ์ธ์ด ๋ชจ๋ธ์ ๋์ ์์ํ</a></li>
<li class="toctree-l1"><a class="reference internal" href="dynamic_quantization_bert_tutorial.html">(๋ฒ ํ) BERT ๋ชจ๋ธ ๋์ ์์ํํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="quantized_transfer_learning_tutorial.html">(๋ฒ ํ) ์ปดํจํฐ ๋น์ ํํ ๋ฆฌ์ผ์ ์ํ ์์ํ๋ ์ ์ดํ์ต(Quantized Transfer Learning)</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/static_quantization_tutorial.html">(๋ฒ ํ) PyTorch์์ Eager Mode๋ฅผ ์ด์ฉํ ์ ์ ์์ํ</a></li>
<li class="toctree-l1"><a class="reference internal" href="torchserve_with_ipex.html">Grokking PyTorch Intel CPU performance from first principles</a></li>
<li class="toctree-l1"><a class="reference internal" href="torchserve_with_ipex_2.html">Grokking PyTorch Intel CPU performance from first principles (Part 2)</a></li>
<li class="toctree-l1"><a class="reference internal" href="nvfuser_intro_tutorial.html">Getting Started - Accelerate Your Scripts with nvFuser</a></li>
<li class="toctree-l1"><a class="reference internal" href="ax_multiobjective_nas_tutorial.html">Multi-Objective NAS with Ax</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_compile_tutorial.html">Introduction to <code class="docutils literal notranslate"><span class="pre">torch.compile</span></code></a></li>
<li class="toctree-l1"><a class="reference internal" href="inductor_debug_cpu.html">Inductor CPU backend debugging and profiling</a></li>
<li class="toctree-l1"><a class="reference internal" href="scaled_dot_product_attention_tutorial.html">(Beta) Scaled Dot Product Attention (SDPA)๋ก ๊ณ ์ฑ๋ฅ ํธ๋์คํฌ๋จธ(Transformers) ๊ตฌํํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="scaled_dot_product_attention_tutorial.html#torch-compile-sdpa"><code class="docutils literal notranslate"><span class="pre">torch.compile</span></code> ๊ณผ ํจ๊ป SDPA ์ฌ์ฉํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="scaled_dot_product_attention_tutorial.html#sdpa-atteition-bias">SDPA๋ฅผ <code class="docutils literal notranslate"><span class="pre">atteition.bias</span></code> ํ์ ํด๋์ค์ ์ฌ์ฉํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="scaled_dot_product_attention_tutorial.html#id8">๊ฒฐ๋ก </a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/knowledge_distillation_tutorial.html">Knowledge Distillation Tutorial</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">๋ณ๋ ฌ ๋ฐ ๋ถ์ฐ ํ์ต</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../distributed/home.html">Distributed and Parallel Training Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/dist_overview.html">PyTorch Distributed Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/ddp_series_intro.html">Distributed Data Parallel in PyTorch - Video Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="model_parallel_tutorial.html">๋จ์ผ ๋จธ์ ์ ์ฌ์ฉํ ๋ชจ๋ธ ๋ณ๋ ฌํ ๋ชจ๋ฒ ์ฌ๋ก</a></li>
<li class="toctree-l1"><a class="reference internal" href="ddp_tutorial.html">๋ถ์ฐ ๋ฐ์ดํฐ ๋ณ๋ ฌ ์ฒ๋ฆฌ ์์ํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="dist_tuto.html">PyTorch๋ก ๋ถ์ฐ ์ดํ๋ฆฌ์ผ์ด์
๊ฐ๋ฐํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="FSDP_tutorial.html">Getting Started with Fully Sharded Data Parallel(FSDP)</a></li>
<li class="toctree-l1"><a class="reference internal" href="FSDP_adavnced_tutorial.html">Advanced Model Training with Fully Sharded Data Parallel (FSDP)</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Large Scale Transformer model training with Tensor Parallel (TP)</a></li>
<li class="toctree-l1"><a class="reference internal" href="process_group_cpp_extension_tutorial.html">Cpp ํ์ฅ์ ์ฌ์ฉํ ํ๋ก์ธ์ค ๊ทธ๋ฃน ๋ฐฑ์๋ ์ฌ์ฉ์ ์ ์</a></li>
<li class="toctree-l1"><a class="reference internal" href="rpc_tutorial.html">Getting Started with Distributed RPC Framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="rpc_param_server_tutorial.html">Implementing a Parameter Server Using Distributed RPC Framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="dist_pipeline_parallel_tutorial.html">Distributed Pipeline Parallelism Using RPC</a></li>
<li class="toctree-l1"><a class="reference internal" href="rpc_async_execution.html">Implementing Batch RPC Processing Using Asynchronous Executions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/rpc_ddp_tutorial.html">๋ถ์ฐ ๋ฐ์ดํฐ ๋ณ๋ ฌ(DDP)๊ณผ ๋ถ์ฐ RPC ํ๋ ์์ํฌ ๊ฒฐํฉ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/ddp_pipeline.html">๋ถ์ฐ ๋ฐ์ดํฐ ๋ณ๋ ฌ ์ฒ๋ฆฌ์ ๋ณ๋ ฌ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํ ํธ๋์คํฌ๋จธ ๋ชจ๋ธ ํ์ต</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/generic_join.html">Distributed Training with Uneven Inputs Using the Join Context Manager</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Edge with ExecuTorch</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/executorch/stable/tutorials/export-to-executorch-tutorial.html">Exporting to ExecuTorch Tutorial</a></li>
<li class="toctree-l1"><a class="reference external" href=" https://pytorch.org/executorch/stable/running-a-model-cpp-tutorial.html">Running an ExecuTorch Model in C++ Tutorial</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/executorch/stable/tutorials/sdk-integration-tutorial.html">Using the ExecuTorch SDK to Profile a Model</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/executorch/stable/demo-apps-ios.html">Building an ExecuTorch iOS Demo App</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/executorch/stable/demo-apps-android.html">Building an ExecuTorch Android Demo App</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/executorch/stable/examples-end-to-end-to-lower-model-to-delegate.html">Lowering a Model as a Delegate</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">์ถ์ฒ ์์คํ
</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="torchrec_tutorial.html">TorchRec ์๊ฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../advanced/sharding.html">Exploring TorchRec sharding</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Multimodality</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/flava_finetuning_tutorial.html">TorchMultimodal ํํ ๋ฆฌ์ผ: FLAVA ๋ฏธ์ธ์กฐ์ </a></li>
</ul>
</div>
</div>
</nav>
<div class="pytorch-container">
<div class="pytorch-page-level-bar" id="pytorch-page-level-bar">
<div class="pytorch-breadcrumbs-wrapper">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="pytorch-breadcrumbs">
<li>
<a href="../index.html">
Tutorials
</a> >
</li>
<li>Large Scale Transformer model training with Tensor Parallel (TP)</li>
<li class="pytorch-breadcrumbs-aside">
<a href="../_sources/intermediate/TP_tutorial.rst.txt" rel="nofollow"><img src="../_static/images/view-page-source-icon.svg"></a>
</li>
</ul>
</div>
</div>
<div class="pytorch-shortcuts-wrapper" id="pytorch-shortcuts-wrapper">
Shortcuts
</div>
</div>
<section data-toggle="wy-nav-shift" id="pytorch-content-wrap" class="pytorch-content-wrap">
<div class="pytorch-content-left">
<div class="pytorch-call-to-action-links">
<div id="tutorial-type">intermediate/TP_tutorial</div>
<div id="google-colab-link">
<img class="call-to-action-img" src="../_static/images/pytorch-colab.svg"/>
<div class="call-to-action-desktop-view">Run in Google Colab</div>
<div class="call-to-action-mobile-view">Colab</div>
</div>
<div id="download-notebook-link">
<img class="call-to-action-notebook-img" src="../_static/images/pytorch-download.svg"/>
<div class="call-to-action-desktop-view">Download Notebook</div>
<div class="call-to-action-mobile-view">Notebook</div>
</div>
<div id="github-view-link">
<img class="call-to-action-img" src="../_static/images/pytorch-github.svg"/>
<div class="call-to-action-desktop-view">View on GitHub</div>
<div class="call-to-action-mobile-view">GitHub</div>
</div>
</div>
<div class="rst-content">
<div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
<article itemprop="articleBody" id="pytorch-article" class="pytorch-article">
<div class="section" id="large-scale-transformer-model-training-with-tensor-parallel-tp">
<h1>Large Scale Transformer model training with Tensor Parallel (TP)<a class="headerlink" href="#large-scale-transformer-model-training-with-tensor-parallel-tp" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h1>
<p><strong>Author</strong>: <a class="reference external" href="https://github.com/wanchaol">Wanchao Liang</a>, <a class="reference external" href="https://github.com/tianyu-l">Tianyu Liu</a></p>
<div class="admonition note">
<p class="admonition-title">์ฐธ๊ณ </p>
<p><a class="reference internal" href="../_images/pencil-16.png"><img alt="edit" src="../_images/pencil-16.png" style="width: 16px; height: 16px;" /></a> View and edit this tutorial in <a class="reference external" href="https://github.com/pytorch/tutorials/blob/main/intermediate_source/TP_tutorial.rst">github</a>.</p>
</div>
<p>This tutorial demonstrates how to train a large Transformer-like model across hundreds to thousands of GPUs using Tensor Parallel and Fully Sharded Data Parallel.</p>
<p>Prerequisites:</p>
<ul class="simple">
<li><p>PyTorch 2.3.0 or later installed with CUDA/Linux</p></li>
<li><p><a class="reference external" href="https://pytorch.org/docs/stable/distributed.tensor.parallel.html">Tensor Parallel APIs</a></p></li>
<li><p><a class="reference external" href="https://tutorials.pytorch.kr/recipes/distributed_device_mesh.html">Getting Started with DeviceMesh</a></p></li>
<li><p><a class="reference external" href="https://tutorials.pytorch.kr/intermediate/FSDP_tutorial.html">Getting Started with Fully Sharded Data Parallel</a></p></li>
</ul>
<div class="section" id="how-tensor-parallel-works">
<h2>How Tensor Parallel works?<a class="headerlink" href="#how-tensor-parallel-works" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h2>
<p>Tensor Parallel (TP) was originally proposed in the <a class="reference external" href="https://arxiv.org/abs/1909.08053">Megatron-LM</a> paper,
and it is an efficient model parallelism technique to train large scale Transformer models.
<a class="reference external" href="https://arxiv.org/abs/2205.05198">Sequence Parallel</a> (SP) we mention in this tutorial is a variant of Tensor
Parallel that shards on the sequence dimension for <code class="docutils literal notranslate"><span class="pre">nn.LayerNorm</span></code> or <code class="docutils literal notranslate"><span class="pre">RMSNorm</span></code> to further save activation memory
during training. As the model becomes larger, the activation memory becomes the bottleneck, so in Tensor
Parallel training it usually applies Sequence Parallel to <code class="docutils literal notranslate"><span class="pre">LayerNorm</span></code> or <code class="docutils literal notranslate"><span class="pre">RMSNorm</span></code> layers.</p>
<div class="figure align-center" id="id1">
<a class="reference internal image-reference" href="../_images/megatron_lm.png"><img alt="Megatron-LM TP" src="../_images/megatron_lm.png" style="width: 100%;" /></a>
<p class="caption"><span class="caption-text">Figure 1. represents the sharding in Tensor Parallel style on a Transformer modelโs MLP and Self-Attention layer, where the matrix multiplications in both attention/MLP happens through sharded computations (<a class="reference external" href="https://arxiv.org/abs/1909.08053">image source</a>)</span><a class="headerlink" href="#id1" title="์ด ์ด๋ฏธ์ง์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></p>
</div>
<p>At a high level, PyTorch Tensor Parallel works as follows:</p>
<p><strong>Sharding initialization</strong></p>
<ul class="simple">
<li><p>Determine which <code class="docutils literal notranslate"><span class="pre">ParallelStyle</span></code> to apply to each layer and shard the initialized module by calling <code class="docutils literal notranslate"><span class="pre">parallelize_module</span></code>.</p></li>
<li><p>The parallelized modules would have their model parameters be swapped to DTensors, and DTensor would be responsible to run the parallelized module using sharded computation.</p></li>
</ul>
<p><strong>Runtime foward/backward</strong></p>
<ul class="simple">
<li><p>Depending on the input/outputs DTensor layouts user specified for each <code class="docutils literal notranslate"><span class="pre">ParallelStyle</span></code>, it would run proper communication operation to transform the DTensor layouts for inputs/outputs (such as <code class="docutils literal notranslate"><span class="pre">allreduce</span></code>, <code class="docutils literal notranslate"><span class="pre">allgather</span></code> and <code class="docutils literal notranslate"><span class="pre">reduce_scatter</span></code>).</p></li>
<li><p>Run sharded computation for the parallelized layers to save compute/memory (for example, <code class="docutils literal notranslate"><span class="pre">nn.Linear</span></code>, <code class="docutils literal notranslate"><span class="pre">nn.Embedding</span></code>).</p></li>
</ul>
</div>
<div class="section" id="when-and-why-you-should-apply-tensor-parallel">
<h2>When and Why you should apply Tensor Parallel<a class="headerlink" href="#when-and-why-you-should-apply-tensor-parallel" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h2>
<p>The PyTorch Fully Sharded Data Parallel (FSDP) already has the capability to scale model training to a specific
number of GPUs. However, when it comes to further scale the model training in terms of model size and GPU quantity,
many additional challenges arise that may require combining Tensor Parallel with FSDP.:</p>
<ol class="arabic simple">
<li><p>As the world size (number of GPUs) is becoming excessively large (exceeding 128/256 GPUs), the FSDP collectives (such as <code class="docutils literal notranslate"><span class="pre">allgather</span></code>) are being dominated by ring latency.
By implementing TP/SP on top of FSDP, the FSDP world size could be reduced by 8 by applying FSDP to be inter-host only, consequently decreasing the latency costs by the same amount.</p></li>
<li><p>Hit data parallelism limit where you can not raise the global batch size to be above the number of GPUs due to both convergence and GPU memory limitations, Tensor/Sequence Parallel
is the only known way to โballparkโ the global batch size and continue scaling with more GPUs. This means both model size and number of GPUs could continue to scale.</p></li>
<li><p>For certain types of models, when local batch size becomes smaller, TP/SP can yield matrix multiplication shapes that are more optimized for floating point operations (FLOPS).</p></li>
</ol>
<p>So, when pre-training, how easy is it to hit those limits? As of now, pre-training a Large Language Model (LLM) with billions or trillions of tokens could take months, even when using thousands of GPUs.</p>
<ul class="simple">
<li><p>It will always hit limitation 1 when training LLM on a large scale. For example, Llama 2 70B trained with 2k GPUs for 35 days, multi-dimensional parallelisms are needed at 2k scale.</p></li>
<li><p>When the Transformer model becomes larger (such as Llama2 70B), it will also quickly hit the limitation 2. One could not use FSDP alone with even local <code class="docutils literal notranslate"><span class="pre">batch_size=1</span></code> due to memory
and convergence constraints. For example, Llama 2 global batch size is 1K, so data parallelism alone can not be used at 2K GPUs.</p></li>
</ul>
</div>
<div class="section" id="how-to-apply-tensor-parallel">
<h2>How to apply Tensor Parallel<a class="headerlink" href="#how-to-apply-tensor-parallel" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h2>
<p>PyTorch Tensor Parallel APIs offers a set of module level primitives (<code class="docutils literal notranslate"><span class="pre">ParallelStyle</span></code>) to configure the sharding for each individual layers of the model, including:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">ColwiseParallel</span></code> and <code class="docutils literal notranslate"><span class="pre">RowwiseParallel</span></code>: Shard the <code class="docutils literal notranslate"><span class="pre">nn.Linear</span></code> and <code class="docutils literal notranslate"><span class="pre">nn.Embedding</span></code> in the column or row fashion.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">SequenceParallel</span></code>: Perform sharded computations on <code class="docutils literal notranslate"><span class="pre">nn.LayerNorm</span></code>, <code class="docutils literal notranslate"><span class="pre">nn.Dropout</span></code>, <code class="docutils literal notranslate"><span class="pre">RMSNormPython</span></code>, etc.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PrepareModuleInput</span></code> and <code class="docutils literal notranslate"><span class="pre">PrepareModuleOutput</span></code>: Configure the module inputs/outputs sharding layouts with proper communication operations.</p></li>
</ul>
<p>To demonstrate how to use the PyTorch native Tensor Parallel APIs, let us look at a common Transformer model. In this tutorial, we use the most recent <a class="reference external" href="https://github.com/pytorch/examples/blob/main/distributed/tensor_parallelism/llama2_model.py">Llama2 model</a> as a reference Transformer model implementation, as it is also widely used in the community.</p>
<p>Since Tensor Parallel shard individual tensors over a set of devices, we would need to set up the distributed environment (such as NCCL communicators) first.
Tensor Parallelism is a Single-Program Multiple-Data (SPMD) sharding algorithm similar to PyTorch DDP/FSDP, and it under the hood leverages the PyTorch DTensor
to perform sharding. It also utilizes the DeviceMesh abstraction (which under the hood manages ProcessGroups) for device management and sharding.
To see how to utilize DeviceMesh to set up multi-dimensional parallelisms, please refer to <a class="reference external" href="https://tutorials.pytorch.kr/recipes/distributed_device_mesh.html">this tutorial</a>. Tensor Parallel usually works within each host, so let us first initialize a DeviceMesh that connects 8 GPUs within a host.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># run this via torchrun: torchrun --standalone --nproc_per_node=8 ./tp_tutorial.py</span>
<span class="kn">from</span> <span class="nn">torch.distributed.device_mesh</span> <span class="kn">import</span> <span class="n">init_device_mesh</span>
<span class="n">tp_mesh</span> <span class="o">=</span> <span class="n">init_device_mesh</span><span class="p">(</span><span class="s2">"cuda"</span><span class="p">,</span> <span class="p">(</span><span class="mi">8</span><span class="p">,))</span>
</pre></div>
</div>
<p>Now that we have initialized DeviceMesh, let us take a detailed look at the Llama 2 model architecture and see how we should perform the Tensor Parallel sharding.
Here we focus on the core <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code>, where the Transformer model stacks the identical <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code> s to scale up the model.</p>
<p>The core <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code> consists of an <code class="docutils literal notranslate"><span class="pre">Attention</span></code> layer and a <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> layer. Let us first look at the simpler <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> layer.
For the <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> Layer it consists of three Linear layers, where it performs a SwiGLU style MLP, looking at its forward function:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># forward in the FeedForward layer</span>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">w2</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">silu</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">w1</span><span class="p">(</span><span class="n">x</span><span class="p">))</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">w3</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
</pre></div>
</div>
<p>It performs <code class="docutils literal notranslate"><span class="pre">w1</span></code> and <code class="docutils literal notranslate"><span class="pre">w3</span></code> matmuls concurrently and followed by a <code class="docutils literal notranslate"><span class="pre">w2</span></code> matmul with the result of the combined w1/w3 linear projection results. This means we could
use the idea from the Tensor Parallelism paper to shard the w1/w3 Linear layers in the colwise fashion and shard the <code class="docutils literal notranslate"><span class="pre">w2</span></code> Linear layer in the rowwise fashion, so that
there is only one <code class="docutils literal notranslate"><span class="pre">allreduce</span></code> communication happening at the end of all the three layers. With the PyTorch native Tensor Parallel, we can simply create a <code class="docutils literal notranslate"><span class="pre">parallelize_plan</span></code> for the <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> layer like below:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">torch.distributed.tensor.parallel</span> <span class="kn">import</span> <span class="n">ColwiseParallel</span><span class="p">,</span> <span class="n">RowwiseParallel</span><span class="p">,</span> <span class="n">parallelize_module</span>
<span class="n">layer_tp_plan</span> <span class="o">=</span> <span class="p">{</span>
<span class="c1"># by default ColwiseParallel input layouts is replicated</span>
<span class="c1"># and RowwiseParallel output layouts is replicated</span>
<span class="s2">"feed_foward.w1"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"feed_forward.w2"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(),</span>
<span class="s2">"feed_forward.w3"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Thatโs simply how we configure the shardings for the <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> layer using the PyTorch Tensor Parallel APIs. Note that users would only need to specify how to shard the individual layers and the communications (for example, <code class="docutils literal notranslate"><span class="pre">allreduce</span></code>) will happen under the hood.</p>
<p>Moving on to the <code class="docutils literal notranslate"><span class="pre">Attention</span></code> Layer. It consists of <code class="docutils literal notranslate"><span class="pre">wq</span></code>, <code class="docutils literal notranslate"><span class="pre">wk</span></code>, <code class="docutils literal notranslate"><span class="pre">wv</span></code> Linear layers to project input to <code class="docutils literal notranslate"><span class="pre">q</span></code>/ <code class="docutils literal notranslate"><span class="pre">k</span></code> / <code class="docutils literal notranslate"><span class="pre">v</span></code>, and then it performs attention and output projection with the <code class="docutils literal notranslate"><span class="pre">wo</span></code> Linear layer. Tensor Parallelism here intends to perform column-wise sharding for the
q/k/v projection and row-wise sharding for the <code class="docutils literal notranslate"><span class="pre">wo</span></code> linear projection. So we can add the Attention plan to the <code class="docutils literal notranslate"><span class="pre">tp_plan</span></code> that we just drafted up:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">layer_tp_plan</span> <span class="o">=</span> <span class="p">{</span>
<span class="c1"># by default ColwiseParallel input layouts is replicated</span>
<span class="c1"># and RowwiseParallel output layouts is replicated</span>
<span class="s2">"attention.wq"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"attention.wk"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"attention.wv"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"attention.wo"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(),</span>
<span class="s2">"feed_forward.w1"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"feed_forward.w2"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(),</span>
<span class="s2">"feed_forward.w3"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="p">}</span>
</pre></div>
</div>
<p>This is almost the <code class="docutils literal notranslate"><span class="pre">layer_tp_plan</span></code> we need to apply Tensor Parallelism to the <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code>. However, one thing we should be aware is that when sharding the linear layer column-wise, the output of the linear layers would become sharded on the last tensor dimension, and the row-wise sharding linear layer directly accepts an input that shards on the last dimension.
If there are any more tensor operations (such as view operations) between the column-wise linear and the row-wise linear, we would need to adjust the relevant shape related ops to sharded shape.</p>
<p>For the Llama model, in the attention layer there are couple of view operations that are shape related. In particular, column-wise parallel for <code class="docutils literal notranslate"><span class="pre">wq</span></code>/ <code class="docutils literal notranslate"><span class="pre">wk</span></code>/ <code class="docutils literal notranslate"><span class="pre">wv</span></code> linear layers, the activation tensor is sharded on the <code class="docutils literal notranslate"><span class="pre">num_heads</span></code> dimension, so we would need to adjust the <code class="docutils literal notranslate"><span class="pre">num_heads</span></code> to local <code class="docutils literal notranslate"><span class="pre">num_heads</span></code>.</p>
<p>Finally, we need to call <code class="docutils literal notranslate"><span class="pre">parallelize_module</span></code> API to make the plan for each <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code> effective. Under the hood, it distributes the model parameters inside <code class="docutils literal notranslate"><span class="pre">Attention</span></code> and <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> layers to DTensors, and registers communication hooks for model inputs and outputs (before and after each module respectively), if necessary:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">layer_id</span><span class="p">,</span> <span class="n">transformer_block</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">layers</span><span class="p">):</span>
<span class="n">layer_tp_plan</span> <span class="o">=</span> <span class="p">{</span><span class="o">...</span><span class="p">}</span> <span class="c1"># i.e. the plan we just generated</span>
<span class="c1"># Adjust attention module to use the local number of heads</span>
<span class="n">attn_layer</span> <span class="o">=</span> <span class="n">transformer_block</span><span class="o">.</span><span class="n">attention</span>
<span class="n">attn_layer</span><span class="o">.</span><span class="n">n_heads</span> <span class="o">=</span> <span class="n">attn_layer</span><span class="o">.</span><span class="n">n_heads</span> <span class="o">//</span> <span class="n">tp_mesh</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>
<span class="n">attn_layer</span><span class="o">.</span><span class="n">n_kv_heads</span> <span class="o">=</span> <span class="n">attn_layer</span><span class="o">.</span><span class="n">n_kv_heads</span> <span class="o">//</span> <span class="n">tp_mesh</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>
<span class="n">parallelize_module</span><span class="p">(</span>
<span class="n">module</span><span class="o">=</span><span class="n">transformer_block</span><span class="p">,</span>
<span class="n">device_mesh</span><span class="o">=</span><span class="n">tp_mesh</span><span class="p">,</span>
<span class="n">parallelize_plan</span><span class="o">=</span><span class="n">layer_tp_plan</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Now that we have elaborated the sharding plan for each <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code>, there is usually a <code class="docutils literal notranslate"><span class="pre">nn.Embedding</span></code> in the first layer and a final <code class="docutils literal notranslate"><span class="pre">nn.Linear</span></code> projection layer, where user could choose row-wise or column-wise sharding to the first <code class="docutils literal notranslate"><span class="pre">nn.Embedding</span></code> and column-wise sharding to the last <code class="docutils literal notranslate"><span class="pre">nn.Linear</span></code> projection layer with proper input and output layouts specified.
Here is an example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">model</span> <span class="o">=</span> <span class="n">parallelize_module</span><span class="p">(</span>
<span class="n">model</span><span class="p">,</span>
<span class="n">tp_mesh</span><span class="p">,</span>
<span class="p">{</span>
<span class="s2">"tok_embeddings"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(</span>
<span class="n">input_layouts</span><span class="o">=</span><span class="n">Replicate</span><span class="p">(),</span>
<span class="p">),</span>
<span class="s2">"output"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(</span>
<span class="n">output_layouts</span><span class="o">=</span><span class="n">Replicate</span><span class="p">(),</span>
<span class="p">),</span>
<span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">์ฐธ๊ณ </p>
<p>If the model to be partitioned is too large to fit into CPU memory, one could either use <code class="docutils literal notranslate"><span class="pre">meta</span></code> device initialization (for example, initialize the model on meta device first, shard the layers, and the materialize the model), or parallelize the <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code> layer by layer during the Transformer model initialization.</p>
</div>
</div>
<div class="section" id="apply-sequence-parallel-to-layernorm-rmsnorm-layers">
<h2>Apply Sequence Parallel to <code class="docutils literal notranslate"><span class="pre">LayerNorm/RMSNorm</span></code> layers<a class="headerlink" href="#apply-sequence-parallel-to-layernorm-rmsnorm-layers" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h2>
<p>Sequence Parallel works on top of the Tensor Parallel illustrated above. Compared with basic Tensor Parallel, which only shards tensors within the <code class="docutils literal notranslate"><span class="pre">Attention</span></code> modules and <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> modules and keep their module inputs and outputs (namely activations in the forward pass and gradients in the backward pass) replicated, Sequence Parallel keeps them sharded on the sequence dimension.</p>
<p>In a typical <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code>, the forward function combines norm layers (<code class="docutils literal notranslate"><span class="pre">LayerNorm</span></code> or <code class="docutils literal notranslate"><span class="pre">RMSNorm</span></code>), an attention layer, a feed forward layer, and residual connections. For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># forward in a TransformerBlock</span>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">attention</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">attention_norm</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="n">out</span> <span class="o">=</span> <span class="n">h</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">feed_forward</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ffn_norm</span><span class="p">(</span><span class="n">h</span><span class="p">))</span>
<span class="k">return</span> <span class="n">out</span>
</pre></div>
</div>
<p>In most use cases, the activations (and gradients) are of the shape <code class="docutils literal notranslate"><span class="pre">[batch</span> <span class="pre">size,</span> <span class="pre">sequence</span> <span class="pre">length,</span> <span class="pre">hidden</span> <span class="pre">dimension]</span></code> outside the <code class="docutils literal notranslate"><span class="pre">Attention</span></code> and <code class="docutils literal notranslate"><span class="pre">FeedForward</span></code> modules. In the DTensorโs language, Sequence Parallel performs activation computation using the <code class="docutils literal notranslate"><span class="pre">Shard(1)</span></code> layout for both forward/backward of the module.
Following the code example earlier, the code below demonstrates how we apply Sequence Parallel to the norm layers within a <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code>:</p>
<p>First letโs import the required dependencies for Sequence Parallel:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">torch.distributed.tensor.parallel</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">PrepareModuleInput</span><span class="p">,</span>
<span class="n">SequenceParallel</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Next letโs adjust the <code class="docutils literal notranslate"><span class="pre">layer_tp_plan</span></code> to enable sequence parallel on the <code class="docutils literal notranslate"><span class="pre">RMSNorm</span></code> layers:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">layer_tp_plan</span> <span class="o">=</span> <span class="p">{</span>
<span class="c1"># Now the input and output of SequenceParallel has Shard(1) layouts,</span>
<span class="c1"># to represent the input/output tensors sharded on the sequence dimension</span>
<span class="s2">"attention_norm"</span><span class="p">:</span> <span class="n">SequenceParallel</span><span class="p">(),</span>
<span class="s2">"attention"</span><span class="p">:</span> <span class="n">PrepareModuleInput</span><span class="p">(</span>
<span class="n">input_layouts</span><span class="o">=</span><span class="p">(</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">),),</span>
<span class="n">desired_input_layouts</span><span class="o">=</span><span class="p">(</span><span class="n">Replicate</span><span class="p">(),),</span>
<span class="p">),</span>
<span class="s2">"attention.wq"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"attention.wk"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"attention.wv"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"attention.wo"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(</span><span class="n">output_layouts</span><span class="o">=</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
<span class="s2">"ffn_norm"</span><span class="p">:</span> <span class="n">SequenceParallel</span><span class="p">(),</span>
<span class="s2">"feed_forward"</span><span class="p">:</span> <span class="n">PrepareModuleInput</span><span class="p">(</span>
<span class="n">input_layouts</span><span class="o">=</span><span class="p">(</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">),),</span>
<span class="n">desired_input_layouts</span><span class="o">=</span><span class="p">(</span><span class="n">Replicate</span><span class="p">(),),</span>
<span class="p">),</span>
<span class="s2">"feed_forward.w1"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="s2">"feed_forward.w2"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(</span><span class="n">output_layouts</span><span class="o">=</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">)),</span>
<span class="s2">"feed_forward.w3"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(),</span>
<span class="p">}</span>
</pre></div>
</div>
<p>One can see we now use <code class="docutils literal notranslate"><span class="pre">PrepareModuleInput</span></code> to modify the module input layouts to the Attention and FeedForward layers from <code class="docutils literal notranslate"><span class="pre">Shard(1)</span></code> to <code class="docutils literal notranslate"><span class="pre">Replicate()</span></code>, and mark their output layouts as <code class="docutils literal notranslate"><span class="pre">Shard(1)</span></code>.
Just like what happens to Tensor Parallelism, one only needs to specify the tensor sharding layouts of the inputs and outputs, and the communication between layers will happen automatically.</p>
<p>Note that with Sequence Parallel, we assume the inputs and outputs of a <code class="docutils literal notranslate"><span class="pre">TransformerBlock</span></code> are always sharded on the sequence dimension, so that multiple <code class="docutils literal notranslate"><span class="pre">TransformerBlocks</span></code> can be concatenated seamlessly.
This can be facilitated by explicitly specifying the output of the beginning <code class="docutils literal notranslate"><span class="pre">nn.Embedding</span></code> layer and the input of the final <code class="docutils literal notranslate"><span class="pre">nn.Linear</span></code> projection layer to be <code class="docutils literal notranslate"><span class="pre">Shard(1)</span></code>:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">model</span> <span class="o">=</span> <span class="n">parallelize_module</span><span class="p">(</span>
<span class="n">model</span><span class="p">,</span>
<span class="n">tp_mesh</span><span class="p">,</span>
<span class="p">{</span>
<span class="s2">"tok_embeddings"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(</span>
<span class="n">input_layouts</span><span class="o">=</span><span class="n">Replicate</span><span class="p">(),</span>
<span class="n">output_layouts</span><span class="o">=</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span>
<span class="p">),</span>
<span class="s2">"norm"</span><span class="p">:</span> <span class="n">SequenceParallel</span><span class="p">(),</span>
<span class="s2">"output"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(</span>
<span class="n">input_layouts</span><span class="o">=</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span>
<span class="n">output_layouts</span><span class="o">=</span><span class="n">Replicate</span><span class="p">()</span>
<span class="p">),</span>
<span class="p">}</span>
<span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="apply-loss-parallel">
<h2>Apply Loss Parallel<a class="headerlink" href="#apply-loss-parallel" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h2>
<p>Loss Parallel is a related technique to save memory and communication when the loss function is computed, as model outputs are usually very large. In Loss Parallel, when the model outputs are sharded on the (often huge) vocabulary dimension, the cross-entropy loss can be computed efficiently, without gathering all the model outputs to every single GPU. This not only significantly reduces the memory consumption, but also improves training speed by reducing communication overhead and doing sharded computation in parallel. The picture below briefly illustrates how Loss Parallel avoids gathering all model outputs to every GPU by doing sharded computation.</p>
<div class="figure align-center" id="id2">
<a class="reference internal image-reference" href="../_images/loss_parallel.png"><img alt="loss parallel" src="../_images/loss_parallel.png" style="width: 100%;" /></a>
<p class="caption"><span class="caption-text">Figure 2. Cross-entropy loss forward computation with loss parallel on one GPU. Blue represents sharded tensors; green represents replicated tensors; yellow represents tensors with partial values (to be all-reduced). Black arrows are local computations; red arrows are functional collectives among GPUs.</span><a class="headerlink" href="#id2" title="์ด ์ด๋ฏธ์ง์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></p>
</div>
<p>In the PyTorch Tensor Parallel API, Loss Parallel can be enabled via a context manager <code class="docutils literal notranslate"><span class="pre">loss_parallel</span></code>, with which one can directly use <code class="docutils literal notranslate"><span class="pre">torch.nn.functional.cross_entropy</span></code> or <code class="docutils literal notranslate"><span class="pre">torch.nn.CrossEntropyLoss</span></code> without modifying other parts of their code.</p>
<p>To apply Loss Parallel, the model predictions, usually of the shape <code class="docutils literal notranslate"><span class="pre">[batch</span> <span class="pre">size,</span> <span class="pre">sequence</span> <span class="pre">length,</span> <span class="pre">vocabulary</span> <span class="pre">size]</span></code>, should be sharded on the vocabulary dimension. This can be easily done via marking the output layouts of the last linear projection layer output:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">model</span> <span class="o">=</span> <span class="n">parallelize_module</span><span class="p">(</span>
<span class="n">model</span><span class="p">,</span>
<span class="n">tp_mesh</span><span class="p">,</span>
<span class="p">{</span>
<span class="s2">"tok_embeddings"</span><span class="p">:</span> <span class="n">RowwiseParallel</span><span class="p">(</span>
<span class="n">input_layouts</span><span class="o">=</span><span class="n">Replicate</span><span class="p">(),</span>
<span class="n">output_layouts</span><span class="o">=</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span>
<span class="p">),</span>
<span class="s2">"norm"</span><span class="p">:</span> <span class="n">SequenceParallel</span><span class="p">(),</span>
<span class="s2">"output"</span><span class="p">:</span> <span class="n">ColwiseParallel</span><span class="p">(</span>
<span class="n">input_layouts</span><span class="o">=</span><span class="n">Shard</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span>
<span class="c1"># use DTensor as the output</span>
<span class="n">use_local_output</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="p">),</span>
<span class="p">},</span>
<span class="p">)</span>
</pre></div>
</div>
<p>In the code above, we also apply Sequence Parallel to the norm layer before output. We apply <code class="docutils literal notranslate"><span class="pre">use_local_output=False</span></code> to let the output stay as a DTensor, to work with the <code class="docutils literal notranslate"><span class="pre">loss_parallel</span></code> context manager. After that, one can simply call the cross_entropy loss function as is shown below. Note that the backward computation also needs to happen within the context.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">torch.nn.functional</span> <span class="k">as</span> <span class="nn">F</span>
<span class="kn">from</span> <span class="nn">torch.distributed.tensor.parallel</span> <span class="kn">import</span> <span class="n">loss_parallel</span>
<span class="n">pred</span> <span class="o">=</span> <span class="n">model</span><span class="p">(</span><span class="n">input_ids</span><span class="p">)</span>
<span class="k">with</span> <span class="n">loss_parallel</span><span class="p">():</span>
<span class="c1"># assuming pred and labels are of the shape [batch, seq, vocab]</span>
<span class="n">loss</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">cross_entropy</span><span class="p">(</span><span class="n">pred</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">labels</span><span class="o">.</span><span class="n">flatten</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="n">loss</span><span class="o">.</span><span class="n">backward</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="combine-tensor-parallel-with-fully-sharded-data-parallel-together">
<h2>Combine Tensor Parallel with Fully Sharded Data Parallel together<a class="headerlink" href="#combine-tensor-parallel-with-fully-sharded-data-parallel-together" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h2>
<p>Now that we have shown how to apply Tensor/Sequence Parallel to the model, let us also take a look at how Tensor Parallel and Fully Sharded Data Parallel could work together.
Since Tensor Parallelism incurs communications that block the computation, we want to make sure it runs within a fast communication channel, such as NVLink.
In practice, we usually apply Tensor Parallel within each host, and apply Fully Sharded Data Parallel across the hosts.</p>
<div class="figure align-center" id="id3">
<a class="reference internal image-reference" href="../_images/fsdp_tp.png"><img alt="fsdp + tp" src="../_images/fsdp_tp.png" style="width: 100%;" /></a>
<p class="caption"><span class="caption-text">Figure 3. FSDP and TP work on separate device dimensions, FSDP communication happens inter-host and TP communication happens intra-host.</span><a class="headerlink" href="#id3" title="์ด ์ด๋ฏธ์ง์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></p>
</div>
<p>This 2-D parallelism pattern can be easily expressed via a 2-D DeviceMesh, and we just need pass each โsubโ DeviceMesh to each individual parallelism APIs:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">torch.distributed.device_mesh</span> <span class="kn">import</span> <span class="n">init_device_mesh</span>
<span class="kn">from</span> <span class="nn">torch.distributed.tensor.parallel</span> <span class="kn">import</span> <span class="n">ColwiseParallel</span><span class="p">,</span> <span class="n">RowwiseParallel</span><span class="p">,</span> <span class="n">parallelize_module</span>
<span class="kn">from</span> <span class="nn">torch.distributed.fsdp</span> <span class="kn">import</span> <span class="n">FullyShardedDataParallel</span> <span class="k">as</span> <span class="n">FSDP</span>
<span class="c1"># i.e. 2-D mesh is [dp, tp], training on 64 GPUs that performs 8 way DP and 8 way TP</span>
<span class="n">mesh_2d</span> <span class="o">=</span> <span class="n">init_device_mesh</span><span class="p">(</span><span class="s2">"cuda"</span><span class="p">,</span> <span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span>
<span class="n">tp_mesh</span> <span class="o">=</span> <span class="n">mesh_2d</span><span class="p">[</span><span class="s2">"tp"</span><span class="p">]</span> <span class="c1"># a submesh that connects intra-host devices</span>
<span class="n">dp_mesh</span> <span class="o">=</span> <span class="n">mesh_2d</span><span class="p">[</span><span class="s2">"dp"</span><span class="p">]</span> <span class="c1"># a submesh that connects inter-host devices</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">Model</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="n">tp_plan</span> <span class="o">=</span> <span class="p">{</span><span class="o">...</span><span class="p">}</span>
<span class="c1"># apply Tensor Parallel intra-host on tp_mesh</span>
<span class="n">model_tp</span> <span class="o">=</span> <span class="n">parallelize_module</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">tp_mesh</span><span class="p">,</span> <span class="n">tp_plan</span><span class="p">)</span>
<span class="c1"># apply FSDP inter-host on dp_mesh</span>
<span class="n">model_2d</span> <span class="o">=</span> <span class="n">FSDP</span><span class="p">(</span><span class="n">model_tp</span><span class="p">,</span> <span class="n">device_mesh</span><span class="o">=</span><span class="n">dp_mesh</span><span class="p">,</span> <span class="n">use_orig_params</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span>
</pre></div>
</div>
<p>This would allow us to easily apply Tensor Parallel within each host (intra-host) and apply FSDP across hosts (inter-hosts), with <strong>0-code changes</strong> to the Llama model.
The Tensor(Model) Parallel and Data Parallel techniques combined together provides the ability to continue increasing model size and training efficiently using a large number of GPUs.</p>
</div>
<div class="section" id="conclusion">
<h2>Conclusion<a class="headerlink" href="#conclusion" title="์ด ์ ๋ชฉ์ ๋ํ ํผ๋จธ๋งํฌ">ยถ</a></h2>
<p>This tutorial demonstrates how to train a large Transformer-like model across hundreds to thousands of GPUs using Tensor Parallel in combination with Fully Sharded Data Parallel.
It explains how to apply Tensor Parallel to different parts of the model, with <strong>no code changes</strong> to the model itself. Tensor Parallel is a efficient model parallelism technique for large scale training.</p>
<p>To see the complete end to end code example explained in this tutorial, please refer to the <a class="reference external" href="https://github.com/pytorch/examples/blob/main/distributed/tensor_parallelism/fsdp_tp_example.py">Tensor Parallel examples</a> in the pytorch/examples repository.</p>
</div>
</div>
</article>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="process_group_cpp_extension_tutorial.html" class="btn btn-neutral float-right" title="Cpp ํ์ฅ์ ์ฌ์ฉํ ํ๋ก์ธ์ค ๊ทธ๋ฃน ๋ฐฑ์๋ ์ฌ์ฉ์ ์ ์" accesskey="n" rel="next">Next <img src="../_static/images/chevron-right-orange.svg" class="next-page"></a>
<a href="FSDP_adavnced_tutorial.html" class="btn btn-neutral" title="Advanced Model Training with Fully Sharded Data Parallel (FSDP)" accesskey="p" rel="prev"><img src="../_static/images/chevron-right-orange.svg" class="previous-page"> Previous</a>
</div>
<hr class="community-hr hr-top" />
<div class="community-container">
<div class="community-prompt">๋ ๊ถ๊ธํ์๊ฑฐ๋ ๊ฐ์ ํ ๋ด์ฉ์ด ์์ผ์ ๊ฐ์? ์ปค๋ฎค๋ํฐ์ ์ฐธ์ฌํด๋ณด์ธ์!</div>
<div class="community-link"><a href="https://discuss.pytorch.kr/" aria-label="PyTorchKoreaCommunity">ํ๊ตญ์ด ์ปค๋ฎค๋ํฐ ๋ฐ๋ก๊ฐ๊ธฐ</a></div>
</div>
<hr class="community-hr hr-bottom"/>
<hr class="rating-hr hr-top" />
<div class="rating-container">
<div class="rating-prompt">์ด ํํ ๋ฆฌ์ผ์ด ์ด๋ ์
จ๋์? ํ๊ฐํด์ฃผ์๋ฉด ์ดํ ๊ฐ์ ์ ์ฐธ๊ณ ํ๊ฒ ์ต๋๋ค! :)</div>
<div class="stars-outer">
<i class="far fa-star" title="1 Star" data-behavior="tutorial-rating" data-count="1"></i>
<i class="far fa-star" title="2 Stars" data-behavior="tutorial-rating" data-count="2"></i>
<i class="far fa-star" title="3 Stars" data-behavior="tutorial-rating" data-count="3"></i>
<i class="far fa-star" title="4 Stars" data-behavior="tutorial-rating" data-count="4"></i>
<i class="far fa-star" title="5 Stars" data-behavior="tutorial-rating" data-count="5"></i>
</div>
</div>
<hr class="rating-hr hr-bottom"/>
<div role="contentinfo">
<p>
© Copyright 2018-2024, PyTorch & ํ์ดํ ์น ํ๊ตญ ์ฌ์ฉ์ ๋ชจ์(PyTorch Korea User Group).
</p>
</div>
<div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</div>
</footer>
</div>
<script>
if((window.location.href.indexOf("/prototype/")!= -1) && (window.location.href.indexOf("/prototype/prototype_index")< 1))
{
var div = '<div class="admonition note"><p class="admonition-title">Note</p><p><i class="fa fa-flask" aria-hidden="true"> </i> ์ด ํํ ๋ฆฌ์ผ์ ํ๋กํ ํ์
(prototype) ๊ธฐ๋ฅ๋ค์ ๋ํด์ ์ค๋ช
ํ๊ณ ์์ต๋๋ค. ํ๋กํ ํ์
๊ธฐ๋ฅ์ ์ผ๋ฐ์ ์ผ๋ก ํผ๋๋ฐฑ ๋ฐ ํ
์คํธ์ฉ์ผ๋ก, ๋ฐํ์ ํ๋๊ทธ ์์ด๋ PyPI๋ Conda๋ก ๋ฐฐํฌ๋๋ ๋ฐ์ด๋๋ฆฌ์์๋ ์ฌ์ฉํ ์ ์์ต๋๋ค.</p></div>'
document.getElementById("pytorch-article").insertAdjacentHTML('afterBegin', div)
}
</script>
</div>
<div class="pytorch-content-right" id="pytorch-content-right">
<div class="pytorch-right-menu" id="pytorch-right-menu">
<div class="pytorch-side-scroll" id="pytorch-side-scroll-right">
<ul>
<li><a class="reference internal" href="#">Large Scale Transformer model training with Tensor Parallel (TP)</a><ul>
<li><a class="reference internal" href="#how-tensor-parallel-works">How Tensor Parallel works?</a></li>
<li><a class="reference internal" href="#when-and-why-you-should-apply-tensor-parallel">When and Why you should apply Tensor Parallel</a></li>
<li><a class="reference internal" href="#how-to-apply-tensor-parallel">How to apply Tensor Parallel</a></li>
<li><a class="reference internal" href="#apply-sequence-parallel-to-layernorm-rmsnorm-layers">Apply Sequence Parallel to <code class="docutils literal notranslate"><span class="pre">LayerNorm/RMSNorm</span></code> layers</a></li>
<li><a class="reference internal" href="#apply-loss-parallel">Apply Loss Parallel</a></li>
<li><a class="reference internal" href="#combine-tensor-parallel-with-fully-sharded-data-parallel-together">Combine Tensor Parallel with Fully Sharded Data Parallel together</a></li>
<li><a class="reference internal" href="#conclusion">Conclusion</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</section>
</div>
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/clipboard.min.js"></script>
<script src="../_static/copybutton.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/katex.min.js"></script>
<script src="../_static/auto-render.min.js"></script>
<script src="../_static/katex_autorenderer.js"></script>
<script src="../_static/design-tabs.js"></script>
<script type="text/javascript" src="../_static/js/vendor/popper.min.js"></script>
<script type="text/javascript" src="../_static/js/vendor/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
<script>
// Helper function to make it easier to call dataLayer.push()
function gtag(){window.dataLayer.push(arguments);}
//add microsoft link
if(window.location.href.indexOf("/beginner/basics/")!= -1)
{
var url="https://docs.microsoft.com/learn/paths/pytorch-fundamentals/?wt.mc_id=aiml-7486-cxa";
switch(window.location.pathname.split("/").pop().replace('.html',''))
{
case"quickstart_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/9-quickstart?WT.mc_id=aiml-7486-cxa";
break;
case"tensorqs_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/2-tensors?WT.mc_id=aiml-7486-cxa";
break;
case"data_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/3-data?WT.mc_id=aiml-7486-cxa";
break;
case"transforms_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/4-transforms?WT.mc_id=aiml-7486-cxa";
break;
case"buildmodel_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/5-model?WT.mc_id=aiml-7486-cxa";
break;
case"autogradqs_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/6-autograd?WT.mc_id=aiml-7486-cxa";
break;
case"optimization_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/7-optimization?WT.mc_id=aiml-7486-cxa";
break;
case"saveloadrun_tutorial":
url="https://docs.microsoft.com/learn/modules/intro-machine-learning-pytorch/8-inference?WT.mc_id=aiml-7486-cxa";
}
$(".pytorch-call-to-action-links").children().first().before("<a href="+url+' data-behavior="call-to-action-event" data-response="Run in Microsoft Learn" target="_blank"><div id="microsoft-learn-link" style="padding-bottom: 0.625rem;border-bottom: 1px solid #f3f4f7;padding-right: 2.5rem;display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-align: center;-ms-flex-align: center;align-items: center;"><img class="call-to-action-img" src="../../_static/images/microsoft-logo.svg"/><div class="call-to-action-desktop-view">Run in Microsoft Learn</div><div class="call-to-action-mobile-view">Learn</div></div></a>')
}
</script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LZRD6GXDLF"></script>
<script data-cfasync="false">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-LZRD6GXDLF'); // GA4
gtag('config', 'UA-71919972-3'); // UA
</script>
<script data-cfasync="false">
$("[data-behavior='call-to-action-event']").on('click', function(){
ga('send', {
hitType: 'event',
eventCategory: $(this).attr("data-response"),
eventAction: 'click',
eventLabel: window.location.href
});
gtag('event', 'click', {
'event_category': $(this).attr("data-response"),
'event_label': $("h1").first().text(),
'tutorial_link': window.location.href
});
});
$("[data-behavior='tutorial-rating']").on('click', function(){
gtag('event', 'click', {
'event_category': 'Tutorial Rating',
'event_label': $("h1").first().text(),
'value': $(this).attr("data-count"),
'customEvent:Rating': $(this).attr("data-count") // send to GA custom dimension customEvent:Rating.
});
});
if (location.pathname == "/") {
$(".rating-container").hide();
$(".hr-bottom").hide();
}
</script>
<script type="text/javascript">
var collapsedSections = ['ํ์ดํ ์น(PyTorch) ๋ ์ํผ', 'ํ์ดํ ์น(PyTorch) ๋ฐฐ์ฐ๊ธฐ', 'Introduction to PyTorch on YouTube', '์ด๋ฏธ์ง/๋น๋์ค', '์ค๋์ค', 'ํ
์คํธ', '๋ฐฑ์๋', '๊ฐํํ์ต', 'PyTorch ๋ชจ๋ธ์ ํ๋ก๋์
ํ๊ฒฝ์ ๋ฐฐํฌํ๊ธฐ', 'PyTorch ํ๋กํ์ผ๋ง', 'Code Transforms with FX', 'ํ๋ก ํธ์๋ API', 'PyTorch ํ์ฅํ๊ธฐ', '๋ชจ๋ธ ์ต์ ํ', '๋ณ๋ ฌ ๋ฐ ๋ถ์ฐ ํ์ต', 'Edge with ExecuTorch', '์ถ์ฒ ์์คํ
', 'Multimodality'];
</script>
<!-- Begin Footer -->
<div class="container-fluid docs-tutorials-resources" id="docs-tutorials-resources">
<div class="container">
<div class="row">
<div class="col-md-4 text-center">
<h2>PyTorchKorea @ GitHub</h2>
<p>ํ์ดํ ์น ํ๊ตญ ์ฌ์ฉ์ ๋ชจ์์ GitHub์์ ๋ง๋๋ณด์ธ์.</p>
<a class="with-right-arrow" href="https://github.com/PyTorchKorea" target="_blank">GitHub๋ก ์ด๋</a>
</div>
<div class="col-md-4 text-center">
<h2>ํ๊ตญ์ด ํํ ๋ฆฌ์ผ</h2>
<p>ํ๊ตญ์ด๋ก ๋ฒ์ญ ์ค์ธ PyTorch ํํ ๋ฆฌ์ผ์
๋๋ค.</p>
<a class="with-right-arrow" href="https://tutorials.pytorch.kr/">ํํ ๋ฆฌ์ผ๋ก ์ด๋</a>
</div>
<div class="col-md-4 text-center">
<h2>์ปค๋ฎค๋ํฐ</h2>
<p>๋ค๋ฅธ ์ฌ์ฉ์๋ค๊ณผ ์๊ฒฌ์ ๋๋๊ณ , ๋์์ฃผ์ธ์!</p>
<a class="with-right-arrow" href="https://discuss.pytorch.kr/">์ปค๋ฎค๋ํฐ๋ก ์ด๋</a>
</div>
</div>
</div>
</div>
<footer class="site-footer">
<div class="container footer-container">
<div class="footer-logo-wrapper">
<a href="https://pytorch.kr/" class="footer-logo"></a>
</div>
<div class="footer-links-wrapper">
<div class="footer-links-col">
<ul>
<li class="list-title"><a href="https://pytorch.kr/">ํ์ดํ ์น ํ๊ตญ ์ฌ์ฉ์ ๋ชจ์</a></li>
<li><a href="https://pytorch.kr//about">์ฌ์ฉ์ ๋ชจ์ ์๊ฐ</a></li>
<li><a href="https://pytorch.kr//about/contributors">๊ธฐ์ฌํด์ฃผ์ ๋ถ๋ค</a></li>
<li><a href="https://pytorch.kr//resources">๋ฆฌ์์ค</a></li>
<li><a href="https://pytorch.kr//coc">ํ๋ ๊ฐ๋ น</a></li>
</ul>
</div>
</div>
<div class="trademark-disclaimer">
<ul>
<li>์ด ์ฌ์ดํธ๋ ๋
๋ฆฝ์ ์ธ ํ์ดํ ์น ์ฌ์ฉ์ ์ปค๋ฎค๋ํฐ๋ก, ์ต์ ๋ฒ์ ์ด ์๋๊ฑฐ๋ ์๋ชป๋ ๋ด์ฉ์ด ํฌํจ๋์ด ์์ ์ ์์ต๋๋ค. This site is an independent user community and may be out of date or contain incorrect information.</li>
<li><a href="https://pytorch.kr/coc">ํ๋ ๊ฐ๋ น</a>์ ์ฝ๊ณ ์ง์ผ์ฃผ์ธ์. PyTorch ๊ณต์ ๋ก๊ณ ์ฌ์ฉ ์ ์ฑ
์ <a href="https://www.linuxfoundation.org/policies/">Linux Foundation์ ์ ์ฑ
</a>์ ๋ฐ๋ฆ
๋๋ค. Please read and follow <a href="https://pytorch.kr/coc">our code of conduct</a>. All PyTorch trademark policy applicable to <a href="https://www.linuxfoundation.org/policies/">Linux Foundation's policies</a>.</li>
</ul>
</div>
</div>
</footer>
<!-- End Footer -->
<!-- Begin Mobile Menu -->
<div class="mobile-main-menu">
<div class="container-fluid">