-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathextend_dispatcher.html
1016 lines (835 loc) ยท 73.2 KB
/
extend_dispatcher.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="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Extending dispatcher for a new backend in C++ — PyTorch Tutorials 1.10.2+cu102 documentation</title>
<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/copybutton.css" type="text/css" />
<link rel="stylesheet" href="../_static/gallery.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="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/katex-math.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="PyTorch ๋ชจ๋ ํ๋กํ์ผ๋ง ํ๊ธฐ" href="../beginner/profiler.html" />
<link rel="prev" title="Registering a Dispatched Operator in C++" href="dispatcher.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">
1.10.2+cu102
</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"><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"><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"><span class="caption-text">Introduction to PyTorch on YouTube</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt.html">Introduction to PyTorch - YouTube Series</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/introyt1_tutorial.html">Introduction to PyTorch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/introyt/tensors_deeper_tutorial.html">Introduction to PyTorch Tensors</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"><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="../intermediate/tensorboard_tutorial.html">TensorBoard๋ก ๋ชจ๋ธ, ๋ฐ์ดํฐ, ํ์ต ์๊ฐํํ๊ธฐ</a></li>
</ul>
<p class="caption"><span class="caption-text">์ด๋ฏธ์ง/๋น๋์ค</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/torchvision_tutorial.html">TorchVision ๊ฐ์ฒด ๊ฒ์ถ ๋ฏธ์ธ์กฐ์ (Finetuning) ํํ ๋ฆฌ์ผ</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>
</ul>
<p class="caption"><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="../intermediate/speech_recognition_pipeline_tutorial.html">Speech Recognition with Wav2Vec2</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/speech_command_classification_with_torchaudio_tutorial.html">Speech Command Classification with torchaudio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/text_to_speech_with_torchaudio.html">Text-to-speech with torchaudio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/forced_alignment_with_torchaudio_tutorial.html">Forced Alignment with Wav2Vec2</a></li>
</ul>
<p class="caption"><span class="caption-text">ํ
์คํธ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/transformer_tutorial.html">nn.Transformer ์ TorchText ๋ก ์ํ์ค-ํฌ-์ํ์ค(Sequence-to-Sequence) ๋ชจ๋ธ๋งํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/char_rnn_classification_tutorial.html">๊ธฐ์ด๋ถํฐ ์์ํ๋ NLP: ๋ฌธ์-๋จ์ RNN์ผ๋ก ์ด๋ฆ ๋ถ๋ฅํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/char_rnn_generation_tutorial.html">๊ธฐ์ด๋ถํฐ ์์ํ๋ NLP: ๋ฌธ์-๋จ์ RNN์ผ๋ก ์ด๋ฆ ์์ฑํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/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">nn.Transformer์ torchtext๋ก ์ธ์ด ๋ฒ์ญํ๊ธฐ</a></li>
</ul>
<p class="caption"><span class="caption-text">๊ฐํํ์ต</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/reinforcement_q_learning.html">๊ฐํ ํ์ต (DQN) ํํ ๋ฆฌ์ผ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/mario_rl_tutorial.html">Train a Mario-playing RL Agent</a></li>
</ul>
<p class="caption"><span class="caption-text">PyTorch ๋ชจ๋ธ์ ํ๋ก๋์
ํ๊ฒฝ์ ๋ฐฐํฌํ๊ธฐ</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/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="cpp_export.html">C++์์ TorchScript ๋ชจ๋ธ ๋ก๋ฉํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="super_resolution_with_onnxruntime.html">(์ ํ) PyTorch ๋ชจ๋ธ์ ONNX์ผ๋ก ๋ณํํ๊ณ ONNX ๋ฐํ์์์ ์คํํ๊ธฐ</a></li>
</ul>
<p class="caption"><span class="caption-text">Code Transforms with FX</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/fx_conv_bn_fuser.html">(๋ฒ ํ) FX์์ ํฉ์ฑ๊ณฑ/๋ฐฐ์น ์ ๊ทํ(Convolution/Batch Norm) ๊ฒฐํฉ๊ธฐ(Fuser) ๋ง๋ค๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/fx_profiling_tutorial.html">(beta) Building a Simple CPU Performance Profiler with FX</a></li>
</ul>
<p class="caption"><span class="caption-text">ํ๋ก ํธ์๋ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/memory_format_tutorial.html">(๋ฒ ํ) PyTorch๋ฅผ ์ฌ์ฉํ Channels Last ๋ฉ๋ชจ๋ฆฌ ํ์</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/forward_ad_usage.html">Forward-mode Automatic Differentiation (Beta)</a></li>
<li class="toctree-l1"><a class="reference internal" href="cpp_frontend.html">PyTorch C++ ํ๋ก ํธ์๋ ์ฌ์ฉํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch-script-parallelism.html">TorchScript์ ๋์ ๋ณ๋ ฌ ์ฒ๋ฆฌ(Dynamic Parallelism)</a></li>
<li class="toctree-l1"><a class="reference internal" href="cpp_autograd.html">C++ ํ๋ก ํธ์๋์ ์๋ ๋ฏธ๋ถ (autograd)</a></li>
</ul>
<p class="caption"><span class="caption-text">PyTorch ํ์ฅํ๊ธฐ</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../intermediate/custom_function_double_backward_tutorial.html">Double Backward with Custom Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/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="cpp_extension.html">Custom C++ and CUDA Extensions</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_script_custom_ops.html">Extending TorchScript with Custom C++ Operators</a></li>
<li class="toctree-l1"><a class="reference internal" href="torch_script_custom_classes.html">์ปค์คํ
C++ ํด๋์ค๋ก TorchScript ํ์ฅํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="dispatcher.html">Registering a Dispatched Operator in C++</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Extending dispatcher for a new backend in C++</a></li>
</ul>
<p class="caption"><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="../intermediate/tensorboard_profiler_tutorial.html">PyTorch Profiler With TensorBoard</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/hyperparameter_tuning_tutorial.html">Hyperparameter tuning with 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="../intermediate/parametrizations.html">Parametrizations Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/pruning_tutorial.html">๊ฐ์ง์น๊ธฐ ๊ธฐ๋ฒ(Pruning) ํํ ๋ฆฌ์ผ</a></li>
<li class="toctree-l1"><a class="reference internal" href="dynamic_quantization_tutorial.html">(๋ฒ ํ) LSTM ๊ธฐ๋ฐ ๋จ์ด ๋จ์ ์ธ์ด ๋ชจ๋ธ์ ๋์ ์์ํ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/dynamic_quantization_bert_tutorial.html">(๋ฒ ํ) BERT ๋ชจ๋ธ ๋์ ์์ํํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/quantized_transfer_learning_tutorial.html">(๋ฒ ํ) ์ปดํจํฐ ๋น์ ํํ ๋ฆฌ์ผ์ ์ํ ์์ํ๋ ์ ์ดํ์ต(Quantized Transfer Learning)</a></li>
<li class="toctree-l1"><a class="reference internal" href="static_quantization_tutorial.html">(beta) Static Quantization with Eager Mode in PyTorch</a></li>
</ul>
<p class="caption"><span class="caption-text">๋ณ๋ ฌ ๋ฐ ๋ถ์ฐ ํ์ต</span></p>
<ul>
<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="../intermediate/model_parallel_tutorial.html">๋จ์ผ ๋จธ์ ์ ์ฌ์ฉํ ๋ชจ๋ธ ๋ณ๋ ฌํ ๋ชจ๋ฒ ์ฌ๋ก</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/ddp_tutorial.html">๋ถ์ฐ ๋ฐ์ดํฐ ๋ณ๋ ฌ ์ฒ๋ฆฌ ์์ํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/dist_tuto.html">PyTorch๋ก ๋ถ์ฐ ์ดํ๋ฆฌ์ผ์ด์
๊ฐ๋ฐํ๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/rpc_tutorial.html">Getting Started with Distributed RPC Framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/rpc_param_server_tutorial.html">Implementing a Parameter Server Using Distributed RPC Framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/dist_pipeline_parallel_tutorial.html">Distributed Pipeline Parallelism Using RPC</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/rpc_async_execution.html">Implementing Batch RPC Processing Using Asynchronous Executions</a></li>
<li class="toctree-l1"><a class="reference internal" href="rpc_ddp_tutorial.html">๋ถ์ฐ ๋ฐ์ดํฐ ๋ณ๋ ฌ(DDP)๊ณผ ๋ถ์ฐ RPC ํ๋ ์์ํฌ ๊ฒฐํฉ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intermediate/pipeline_tutorial.html">ํ์ดํ๋ผ์ธ ๋ณ๋ ฌํ๋ก ํธ๋์คํฌ๋จธ ๋ชจ๋ธ ํ์ต์ํค๊ธฐ</a></li>
<li class="toctree-l1"><a class="reference internal" href="ddp_pipeline.html">๋ถ์ฐ ๋ฐ์ดํฐ ๋ณ๋ ฌ ์ฒ๋ฆฌ์ ๋ณ๋ ฌ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํ ํธ๋์คํฌ๋จธ ๋ชจ๋ธ ํ์ต</a></li>
<li class="toctree-l1"><a class="reference internal" href="generic_join.html">Distributed Training with Uneven Inputs Using the Join Context Manager</a></li>
</ul>
<p class="caption"><span class="caption-text">Mobile</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../beginner/deeplabv3_on_ios.html">iOS์์์ ์ด๋ฏธ์ง ๋ถํ DeepLapV3</a></li>
<li class="toctree-l1"><a class="reference internal" href="../beginner/deeplabv3_on_android.html">์๋๋ก์ด๋์์์ ์ด๋ฏธ์ง ๋ถํ DeepLapV3</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>Extending dispatcher for a new backend in C++</li>
<li class="pytorch-breadcrumbs-aside">
<a href="../_sources/advanced/extend_dispatcher.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">advanced/extend_dispatcher</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="extending-dispatcher-for-a-new-backend-in-c">
<h1>Extending dispatcher for a new backend in C++<a class="headerlink" href="#extending-dispatcher-for-a-new-backend-in-c" title="Permalink to this headline">ยถ</a></h1>
<p>In this tutorial we will walk through all necessary steps to extend the dispatcher to
add a new device living outside <code class="docutils literal notranslate"><span class="pre">pytorch/pytorch</span></code> repo and maintain it to keep in
sync with native PyTorch devices. Here weโll assume that youโre familiar with how
to <a class="reference external" href="dispatcher">register a dispatched operator in C++</a> and how to write a
<a class="reference external" href="cpp_autograd">custom autograd function</a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This tutorial touches a lot of internal components inside PyTorch which are being actively improved,
please expect changes to APIs if you decide to follow this tutorial. Weโll keep this tutorial
up to date with the latest APIs.</p>
</div>
<div class="section" id="what-s-a-new-backend">
<h2>Whatโs a new backend?<a class="headerlink" href="#what-s-a-new-backend" title="Permalink to this headline">ยถ</a></h2>
<p>Adding a new backend to PyTorch requires a lot of developement and maintainence from backend extenders.
Before adding a new backend, letโs first consider a few common use cases and recommended solutions for them:</p>
<ul class="simple">
<li>If you have new algorithms for an existing PyTorch operator, send a PR to PyTorch.</li>
<li>If you want to propose a new operator, send a feature request/PR to PyTorch.</li>
<li>If you want to add support for a new device/hardware like Google TPU and customized chips, which often requires using
hardware-specific API to write kernels, follow this tutorial and add a out-of-tree backend to PyTorch.</li>
<li>If you want to add support for existing operators but with a different Tensor layout/representation
like sparse and quantized, which enforces your kernels to be written in a way thatโs more efficient
given the layout/representation limitation, follow this tutorial and add a out-of-tree backend to PyTorch.</li>
</ul>
<p>In this tutorial weโll mainly focus on adding a new out-of-tree device below. Adding out-of-tree support
for a different tensor layout might share many common steps with devices, but we havenโt seen an example of
such integrations yet so it might require addtional work from PyTorch to support it.</p>
</div>
<div class="section" id="get-a-dispatch-key-for-your-backend">
<h2>Get a dispatch key for your backend<a class="headerlink" href="#get-a-dispatch-key-for-your-backend" title="Permalink to this headline">ยถ</a></h2>
<p>PyTorch operators are implemented in C++ and made available in Python frontend through Python bindings.
The PyTorch dispatcher divides the implementation of an operator into multiple kernels, each of which is
associated with a specific dispatch key. Supporting a new backend in PyTorch essentially means writing
a kernel for each PyTorch operator in C++ and then registering them to a dispatch key representing your
customized backend in the dispatcher.</p>
<p>Dispatch key is your identifier in the dispatcher system. The dispatcher looks at the dispatch keys carried on
input tensors and calls the right kernel accordingly. PyTorch provides three reserved dispatch keys
(and their corresponding Autograd keys) for prototyping out-of-tree backend extensions:</p>
<ul class="simple">
<li>PrivateUse1/AutogradPrivateUse1</li>
<li>PrivateUse2/AutogradPrivateUse2</li>
<li>PrivateUse3/AutogradPrivateUse3</li>
</ul>
<p>You can choose any of keys above to prototype your customized backend.
To create a Tensor on <code class="docutils literal notranslate"><span class="pre">PrivateUse1</span></code> backend, you need to set dispatch key in <code class="docutils literal notranslate"><span class="pre">TensorImpl</span></code> constructor.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="cm">/* Example TensorImpl constructor */</span>
<span class="n">TensorImpl</span><span class="p">(</span>
<span class="n">Storage</span><span class="o">&&</span> <span class="n">storage</span><span class="p">,</span>
<span class="n">DispatchKeySet</span> <span class="n">ks</span><span class="p">,</span>
<span class="k">const</span> <span class="n">caffe2</span><span class="o">::</span><span class="n">TypeMeta</span> <span class="n">data_type</span><span class="p">);</span>
<span class="c1">// To create a TensorImpl on PrivateUse1 backend, pass in the following ks to TensorImpl creation.</span>
<span class="n">DispatchKeySet</span> <span class="n">ks</span> <span class="o">=</span> <span class="n">c10</span><span class="o">::</span><span class="n">DispatchKeySet</span><span class="p">{</span><span class="n">c10</span><span class="o">::</span><span class="n">DispatchKey</span><span class="o">::</span><span class="n">PrivateUse1</span><span class="p">,</span> <span class="n">c10</span><span class="o">::</span><span class="n">DispatchKey</span><span class="o">::</span><span class="n">AutogradPrivateUse1</span><span class="p">};</span>
</pre></div>
</div>
<p>Note that <code class="docutils literal notranslate"><span class="pre">TensorImpl</span></code> class above assumes your Tensor is backed by a storage like CPU/CUDA. We also
provide <code class="docutils literal notranslate"><span class="pre">OpaqueTensorImpl</span></code> for backends without a storage. And you might need to tweak/override certain
methods to fit your customized hardware.
One example in pytorch repo is <a class="reference external" href="https://github.com/pytorch/pytorch/blob/1.7/aten/src/ATen/native/vulkan/VulkanOpaqueTensorImpl.h">Vulkan TensorImpl</a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Once the prototype is done and you plan to do regular releases for your backend extension, please feel free to
submit a PR to <code class="docutils literal notranslate"><span class="pre">pytorch/pytorch</span></code> to reserve a dedicated dispath key for your backend.</p>
</div>
</div>
<div class="section" id="get-the-full-list-of-pytorch-operators">
<h2>Get the full list of PyTorch operators<a class="headerlink" href="#get-the-full-list-of-pytorch-operators" title="Permalink to this headline">ยถ</a></h2>
<p>PyTorch provides a full list of extensible C++ operators in generated file
<code class="docutils literal notranslate"><span class="pre">build/aten/src/ATen/RegistrationDeclarations.h</span></code>.
This file is only available after building PyTorch from source.
Hereโs a snippet of the file:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">Tensor</span> <span class="nf">abs</span><span class="p">(</span><span class="k">const</span> <span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::abs(Tensor self) -> Tensor", "dispatch": "True", "default": "True"}</span>
<span class="n">Tensor</span> <span class="o">&</span> <span class="nf">abs_</span><span class="p">(</span><span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::abs_(Tensor(a!) self) -> Tensor(a!)", "dispatch": "True", "default": "True"}</span>
<span class="n">Tensor</span> <span class="o">&</span> <span class="nf">abs_out</span><span class="p">(</span><span class="n">Tensor</span> <span class="o">&</span> <span class="n">out</span><span class="p">,</span> <span class="k">const</span> <span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::abs.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)", "dispatch": "True", "default": "False"}</span>
<span class="n">Tensor</span> <span class="nf">absolute</span><span class="p">(</span><span class="k">const</span> <span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::absolute(Tensor self) -> Tensor", "dispatch": "False", "default": "False"}</span>
<span class="n">Tensor</span> <span class="o">&</span> <span class="nf">absolute_</span><span class="p">(</span><span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::absolute_(Tensor(a!) self) -> Tensor(a!)", "dispatch": "False", "default": "False"}</span>
<span class="n">Tensor</span> <span class="o">&</span> <span class="nf">absolute_out</span><span class="p">(</span><span class="n">Tensor</span> <span class="o">&</span> <span class="n">out</span><span class="p">,</span> <span class="k">const</span> <span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::absolute.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)", "dispatch": "False", "default": "False"}</span>
<span class="n">Tensor</span> <span class="nf">angle</span><span class="p">(</span><span class="k">const</span> <span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::angle(Tensor self) -> Tensor", "dispatch": "True", "default": "True"}</span>
<span class="n">Tensor</span> <span class="o">&</span> <span class="nf">angle_out</span><span class="p">(</span><span class="n">Tensor</span> <span class="o">&</span> <span class="n">out</span><span class="p">,</span> <span class="k">const</span> <span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::angle.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)", "dispatch": "True", "default": "False"}</span>
<span class="n">Tensor</span> <span class="nf">sgn</span><span class="p">(</span><span class="k">const</span> <span class="n">Tensor</span> <span class="o">&</span> <span class="n">self</span><span class="p">);</span> <span class="c1">// {"schema": "aten::sgn(Tensor self) -> Tensor", "dispatch": "True", "default": "True"}</span>
</pre></div>
</div>
<p>Thereโre multiple fields associated with a single operator. Letโs break it down using <code class="docutils literal notranslate"><span class="pre">abs_out</span></code> as an example:</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">Tensor</span> <span class="pre">&</span> <span class="pre">abs_out(Tensor</span> <span class="pre">&</span> <span class="pre">out,</span> <span class="pre">const</span> <span class="pre">Tensor</span> <span class="pre">&</span> <span class="pre">self);</span></code> is the C++ signature of the operator, your C++
kernel should match this signature exactly.</li>
<li><code class="docutils literal notranslate"><span class="pre">aten::abs.out(Tensor</span> <span class="pre">self,</span> <span class="pre">*,</span> <span class="pre">Tensor(a!)</span> <span class="pre">out)</span> <span class="pre">-></span> <span class="pre">Tensor(a!)</span></code> is the unique schema representing the operator,
which also contains aliasing and mutation annotations compared to the C++ signature. This is the unique identifier
the dispatcher uses to find an operator.</li>
<li><code class="docutils literal notranslate"><span class="pre">dispatch</span></code> and <code class="docutils literal notranslate"><span class="pre">default</span></code> are boolean fields that provide information about what native PyTorch kernels
can do, thus implies whether itโs required for backend extenders to implement the kernel.
More details can be found in <a class="reference internal" href="#register-kernel"><span class="std std-ref">register kernels for the new backend</span></a>.</li>
</ul>
</div>
<div class="section" id="register-kernels-for-the-new-backend">
<span id="register-kernel"></span><h2>Register kernels for the new backend<a class="headerlink" href="#register-kernels-for-the-new-backend" title="Permalink to this headline">ยถ</a></h2>
<p>To register your kernels to PyTorch dispatcher, you can use the
<code class="docutils literal notranslate"><span class="pre">TORCH_LIBRARY_IMPL</span></code> API described in
<a class="reference external" href="dispatcher">Registering a Dispatched Operator in C++</a>:</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">TORCH_LIBRARY_IMPL</span><span class="p">(</span><span class="n">aten</span><span class="p">,</span> <span class="n">PrivateUse1</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span> <span class="p">{</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">schema_my_op1</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">my_op1</span><span class="p">);</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">schema_my_op2</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">my_op2</span><span class="p">);</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">schema_my_op2_backward</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">my_op2_backward</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Now letโs zoom in and what operator requires a kernel from a customized backend and whatโs
inside the kernels exactly.</p>
<p>PyTorch currently has more than 1600 operators and itโs still growing. Itโs unrealistic
for backend extensions to keep up with this speed. Even for native backends like CPU
or CUDA, it often requires a lot of work to write dedicated kernels for every new op.</p>
<p>Fortunately, some native PyTorch kernels are written in a way that they decompose to
combination of several known operators. In other words, you only need to implement
a set of known operators (ops that require registration below) instead of all PyTorch operators.</p>
<p>PyTorch operators can be classified into two categories:</p>
<ul>
<li><p class="first">Ops that require registration: PyTorch native implementation for these ops is backend specific
and thus itโs required to provide a kernel for customized backend. Otherwise calling such op
on the customized backend will error out.</p>
<blockquote>
<div><ul class="simple">
<li>In <code class="docutils literal notranslate"><span class="pre">RegistrationDeclarations.h</span></code> these operators have <code class="docutils literal notranslate"><span class="pre">dispatch</span></code> set to True <em>and</em> <code class="docutils literal notranslate"><span class="pre">default</span></code> set to False
in the metadata found in their accompanying comments.</li>
</ul>
</div></blockquote>
</li>
<li><p class="first">Registration is optional: backend extenders can skip registering to these ops without sacrificing any support.
However, if a backend extender wants to override the default kernel provided by PyTorch, they can still
register their customized kernel to their backend and the dispatcher will use it for your backend only.
For example, current implementation of PyTorchโs <code class="docutils literal notranslate"><span class="pre">max_pool2d</span></code> returns <code class="docutils literal notranslate"><span class="pre">indices</span></code> as part of forward outputs which
creates overhead in torch_xla, so torch_xla registers its own kernel for <code class="docutils literal notranslate"><span class="pre">max_pool2d</span></code> instead.</p>
<blockquote>
<div><ul class="simple">
<li>In <code class="docutils literal notranslate"><span class="pre">RegistrationDeclarations.h</span></code> these operators have <code class="docutils literal notranslate"><span class="pre">dispatch</span></code> set to False <em>or</em> <code class="docutils literal notranslate"><span class="pre">default</span></code> set to True
in the metadata found in their accompanying comments.</li>
</ul>
</div></blockquote>
</li>
</ul>
</div>
<div class="section" id="autograd-support-for-the-new-backend">
<h2>Autograd support for the new backend<a class="headerlink" href="#autograd-support-for-the-new-backend" title="Permalink to this headline">ยถ</a></h2>
<p>Gradient formulas are mostly purely mathematical and thus are general for all backends.
PyTorch often registers a kernel to alias dispatch key Autograd, which means it can be used by all backends.</p>
<p>For these operators you donโt have to worry about their derivative formulas,
you can just write forward definitions for operators in <code class="docutils literal notranslate"><span class="pre">RegistrationDeclarations.h</span></code> and PyTorch handles
backward for you automatically.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">Tensor</span> <span class="nf">my_op1</span><span class="p">(</span><span class="k">const</span> <span class="n">Tensor</span><span class="o">&</span> <span class="n">self</span><span class="p">,</span> <span class="k">const</span> <span class="n">Tensor</span><span class="o">&</span> <span class="n">other</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// call your backend-specific APIs to implement my_op so that</span>
<span class="c1">// it matches PyTorch's native behavior</span>
<span class="p">}</span>
<span class="n">TORCH_LIBRARY_IMPL</span><span class="p">(</span><span class="n">aten</span><span class="p">,</span> <span class="n">PrivateUse1</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span> <span class="p">{</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">schema_my_op1</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">my_op</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<p>In some cases, PyTorch backward kernel implementations are also device specific so that they can squeeze out
max performance out of each backend. For those operators youโll see op_backward showing up in
<code class="docutils literal notranslate"><span class="pre">RegistrationDeclarations.h</span></code> as <em>required registration</em> as well.</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="n">Tensor</span> <span class="nf">my_op2_backward</span><span class="p">(</span><span class="k">const</span> <span class="n">Tensor</span><span class="o">&</span> <span class="n">self</span><span class="p">,</span> <span class="k">const</span> <span class="n">Tensor</span><span class="o">&</span> <span class="n">other</span><span class="p">)</span> <span class="p">{</span>
<span class="c1">// call your backend-specific APIs to implement my_op2_backward so that</span>
<span class="c1">// it matches PyTorch's native behavior</span>
<span class="p">}</span>
<span class="c1">// Note backward kernel is still registered to PrivateUse1 instead of AutogradPrivateUse1.</span>
<span class="c1">// PyTorch will wrap your backward kernel with proper autograd setup and then link to it in</span>
<span class="c1">// my_op2's AutogradPrivateUse1 kernel.</span>
<span class="n">TORCH_LIBRARY_IMPL</span><span class="p">(</span><span class="n">aten</span><span class="p">,</span> <span class="n">PrivateUse1</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span> <span class="p">{</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">schema_my_op2</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">my_op2</span><span class="p">);</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">schema_my_op2_backward</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">my_op2_backward</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<p>In a few <em>rare</em> cases, PyTorchโs gradient formula for certain operators may have assumptions that donโt generalize
for all backends. In those cases backend extenders can optionally override PyTorch Autograd layer by registering
a kernel from torch::autograd::Function to the corresponding dispatch key (for example, AutogradPrivateUse1 if
youโre using PrivateUse1 for your backend):</p>
<div class="highlight-cpp notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyAddFunction</span> <span class="o">:</span> <span class="k">public</span> <span class="n">torch</span><span class="o">::</span><span class="n">autograd</span><span class="o">::</span><span class="n">Function</span><span class="o"><</span><span class="n">MyAddFunction</span><span class="o">></span> <span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="k">static</span> <span class="n">Tensor</span> <span class="n">forward</span><span class="p">(</span><span class="n">AutogradContext</span> <span class="o">*</span><span class="n">ctx</span><span class="p">,</span> <span class="n">torch</span><span class="o">::</span><span class="n">Tensor</span> <span class="n">self</span><span class="p">,</span> <span class="n">torch</span><span class="o">::</span><span class="n">Tensor</span> <span class="n">other</span><span class="p">)</span> <span class="p">{</span>
<span class="n">at</span><span class="o">::</span><span class="n">AutoNonVariableTypeMode</span> <span class="n">g</span><span class="p">;</span>
<span class="k">return</span> <span class="nf">myadd</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">other</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">static</span> <span class="n">tensor_list</span> <span class="n">backward</span><span class="p">(</span><span class="n">AutogradContext</span> <span class="o">*</span><span class="n">ctx</span><span class="p">,</span> <span class="n">tensor_list</span> <span class="n">grad_outputs</span><span class="p">)</span> <span class="p">{</span>
<span class="k">auto</span> <span class="n">grad_output</span> <span class="o">=</span> <span class="n">grad_outputs</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>
<span class="k">return</span> <span class="p">{</span><span class="n">grad_output</span><span class="p">,</span> <span class="n">grad_output</span><span class="p">};</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="n">Tensor</span> <span class="nf">myadd_autograd</span><span class="p">(</span><span class="k">const</span> <span class="n">Tensor</span><span class="o">&</span> <span class="n">self</span><span class="p">,</span> <span class="k">const</span> <span class="n">Tensor</span><span class="o">&</span> <span class="n">other</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="n">MyAddFunction</span><span class="o">::</span><span class="n">apply</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">other</span><span class="p">)[</span><span class="mi">0</span><span class="p">];</span>
<span class="p">}</span>
<span class="c1">// Register the autograd kernel to AutogradPrivateUse1</span>
<span class="n">TORCH_LIBRARY_IMPL</span><span class="p">(</span><span class="n">aten</span><span class="p">,</span> <span class="n">AutogradPrivateUse1</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span> <span class="p">{</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">myadd_schema</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">myadd_autograd</span><span class="p">);</span>
<span class="p">}</span>
<span class="c1">// Register the inference kernel to PrivateUse1</span>
<span class="n">TORCH_LIBRARY_IMPL</span><span class="p">(</span><span class="n">aten</span><span class="p">,</span> <span class="n">PrivateUse1</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span> <span class="p">{</span>
<span class="n">m</span><span class="p">.</span><span class="n">impl</span><span class="p">(</span><span class="o"><</span><span class="n">myadd_schema</span><span class="o">></span><span class="p">,</span> <span class="o">&</span><span class="n">myadd</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<p>With this trick you have full control over both training and inference behavior for <code class="docutils literal notranslate"><span class="pre">my_add</span></code> operator in your backend.
Hereโs <a class="reference external" href="https://github.com/pytorch/xla/blob/r1.7/torch_xla/csrc/aten_autograd_ops.h">an example</a> in the <code class="docutils literal notranslate"><span class="pre">pytorch/xla</span></code> repository.</p>
</div>
<div class="section" id="build-an-extension">
<h2>Build an extension<a class="headerlink" href="#build-an-extension" title="Permalink to this headline">ยถ</a></h2>
<p>Out-of-tree backend is supported by adding a C++ extension to PyTorch.
Once you have kernels and registrations ready, you can build a C++ extension by
writing a <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> script that uses <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> to compile C++ code. Hereโs a simplified example from
<a class="reference external" href="https://github.com/pytorch/xla/blob/master/setup.py">pytorch/xla repo</a>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">setuptools</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="kn">from</span> <span class="nn">torch.utils.cpp_extension</span> <span class="kn">import</span> <span class="n">BuildExtension</span><span class="p">,</span> <span class="n">CppExtension</span>
<span class="n">setup</span><span class="p">(</span>
<span class="n">name</span><span class="o">=</span><span class="s1">'torch_xla'</span><span class="p">,</span>
<span class="n">ext_modules</span><span class="o">=</span><span class="p">[</span>
<span class="n">CppExtension</span><span class="p">(</span>
<span class="s1">'_XLAC'</span><span class="p">,</span>
<span class="n">torch_xla_sources</span><span class="p">,</span>
<span class="n">include_dirs</span><span class="o">=</span><span class="n">include_dirs</span><span class="p">,</span>
<span class="n">extra_compile_args</span><span class="o">=</span><span class="n">extra_compile_args</span><span class="p">,</span>
<span class="n">library_dirs</span><span class="o">=</span><span class="n">library_dirs</span><span class="p">,</span>
<span class="n">extra_link_args</span><span class="o">=</span><span class="n">extra_link_args</span> <span class="o">+</span> \
<span class="p">[</span><span class="n">make_relative_rpath</span><span class="p">(</span><span class="s1">'torch_xla/lib'</span><span class="p">)],</span>
<span class="p">),</span>
<span class="p">],</span>
<span class="n">cmdclass</span><span class="o">=</span><span class="p">{</span>
<span class="s1">'build_ext'</span><span class="p">:</span> <span class="n">Build</span><span class="p">,</span> <span class="c1"># Build is a derived class of BuildExtension</span>
<span class="p">}</span>
<span class="c1"># more configs...</span>
<span class="p">)</span>
</pre></div>
</div>
<p>See <a class="reference external" href="https://tutorials.pytorch.kr/advanced/cpp_extension.html#building-with-setuptools">our C++ extension tutorial</a>
for more details.</p>
</div>
<div class="section" id="custom-operator-support">
<h2>Custom operator support<a class="headerlink" href="#custom-operator-support" title="Permalink to this headline">ยถ</a></h2>
<p>Your new backend should work seamlessly with
<a class="reference external" href="https://pytorch.org/docs/stable/notes/extending.html">customized operators extended in python</a>
without writing any new kernels as long as the customized operator is composed of existing
PyTorch operators (which are already supported by your backend).</p>
<p>For <a class="reference external" href="cpp_autograd">custom operators extended in C++</a> they often come with a
<a class="reference external" href="https://github.com/pytorch/vision/blob/master/torchvision/csrc/ops/cuda/nms_kernel.cu">backend specific C++ kernel implementation e.g. nms kernel in torchvsion</a>
as well as <a class="reference external" href="https://github.com/pytorch/vision/blob/master/torchvision/csrc/ops/nms.cpp#L18">a customized Python API e.g. torch.ops.torchvision.nms</a>.
To support these operators, backend extenders will need to write a C++ kernel for your backend and properly
register it to the corresponding namespace in the dispatcher similar to supporting PyTorch native operators.
Alternatively you could also add a customized API in your extension e.g <code class="docutils literal notranslate"><span class="pre">torch_xla.core.functions.nms</span></code> for
these adhoc requests.</p>
</div>
<div class="section" id="jit-support">
<h2>JIT support<a class="headerlink" href="#jit-support" title="Permalink to this headline">ยถ</a></h2>
<p>As we mentioned in <a class="reference external" href="dispatcher">Registering a Dispatched Operator in C++</a>, kernels registered through <cite>m.impl()</cite> API
support being called in both unboxed and boxed ways. In other words your customized backend can also work with our
JIT tracing/scripting frontend just like the in-tree backends like CPU or CUDA do. You could potentially also write specialized optimization
passes for your backend on a JIT graph. But we will not discuss it here since we havenโt finalized the integration point
in JIT, so the current backend support will focus on the eager frontend for now.</p>
</div>
<div class="section" id="testing-your-backend-against-native-pytorch-backends">
<h2>Testing your backend against native PyTorch backends<a class="headerlink" href="#testing-your-backend-against-native-pytorch-backends" title="Permalink to this headline">ยถ</a></h2>
<p>PyTorch lets tests run on multiple device types using its <a class="reference external" href="https://github.com/pytorch/pytorch/blob/master/torch/testing/_internal/common_device_type.py">generic device type testing framework</a>.
You can find details about <a class="reference external" href="https://github.com/pytorch/pytorch/blob/5a8198eb3c594aa18352930fd21f3c25bd7b7100/torch/testing/_internal/common_device_type.py#L23">how tests use it</a>
and information about <a class="reference external" href="https://github.com/pytorch/pytorch/blob/5a8198eb3c594aa18352930fd21f3c25bd7b7100/torch/testing/_internal/common_device_type.py#L369">how to add a new device type</a>.
Once added, PyTorch tests using the generic device type testing framework will be run using your device type, too.
See <a class="reference external" href="https://github.com/pytorch/pytorch/wiki/Writing-tests-that-run-on-all-available-device-types">this Wiki page</a> for an example of how tests are instantiated.</p>
<p>Running PyTorchโs existing test suites with your device type is important to ensure correctness,
but not all PyTorch features are supported by every device type. The generic device type testing
framework allows for considerable customization so that device types can select which tests to run,
which dtypes they support, and even which precisions to use when comparing tensors for equality.</p>
<p>An example device type that uses the generic device type testing framework and doesnโt ship with
PyTorch is XLA. See <a class="reference external" href="https://github.com/pytorch/xla/blob/master/test/pytorch_test_base.py">its extension of the generic device type testing framework</a>,
which contains examples of block listing tests, block listing dtypes, and overriding test precision.</p>
<p>The generic device type testing framework is actively developed. To request a feature please file an
issue on PyTorchโs Github.</p>
</div>
<div class="section" id="backward-compatibility">
<h2>Backward Compatibility<a class="headerlink" href="#backward-compatibility" title="Permalink to this headline">ยถ</a></h2>
<p>Currently PyTorch canโt guarantee backward compatibility for registered operators.
Operators, as well as their schemas, might be added/modified/deleted as needed. Registered
kernels must be <em>exactly</em> the same as PyTorch version. If PyTorch adds more parameters (
even with defaults) for an operator, your old registration wonโt work until itโs updated
to match PyTorchโs new signature.</p>
<p>As a result, we <em>highly recommend</em> out-of-tree backend extenders only sync with major PyTorch
releases to minimize interruptions in development. PyTorch is on a quarterly release cadence.
Backend extenders should join the <em>#announcement</em> channel at <a class="reference external" href="http://pytorch.slack.com/">pytorch.slack.com</a>
to get latest updates on releases.</p>
</div>
<div class="section" id="known-issues-additional-notes">
<h2>Known issues & additional notes<a class="headerlink" href="#known-issues-additional-notes" title="Permalink to this headline">ยถ</a></h2>
<ul class="simple">
<li>Not all test suites are device generic yet. Extensible test classes can be found by searching
<code class="docutils literal notranslate"><span class="pre">instantiate_device_type_tests</span></code> in PyTorch codebase, e.g
<code class="docutils literal notranslate"><span class="pre">TestTorchDeviceType,</span> <span class="pre">TestViewOps,</span> <span class="pre">TestTensorDeviceOps,</span> <span class="pre">TestTypePromotion</span></code> etc.</li>
<li>Thereโs no extension point in C++ for serializing a python Tensor object on customized backend. Currently
you can only extend it by modifying <a class="reference external" href="https://github.com/pytorch/pytorch/blob/5640b79bf8a5412a0209a919c05c811d5427cc12/torch/tensor.py#L83-L150">PyTorch Tensor __reduce_ex__ method</a>
or monkey patching in out-of-tree repository.</li>
<li>If your backend doesnโt allow direct memory access, you should pay additional attention to supporting
view ops since theyโre supposed to share storage. Changes to view tensor need to propagated to its
base tensor and vice versa.</li>
<li>Thereโs no extension point in C++ for Optimizer if your backend doesnโt work with the native PyTorch
Optimizers, e.g. need to carry the states to be updated in backward like torch-xla. Such use cases
currently can only be done through adding customized API or monkey patching in out-of-tree repository.</li>
</ul>
</div>
<div class="section" id="future-work">
<h2>Future Work<a class="headerlink" href="#future-work" title="Permalink to this headline">ยถ</a></h2>
<p>Making every component in PyTorch extensible for an out-of-tree backend seamless
requires a lot of changes to PyTorch internals. Here are a few items that weโre
actively working on might improve the experience in the future:</p>
<ul class="simple">
<li>Improve test coverage of generic testing framework.</li>
<li>Improve <code class="docutils literal notranslate"><span class="pre">Math</span></code> kernel coverage and more comprehensive tests to make sure <code class="docutils literal notranslate"><span class="pre">Math</span></code>
kernel bahavior matches other backends like <code class="docutils literal notranslate"><span class="pre">CPU/CUDA</span></code>.</li>
<li>Refactor <code class="docutils literal notranslate"><span class="pre">RegistrationDeclarations.h</span></code> to carry the minimal information and reuse
PyTorchโs codegen as much as possible.</li>
<li>Support a backend fallback kernel to automatic convert inputs to CPU and convert the
result back to the customized backend. This will allow โfullโ operator coverage even
though you donโt have kernels written for every operator.</li>
</ul>
</div>
<div class="section" id="stay-in-touch">
<h2>Stay in touch<a class="headerlink" href="#stay-in-touch" title="Permalink to this headline">ยถ</a></h2>
<p>Please use <a class="reference external" href="https://dev-discuss.pytorch.org/">PyTorch dev discussions</a> for questions and discussions. If you have
any feature requests or bug reports, please <a class="reference external" href="https://github.com/pytorch/pytorch/issues">file an issue on github</a>.</p>
<p>If youโre interested in helping in any of the future work items above (e.g adding more <code class="docutils literal notranslate"><span class="pre">Math</span></code>
kernels for PyTorch operators in C++), please reach out to us through Github or Slack!</p>
</div>
</div>
</article>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../beginner/profiler.html" class="btn btn-neutral float-right" title="PyTorch ๋ชจ๋ ํ๋กํ์ผ๋ง ํ๊ธฐ" accesskey="n" rel="next">Next <img src="../_static/images/chevron-right-orange.svg" class="next-page"></a>
<a href="dispatcher.html" class="btn btn-neutral" title="Registering a Dispatched Operator in C++" accesskey="p" rel="prev"><img src="../_static/images/chevron-right-orange.svg" class="previous-page"> Previous</a>
</div>
<hr class="rating-hr hr-top">
<div class="rating-container">
<div class="rating-prompt">Rate this Tutorial</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 2021, PyTorch & PyTorch Korea Community.
</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>
</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="#">Extending dispatcher for a new backend in C++</a><ul>
<li><a class="reference internal" href="#what-s-a-new-backend">Whatโs a new backend?</a></li>
<li><a class="reference internal" href="#get-a-dispatch-key-for-your-backend">Get a dispatch key for your backend</a></li>
<li><a class="reference internal" href="#get-the-full-list-of-pytorch-operators">Get the full list of PyTorch operators</a></li>
<li><a class="reference internal" href="#register-kernels-for-the-new-backend">Register kernels for the new backend</a></li>
<li><a class="reference internal" href="#autograd-support-for-the-new-backend">Autograd support for the new backend</a></li>
<li><a class="reference internal" href="#build-an-extension">Build an extension</a></li>
<li><a class="reference internal" href="#custom-operator-support">Custom operator support</a></li>
<li><a class="reference internal" href="#jit-support">JIT support</a></li>
<li><a class="reference internal" href="#testing-your-backend-against-native-pytorch-backends">Testing your backend against native PyTorch backends</a></li>
<li><a class="reference internal" href="#backward-compatibility">Backward Compatibility</a></li>
<li><a class="reference internal" href="#known-issues-additional-notes">Known issues & additional notes</a></li>
<li><a class="reference internal" href="#future-work">Future Work</a></li>
<li><a class="reference internal" href="#stay-in-touch">Stay in touch</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 type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/clipboard.min.js"></script>
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/contrib/auto-render.min.js"></script>
<script type="text/javascript" src="../_static/katex_autorenderer.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>
//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; isplay: 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=UA-71919972-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-71919972-3');
</script>
<script>
$("[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")
});
});
if (location.pathname == "/") {
$(".rating-container").hide();
$(".hr-bottom").hide();
}
</script>
<script type="text/javascript">
var collapsedSections = ['ํ์ดํ ์น(PyTorch) ๋ ์ํผ', 'ํ์ดํ ์น(PyTorch) ๋ฐฐ์ฐ๊ธฐ', '์ด๋ฏธ์ง/๋น๋์ค', '์ค๋์ค', 'ํ
์คํธ', '๊ฐํํ์ต', 'PyTorch ๋ชจ๋ธ์ ํ๋ก๋์
ํ๊ฒฝ์ ๋ฐฐํฌํ๊ธฐ', 'Code Transforms with FX', 'ํ๋ก ํธ์๋ API', 'PyTorch ํ์ฅํ๊ธฐ', '๋ชจ๋ธ ์ต์ ํ', '๋ณ๋ ฌ ๋ฐ ๋ถ์ฐ ํ์ต', 'Mobile'];
</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>๊ณต์ ๋ฌธ์ (์์ด)</h2>
<p>PyTorch ๊ณต์ ๋ฌธ์์
๋๋ค.</p>
<a id="orgTutorialLink" class="with-right-arrow" href="https://pytorch.org/docs/stable/index.html" target="_blank">๊ณต์ ๋ฌธ์๋ก ์ด๋</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.org">PyTorch ํํ์ด์ง (๊ณต์)</a></li>
<li><a href="https://pytorch.org" target="_blank">๊ณต์ ํํ์ด์ง</a></li>
<li><a href="https://pytorch.org/tutorials" target="_blank">๊ณต์ ํํ ๋ฆฌ์ผ</a></li>
<li><a href="https://pytorch.org/docs" target="_blank">๊ณต์ ๋ฌธ์</a></li>
</ul>
</div>
<div class="footer-links-col">
<ul>
<li class="list-title"><a href="">ํ๊ตญ ์ฌ์ฉ์ ๋ชจ์</a></li>
<li><a href="https://pytorch.kr/about">์ฌ์ดํธ ์๊ฐ</a></li>
<li><a href="https://tutorials.pytorch.kr/">ํ๊ตญ์ด ํํ ๋ฆฌ์ผ</a></li>
<li><a href="https://github.com/9bow/PyTorch-tutorials-kr" target="_blank">ํ๊ตญ์ด ํํ ๋ฆฌ์ผ ์ ์ฅ์</a></li>
</ul>
</div>
</div>
<div class="trademark-disclaimer">
<ul>
<li>์ด ์ฌ์ดํธ๋ PyTorch ํ๊ตญ ์ฌ์ฉ์ ์ปค๋ฎค๋ํฐ๋ก Facebook, Inc์์ ์ด์ํ๋ ์ฌ์ดํธ๊ฐ ์๋๋๋ค. PyTorch, PyTorch ๋ก๊ณ ๋ฐ ๋ชจ๋ ๊ด๋ จ ํ๊ธฐ๋ Facebook, Inc์ ์ํ์
๋๋ค.</li>
<li>This site is a user community and is not operated by Facebook, Inc. PyTorch, the PyTorch logo and any related marks are trademarks of Facebook, Inc.</li>
</ul>
</div>
</div>
</footer>
<!-- End Footer -->
<!-- Begin Mobile Menu -->
<div class="mobile-main-menu">
<div class="container-fluid">
<div class="container">
<div class="mobile-main-menu-header-container">
<a class="header-logo" href="https://pytorch.kr/" aria-label="PyTorch"></a>
<a class="main-menu-close-button" href="#" data-behavior="close-mobile-menu"></a>
</div>
</div>
</div>
<div class="mobile-main-menu-links-container">
<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>
</div>
</div>
<!-- End Mobile Menu -->
<script type="text/javascript" src="../_static/js/vendor/anchor.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
mobileMenu.bind();