{"id":351591,"date":"2024-05-20T21:50:46","date_gmt":"2024-05-20T21:50:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=351591"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=351591","title":{"rendered":"<span>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 PyTorch \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0441\u043f\u0435\u0448\u0438\u0442<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d26\/392\/f5a\/d26392f5a9265b6e441ba75005e7697d.webp\" width=\"1200\" height=\"627\"\/><\/figure>\n<p><em>\u0413\u043b\u0443\u0431\u043e\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0432\u0441\u0451 \u0440\u0435\u0436\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432.<\/em><\/p>\n<p><em>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0445\u0430\u0431\u0440\u0430\u0441\u0441\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u0441\u0442\u0430 \u0438\u0437 \u0431\u043b\u043e\u0433\u0430 <\/em><a href=\"https:\/\/lambdalabs.com\/\" rel=\"noopener noreferrer nofollow\"><em>LambdaLabs<\/em><\/a><em>, \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0435\u0439\u0441\u044f \u043d\u0430 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u043b\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u043d \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 PyTorch \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u0430\u0445.<\/em><\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/64d25f7b120b821486c9879e\" data-style=\"\" id=\"64d25f7b120b821486c9879e\" width=\"\"><\/div>\n<p><a href=\"https:\/\/pytorch.org\/\" rel=\"noopener noreferrer nofollow\">PyTorch <\/a>\u0437\u0430\u0434\u0443\u043c\u0430\u043d \u043a\u0430\u043a\u00a0\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043d \u0434\u0430\u0436\u0435 \u0432\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u0430\u0434\u0430\u0447. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043d \u0441\u0442\u0430\u043b <a href=\"https:\/\/paperswithcode.com\/trends\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u043c\u044b\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0434\u043b\u044f\u00a0\u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/a> \u0441\u0440\u0435\u0434\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0434\u0430\u043b\u0435\u043a\u043e \u043f\u043e\u0437\u0430\u0434\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0437\u0430\u00a0\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/pytorch.org\/tutorials\/beginner\/dist_overview.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432<\/a> \u0438 <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u00a0\u0431\u043b\u043e\u0433\u0430\u0445<\/a>, \u043d\u0435\u00a0\u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e\u00a0\u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c PyTorch \u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <strong>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432<\/strong>.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0446\u0435\u043b\u044c \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043a\u0440\u0430\u0442\u043a\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u00a0\u0432\u00a0PyTorch <strong>\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c<\/strong> \u0438 <strong>\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c<\/strong> \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u0438\u0441\u0445\u043e\u0434\u0438\u043c \u0438\u0437\u00a0\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u00a0\u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u044b\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f PyTorch \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e <a href=\"https:\/\/pytorch.org\/tutorials\/intermediate\/ddp_tutorial.html\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/a> \u0438 \u0445\u043e\u0447\u0435\u0442\u00a0\u0431\u044b\u0441\u0442\u0440\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u0435\u043b \u043c\u0435\u0436\u0434\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0437\u0430\u0434\u0430\u0447 \u043d\u0430\u00a0\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0445 \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445. \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437\u00a0\u044d\u0442\u043e\u0433\u043e, \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430:<\/p>\n<ul>\n<li>\n<p>\u043e\u0431\u0449\u0438\u0445 \u0438\u0434\u0435\u044f\u0445 \u043e\u00a0\u0442\u043e\u043c, \u043a\u0430\u043a\u00a0\u043f\u043e\u0434\u00a0\u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0PyTorch;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432\u00a0\u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0442\u043e\u043c, \u043a\u0430\u043a\u00a0\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>torch.distributed.launch<\/code>, <code>torchrun<\/code> \u0438<code>mpirun<\/code> .<\/p>\n<\/li>\n<\/ul>\n<h2>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e PyTorch<\/h2>\n<p>\u0418\u0434\u0435\u044f, \u043b\u0435\u0436\u0430\u0449\u0430\u044f \u0432\u00a0\u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e PyTorch, \u043f\u0440\u043e\u0441\u0442\u043e\u00a0\u2014 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u0421\u0443\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u00a0\u0436\u0435 \u0441\u0430\u043c\u0430\u044f, \u043a\u0430\u043a\u00a0\u0443\u00a0MPI, \u0442\u043e \u0435\u0441\u0442\u044c, \u0447\u0442\u043e\u2011\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>mpirun -n 3 echo hello world<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0440\u0438\u0436\u0434\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u00a0\u0432\u044b\u0432\u043e\u0434\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u00abhello world\u00bb:<\/p>\n<pre><code class=\"bash\">ubuntu@ubuntu-desktop:~$ mpirun -n 3 echo hello world hello world hello world hello world<\/code><\/pre>\n<p>\u041d\u043e\u00a0\u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u00a0PyTorch \u043e\u0442\u00a0\u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441 <code>mpirun<\/code>.<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u00a0\u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u043e\u043c\u0443 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u0435\u043b\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, GPU), \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c <strong>\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439<\/strong> \u043f\u0440\u0438\u00a0\u043f\u0440\u044f\u043c\u043e\u043c \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c <strong>\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044e<\/strong> \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u00a0\u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e\u00a0\u0431\u044b\u043b\u043e \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f\u00a0\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 PyTorch \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b \u043a\u00a0\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u00bb (<code>torch.distributed.init_process_group<\/code>), \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0438\u0445 \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0\u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>nccl<\/code>), \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0432\u0430\u0448 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043c\u043e\u0433\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0440\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 (\u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>torch.utils.data.distributed.DistributedSampler<\/code> \u0438 <code>torch.nn.parallel.DistributedDataParallel<\/code>).<\/p>\n<p>\u0415\u0449\u0451 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0451 \u0432\u043e\u0435\u0434\u0438\u043d\u043e: <code>WORLD_SIZE<\/code>, <code>WORLD_RANK<\/code> \u0438 <code>LOCAL_RANK<\/code> . \u0418\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0434\u043b\u044f\u00a0\u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439 \u043a\u0430\u043a \u00ab\u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e GPU \u0432\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435\u00bb, \u00ab\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 GPU\u00bb \u0438 \u00ab\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f\u00a0\u0443\u0437\u043b\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 GPU\u00bb. \u041a\u0430\u043a\u00a0\u0432\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u043e\u043d\u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f\u00a0\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0430\u00a0\u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0436\u0438\u0437\u043d\u0438 \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e.<\/p>\n<h2>\u041f\u0438\u0448\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u00a0PyTorch<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u00a0\u0440\u044f\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 PyTorch, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0437\u043b\u043e\u0432. \u041d\u0430\u0447\u043d\u0451\u043c \u0441\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u00a0PyTorch Distributed Data Parallel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0443\u0437\u043b\u0430\u0445. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u043c, \u043a\u0430\u043a\u00a0\u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u044b\u0442 \u043d\u0430\u00a0\u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 ResNet.<\/p>\n<p>\u0412\u00a0\u0446\u0435\u043b\u044f\u0445 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <code>2xA600<\/code> \u0432\u00a0Lambda Cloud. \u041d\u043e\u00a0\u0442\u0435\u00a0\u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043b\u044f\u00a0on\u2011prem \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0441\u00a0\u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0434\u0432\u0443\u043c\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 <a href=\"https:\/\/lambdalabs.com\/gpu-cluster\/echelon\" rel=\"noopener noreferrer nofollow\">Lambda Echelon<\/a>.<\/p>\n<p>\u042d\u0442\u0438 \u0434\u0432\u0430 \u0443\u0437\u043b\u0430 <code>2xA600<\/code> (\u0441 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 <code>104.171.200.62<\/code> \u0438 <code>104.171.200.182<\/code>) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c 4\u00a0\u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 (\u043f\u043e 2\u00a0\u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b).<\/p>\n<h3>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u0435\u0442 \u0442\u0435\u043d\u0437\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430\u00a0\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c <a href=\"https:\/\/pytorch.org\/tutorials\/intermediate\/dist_tuto.html\" rel=\"noopener noreferrer nofollow\">\u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435<\/a> \u043f\u043e\u00a0PyTorch, \u043d\u043e\u00a0\u043c\u044b \u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u0438 (\u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043c \u043d\u0435\u00a0\u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u0441\u044f \u043e\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e\u0441\u0442\u0438 \u0432\u00a0PyTorch) \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438, \u0430\u00a0\u043d\u0435\u00a0\u0432\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e (\u0432\u0435\u0434\u044c \u0432\u00a0\u044d\u0442\u043e\u043c\u2011\u0442\u043e \u0432\u0441\u044f \u0441\u0443\u0442\u044c, \u0442\u0430\u043a \u0432\u0435\u0434\u044c?).<\/p>\n<pre><code class=\"python\">import os import argparse  import torch import torch.distributed as dist  # Environment variables set by torch.distributed.launch LOCAL_RANK = int(os.environ['LOCAL_RANK']) WORLD_SIZE = int(os.environ['WORLD_SIZE']) WORLD_RANK = int(os.environ['RANK'])  def run(backend):     tensor = torch.zeros(1)          # Need to put tensor on a GPU device for nccl backend     if backend == 'nccl':         device = torch.device(\"cuda:{}\".format(LOCAL_RANK))         tensor = tensor.to(device)      if WORLD_RANK == 0:         for rank_recv in range(1, WORLD_SIZE):             dist.send(tensor=tensor, dst=rank_recv)             print('worker_{} sent data to Rank {}\\n'.format(0, rank_recv))     else:         dist.recv(tensor=tensor, src=0)         print('worker_{} has received data from rank {}\\n'.format(WORLD_RANK, 0))  def init_processes(backend):     dist.init_process_group(backend, rank=WORLD_RANK, world_size=WORLD_SIZE)     run(backend)  if __name__ == \"__main__\":      parser = argparse.ArgumentParser()     parser.add_argument(\"--local_rank\", type=int, help=\"Local rank. Necessary for using the torch.distributed.launch utility.\")     parser.add_argument(\"--backend\", type=str, default=\"nccl\", choices=['nccl', 'gloo'])     args = parser.parse_args()      init_processes(backend=args.backend)<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 4\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 <code>worker_0<\/code> \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0442\u0435\u043d\u0437\u043e\u0440 \u043d\u0430\u00a0GPU 0\u00a0\u0443\u0437\u043b\u0430 104.171.200.62, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u043c\u0441\u044f \u0442\u0440\u0451\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c. \u041a\u0430\u043a\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0442\u0435\u043d\u0437\u043e\u0440, \u043e\u043d \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\"># output from node 104.171.200.62 worker_0 sent data to Rank 1 worker_0 sent data to Rank 2 worker_0 sent data to Rank 3 worker_1 has received data from rank 0  # output from node 104.171.200.182 worker_2 has received data from rank 0 worker_3 has received data from rank 0<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u00a0\u044d\u0442\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>dist.init_process_group(backend, rank=WORLD_RANK, world_size=WORLD_SIZE)<\/code>. \u041a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d \u043a\u0430\u043a <code>worker_$WORLD_RANK<\/code> , \u0432\u0441\u0435\u0433\u043e \u0432\u00a0\u0433\u0440\u0443\u043f\u043f\u0435 \u0431\u0443\u0434\u0435\u0442 <code>$WORLD_SIZE<\/code> \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>run<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>WORLD_RANK<\/code> \u0438 <code>WORLD_SIZE<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u00a0\u0432\u044b\u0437\u043e\u0432\u0435 <code>dist.init_process_group<\/code> \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 \u0447\u0442\u043e <code>LOCAL_RANK<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u00a0\u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>run<\/code> \u0447\u0442\u043e\u0431\u044b \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 GPU. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043c\u043e\u0436\u043d\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442\u00a0\u0442\u043e\u0433\u043e, \u043d\u0430\u00a0\u043a\u0430\u043a\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u0442\u043e \u0447\u0442\u043e\u00a0\u0438\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f GPU. <\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>backend<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 (nccl, gloo \u0438\u00a0\u0442.\u00a0\u043f.) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f\u00a0\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438. PyTorch \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u043d\u043e\u00a0\u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u044d\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f\u00a0\u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043c\u0435\u0442\u0438\u043c \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>local_rank<\/code> \u0432\u00a0\u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u043a\u0430\u043a \u043d\u0435\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u041c\u044b \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u043a\u043e\u0434\u00a0\u0431\u044b\u043b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 <code>torch.distributed.launch<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e\u00a0\u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>local_rank<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0430\u043c \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0433\u0434\u0435 \u043c\u044b \u0437\u0430\u0434\u0430\u0451\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0\u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <strong>\u0441\u043d\u0430\u0440\u0443\u0436\u0438<\/strong> \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0438 \u043c\u044b \u044d\u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u043f\u043e\u0437\u0436\u0435, \u0432\u00a0\u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0438\u0434\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u044f\u0441\u043d\u0438\u043c, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u00a0\u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<ul>\n<li>\n<p><code>LOCAL_RANK<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 <strong>\u0432\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430<\/strong>. \u0412\u00a0\u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 GPU, \u0442\u0430\u043a \u0447\u0442\u043e <code>LOCAL_RANK<\/code> \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 0\u00a0\u0438\u043b\u0438 1. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0447\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 GPU \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>device = torch.device(\"cuda:{}\".format(LOCAL_RANK))<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>WORLD_SIZE<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0423\u00a0\u043d\u0430\u0441 \u0434\u0432\u0430 \u0443\u0437\u043b\u0430 \u0438 \u043f\u043e\u00a0\u0434\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u043e\u043c, \u0442\u0430\u043a \u0447\u0442\u043e <code>WORLD_SIZE=4<\/code>. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>dist.init_process_group<\/code> \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0412\u00a0\u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0447\u0442\u043e\u0431\u044b <code>worker_0<\/code> \u043c\u043e\u0433 \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c \u0442\u0435\u043d\u0437\u043e\u0440 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p> <code>RANK<\/code> (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043b\u044f\u00a0\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043b\u0438 \u0432 <code>WORLD_RANK<\/code>) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 (\u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432 \u0432\u043c\u0435\u0441\u0442\u0435). \u0422\u0430\u043a \u043a\u0430\u043a <code>WORLD_SIZE<\/code> \u0443\u00a0\u043d\u0430\u0441 4, \u0442\u043e <code>RANK<\/code> (\u0438\u043b\u0438 <code>WORLD_RANK<\/code>) \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c <code>0<\/code>, <code>1<\/code>, <code>2<\/code> \u0438\u043b\u0438 <code>3<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0431\u0443\u0447\u0430\u0435\u043c ResNet<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 PyTorch, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043f\u043e\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0443\u0437\u043b\u0430\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a\u00a0\u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u043c\u0443 <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0434\u0443 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f ResNet \u043e\u0442\u00a0Lei Mao<\/a>. \u041c\u044b \u043d\u0435\u00a0\u0431\u0443\u0434\u0435\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u00a0\u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0441\u00a0\u0442\u0435\u043c, \u0447\u0442\u043e\u00a0\u043c\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u0432\u044b\u0448\u0435 \u0432\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430\u00a0\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u043e\u0447\u043a\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439.<\/p>\n<p>\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0434\u043b\u044f\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432\u00a0PyTorch.<\/p>\n<ul>\n<li>\n<p><code>torch.distributed.init_process_group(backend=\"nccl\")<\/code> <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f\u00a0ResNet<\/a>  \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u0443\u00a0\u0436\u0435 \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0435\u00a0\u0443\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0438 <code>rank<\/code> \u043d\u0438 <code>world_size<\/code>. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/pytorch.org\/docs\/stable\/distributed.html#torch.distributed.init_process_group\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 PyTorch<\/a> \u043e\u043d\u0438 \u043d\u0435\u00a0\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0438\u0437\u00a0\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>WORLD_SIZE<\/code> \u0438 <code>RANK<\/code>. \u0422\u0430\u043a \u0447\u0442\u043e\u00a0\u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b.<\/p>\n<\/li>\n<li>\n<p><code>device = torch.device(\"cuda:{}\".format(local_rank))<\/code> : \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c GPU \u0434\u043b\u044f\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0412 <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043a\u0440\u0438\u043f\u0442\u0435 ResNet<\/a> \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e\u00a0\u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441\u00a0\u043d\u0430\u0448\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e.<\/p>\n<ul>\n<li>\n<p><code>ddp_model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[local_rank], output_device=local_rank)<\/code>: \u0441\u043a\u0440\u0438\u043f\u0442 ResNet \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0443\u044e \u0432\u00a0\u043c\u0438\u0440\u0435 PyTorch \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u043d\u0430\u0434 <strong>ResNet<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043c\u043e\u0433\u043b\u0430\u00a0\u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435.<\/p>\n<\/li>\n<li>\n<p><code>train_sampler = DistributedSampler(dataset=train_set)<\/code>: \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u043d\u0430\u0434 <strong>\u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u043c<\/strong>, \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e\u00a0\u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u00a0\u044d\u0442\u043e\u043c \u0432\u0441\u0451! \u0412\u0441\u0451, \u0447\u0442\u043e\u00a0\u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u044d\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>WORLD_SIZE<\/code> \u0438 <code>WORLD_RANK<\/code>) \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c GPU (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>LOCAL_RANK<\/code>) \u0438 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0432 <code>DistributedDataParallel<\/code> \u0438 <code>DistributedSampler<\/code> \u0434\u043b\u044f\u00a0\u0440\u0430\u0431\u043e\u0442\u044b \u0432\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435.<\/p>\n<h2>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 PyTorch \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0443\u0437\u043b\u0430\u0445<\/h2>\n<p>\u041a\u00a0\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043c\u044b \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043b\u0438 \u043a\u0430\u043a\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 PyTorch \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0443\u0437\u043b\u0430\u0445. \u041e\u00a0\u0447\u0451\u043c \u043c\u044b \u043f\u043e\u043a\u0430 \u043d\u0435\u00a0\u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438, \u0442\u0430\u043a \u044d\u0442\u043e \u043e\u00a0\u0442\u043e\u043c, \u043a\u0430\u043a\u00a0\u0435\u0433\u043e <strong>\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c<\/strong>. \u041d\u043e\u00a0\u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u0448\u043b\u0430, \u0442\u0430\u043a\u0436\u0435, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u043e\u043a\u0430 \u0440\u0430\u0441\u043a\u0440\u044b\u0442\u044c \u0442\u0430\u0439\u043d\u0443, \u043a\u0430\u043a\u00a0\u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>WORLD_SIZE<\/code>, <code>WORLD_RANK<\/code> \u0438 <code>LOCAL_RANK<\/code>.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u00ab\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c\u00bb \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445, \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438, \u0432\u0440\u043e\u0434\u0435 \u0432\u0435\u0442\u0435\u0440\u0430\u043d\u043e\u0432 \u043c\u0438\u0440\u0430 HPC (Open MPI), \u0432\u0435\u0434\u0443\u0449\u0438\u043c\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u043c\u0438 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (PyTorch) \u0438\u043b\u0438\u00a0open\u2011source \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c (Horovod).<\/p>\n<p>\u0412\u00a0\u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>distributed.launch<\/code> \u0438<code>torchrun<\/code>  \u0438\u0437\u00a0PyTorch \u0438 <code>mpirun<\/code> \u0438\u0437\u00a0Open MPI. \u041c\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0437\u2011\u0437\u0430 \u0438\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u00a0\u043e\u043d\u0438 \u0438\u0437\u00a0\u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f PyTorch. \u041c\u044b \u043d\u0435\u00a0\u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c Horovod \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e\u00a0\u043e\u043d \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438 \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432\u00a0\u043d\u0430\u0448 \u043a\u043e\u0434, \u043f\u0440\u0438\u00a0\u0442\u043e\u043c \u0447\u0442\u043e\u00a0\u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0441\u0442\u0438\u0447\u044c <a href=\"https:\/\/horovod.readthedocs.io\/en\/stable\/mpi_include.html#mpirun\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u0445\u00a0\u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432<\/a>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>mpirun<\/code>\u0431\u0435\u0437\u00a0\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<h3>torch.distributed.launch<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>torch.distributed.launch<\/code> \u0434\u043b\u044f\u00a0\u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e ResNet, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0439\u0442\u0438 \u043d\u0430\u00a0\u043d\u0430\u0448\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u044b \u043f\u043e\u00a0ssh \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<\/p>\n<pre><code class=\"bash\"># On 104.171.200.62 (the master node) python3 -m torch.distributed.launch \\ --nproc_per_node=2 --nnodes=2 --node_rank=0 \\ --master_addr=104.171.200.62 --master_port=1234 \\ main.py \\ --backend=nccl --use_syn --batch_size=8192 --arch=resnet152  # On 104.171.200.182 (the worker node) python3 -m torch.distributed.launch \\ --nproc_per_node=2 --nnodes=2 --node_rank=1 \\ --master_addr=104.171.200.62 --master_port=1234 \\ main.py \\ --backend=nccl --use_syn --batch_size=8192 --arch=resnet152  # Output from node 104.171.200.62 Local Rank: 0, Epoch: 0, Training ... Local Rank: 1, Epoch: 0, Training ...  # output from node 104.171.200.182 Local Rank: 0, Epoch: 0, Training ... Local Rank: 1, Epoch: 0, Training ...<\/code><\/pre>\n<ul>\n<li>\n<p><code>nproc_per_node<\/code> \u0437\u0430\u0434\u0430\u0451\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u043e\u00a0\u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 GPU \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0437\u043b\u0435, \u0442\u043e \u0435\u0441\u0442\u044c, \u0432\u00a0\u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, 2.<\/p>\n<\/li>\n<li>\n<p><code>nnodes<\/code> \u0437\u0430\u0434\u0430\u0451\u0442 \u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0437\u043b\u043e\u0432. \u0412\u00a0\u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0442\u043e\u0436\u0435 2.<\/p>\n<\/li>\n<li>\n<p><code>master_addr<\/code> \u0438 <code>master_port<\/code> \u0437\u0430\u0434\u0430\u044e\u0442 IP \u0438 \u043f\u043e\u0440\u0442 \u043c\u0430\u0441\u0442\u0435\u0440\u2011\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u044d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0447\u0442\u043e\u0431\u044b PyTorch \u043d\u0435\u00a0\u0440\u0443\u0433\u0430\u043b\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0434\u043b\u044f\u00a0\u043e\u0431\u043e\u0438\u0445 \u043d\u0430\u0448\u0438\u0445 \u0443\u0437\u043b\u043e\u0432, \u043d\u043e <code>node_rank<\/code> \u0437\u0430\u0434\u0430\u0435\u0442 \u0440\u0430\u043d\u0433 \u0443\u0437\u043b\u0430. \u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u00a0\u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u0445. \u041d\u0430\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u2011\u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <code>0<\/code>, \u0430\u00a0\u043d\u0430\u00a0\u0432\u0442\u043e\u0440\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u00a0\u2014 <code>1<\/code>. \u0415\u0441\u043b\u0438 \u0443\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u2011\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0440\u0430\u043d\u0433 \u043d\u0435 <code>0<\/code>, \u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u0432\u0438\u0441\u043d\u0435\u0442.<\/p>\n<p>\u041d\u0435\u00a0\u0442\u0440\u0443\u0434\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e <code>torch.distributed.launch<\/code> \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>WORLD_SIZE<\/code>, <code>WORLD_RANK<\/code> \u0438 <code>LOCAL_RANK <\/code>\u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <code>nproc_per_nod<\/code>, <code>nnodes<\/code> \u0438<code>node_rank<\/code> .<\/p>\n<h3>torchrun<\/h3>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 PyTorch, <code>torchrun<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u00a0\u0438 <code>torch.distributed.launch<\/code> , \u043d\u043e\u00a0\u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 <a href=\"https:\/\/pytorch.org\/docs\/stable\/elastic\/run.html#launcher-api\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/a> \u043f\u043e\u00a0\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u0431\u043e\u0435\u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0438\u043b\u0438\u00a0\u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043d\u0430\u00a0\u043b\u0435\u0442\u0443. \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, <code>torchrun<\/code> \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0442\u0435\u043c\u0438\u00a0\u0436\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0434\u043b\u044f <code>torch.distributed.launch<\/code>:<\/p>\n<pre><code class=\"bash\"># On 104.171.200.62 (the master node) torchrun \\ --nproc_per_node=2 --nnodes=2 --node_rank=0 \\ --master_addr=104.171.200.62 --master_port=1234 \\ main.py \\ --backend=nccl --use_syn --batch_size=8192 --arch=resnet152  # On 104.171.200.182 (the worker node) torchrun \\ --nproc_per_node=2 --nnodes=2 --node_rank=1 \\ --master_addr=104.171.200.62 --master_port=1234 \\ main.py \\ --backend=nccl --use_syn --batch_size=8192 --arch=resnet152<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, <code>torchrun<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441\u00a0PyTorch 1.10. \u041d\u0443\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u00a0\u043e\u043d \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0432 <code>$PATH<\/code> \u0438\u043b\u0438\u00a0\u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u043e\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0\u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u043d\u0435\u00a0\u043d\u0430\u0439\u0434\u0435\u043d\u0430. \u041c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043b\u0438 <code>torchrun<\/code> \u0432\u00a0Lambda Cloud, \u0441\u043e\u0437\u0434\u0430\u0432 virtual environment \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e PyTorch 1.12.1:<\/p>\n<pre><code class=\"bash\">virtualenv -p \/usr\/bin\/python3.8 venv-torchrun  . venv-torchrun\/bin\/activate  pip3 install torch torchvision torchaudio --extra-index-url https:\/\/download.pytorch.org\/whl\/cu116<\/code><\/pre>\n<h3>mpirun<\/h3>\n<p>\u0425\u043e\u0442\u044f \u0441\u043f\u043e\u0441\u043e\u0431 \u0441 <code>torch.distributed.launch<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438\u0437\u00a0\u043a\u043e\u0440\u043e\u0431\u043a\u0438, \u044f\u0432\u043b\u044f\u044f\u0441\u044c \u0440\u043e\u0434\u043d\u044b\u043c \u0434\u043b\u044f\u00a0PyTorch, \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437\u00a0\u0443\u0437\u043b\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0445 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u0443\u044f. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0442\u0440\u0443\u0434\u043d\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u00a0\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u0438 \u043f\u0440\u0438\u00a0\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043b\u0435\u0433\u043a\u043e \u043e\u0448\u0438\u0431\u0438\u0442\u044c\u0441\u044f. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u0433\u043e\u00a0\u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 <code>mpirun<\/code> \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043d\u0430\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u2011\u0441\u0435\u0440\u0432\u0435\u0440\u0435,<\/p>\n<p>MPI, \u0438\u043b\u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Message_Passing_Interface\" rel=\"noopener noreferrer nofollow\">Message Passing Interface<\/a>, \u044d\u0442\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u043c\u0443 \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430\u0445. \u0412\u00a0\u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u00a0PyTorch, \u00ab\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u00bb \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u0430\u0436\u0434\u044b\u043c GPU, \u0430\u00a0\u043e\u0431\u043c\u0435\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0441\u0431\u043e\u0440 \u044d\u0442\u0438\u0445 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0441\u043e \u0432\u0441\u0435\u0445 GPU \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0435\u0441\u043e\u0432 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442 MPI\u00a0\u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0432\u00a0\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u0434\u0435\u0432\u044f\u043d\u043e\u0441\u0442\u044b\u0445 \u0438 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u00a0\u0431\u044b\u043b \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f\u00a0\u0432\u044b\u0441\u043e\u043a\u043e\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437\u00a0\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043e\u0432 (\u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u0447\u0438\u0442\u0430\u044e\u0449\u0438\u0445 \u043d\u0430\u00a0CPU). \u041d\u043e\u00a0\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0432\u00a0CUDA \u0438 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044e GPU\u2011\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0441\u0442\u0430\u043b\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <a href=\"https:\/\/github.com\/NVIDIA\/nccl\" rel=\"noopener noreferrer nofollow\">NCCL<\/a> (<a href=\"https:\/\/github.com\/NVIDIA\/nccl\" rel=\"noopener noreferrer nofollow\">NVIDIA Collective Communication Library<\/a>), \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0435 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c\u00a0\u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 GPU, \u0432\u00a0\u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441\u00a0\u0443\u0447\u0451\u0442\u043e\u043c \u0442\u043e\u043f\u043e\u043b\u043e\u0433\u0438\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0432\u0440\u043e\u0434\u0435 RMDA \u043f\u043e\u0432\u0435\u0440\u0445 RoCE \u0438\u043b\u0438\u00a0InfiniBand). \u041d\u0430\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, NCCL \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u043b\u0435\u0433\u043a\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432\u00a0\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 MPI. \u0412\u00a0\u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 MPI \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u00ab\u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u043e\u043c\u00bb, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0437\u0430\u00a0\u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u0430\u00a0NCCL \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u00ab\u0431\u0435\u043a\u0435\u043d\u0434\u043e\u043c\u00bb, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044e.<\/p>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 MPI\u00a0\u2014 <a href=\"https:\/\/www.open-mpi.org\/\" rel=\"noopener noreferrer nofollow\">OpenMPI<\/a> \u0438 <a href=\"https:\/\/www.mpich.org\/\" rel=\"noopener noreferrer nofollow\">MPICH<\/a>. \u041d\u0430\u043c \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u043b\u044e\u0431\u0430\u044f, \u043d\u043e\u00a0\u0432\u00a0\u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c OpenMPI. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c <a href=\"https:\/\/www.open-mpi.org\/faq\/?category=building\" rel=\"noopener noreferrer nofollow\">OpenMPI<\/a> \u0438 <a href=\"https:\/\/docs.nvidia.com\/deeplearning\/nccl\/install-guide\/index.html\" rel=\"noopener noreferrer nofollow\">NCCL<\/a>. \u041d\u043e\u00a0\u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Lambda Cloud, \u0442\u043e \u044d\u0442\u0430\u043f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a\u00a0\u043e\u0431\u0430 \u044d\u0442\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 <a href=\"https:\/\/lambdalabs.com\/lambda-stack-deep-learning-software\" rel=\"noopener noreferrer nofollow\">Lambda stack<\/a>.<\/p>\n<p>\u0418\u0442\u0430\u043a, \u0432\u043e\u0442 \u043a\u0430\u043a\u00a0\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0430\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>mpirun<\/code>, \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0439 \u043d\u0430\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u2011\u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<pre><code class=\"bash\"># On 104.171.200.62 (the master node) mpirun -np 4 \\ -H 104.171.200.62:2,104.171.200.182:2 \\ -x MASTER_ADDR=104.171.200.62 \\ -x MASTER_PORT=1234 \\ -x PATH \\ -bind-to none -map-by slot \\ -mca pml ob1 -mca btl ^openib \\ python3 main.py --backend=nccl --use_syn --batch_size=8192 --arch=resnet152   # Output on 104.171.200.62 Local Rank: 0, Epoch: 0, Training ... Local Rank: 1, Epoch: 0, Training ... Local Rank: 0, Epoch: 0, Training ... Local Rank: 1, Epoch: 0, Training ... Local Rank: 1, Epoch: 1, Training ... Local Rank: 0, Epoch: 1, Training ... Local Rank: 0, Epoch: 1, Training ... Local Rank: 1, Epoch: 1, Training ... num_steps_per_gpu: 19, avg_step_time: 1.4266 Local Rank: 1, Epoch: 2, Training ... num_steps_per_gpu: 19, avg_step_time: 1.4266 Local Rank: 0, Epoch: 2, Training ... num_steps_per_gpu: 19, avg_step_time: 1.4266 Local Rank: 0, Epoch: 2, Training ... num_steps_per_gpu: 19, avg_step_time: 1.4266<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u043a\u0430\u043a\u00a0\u0438\u043c\u0435\u043d\u043d\u043e \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>mpirun<\/code>.<\/p>\n<ul>\n<li>\n<p><code>np<\/code>: \u0437\u0430\u0434\u0430\u0451\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 (\u0442\u043e, \u0447\u0442\u043e\u00a0\u0440\u0430\u043d\u044c\u0448\u0435\u00a0\u0431\u044b\u043b\u043e <code>WORLD_SIZE<\/code>).<\/p>\n<\/li>\n<li>\n<p><code>H<\/code>: \u0437\u0430\u0434\u0430\u0451\u0442 IP \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0434\u043b\u044f\u00a0\u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0415\u0441\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u043b\u0438\u043a, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/www.open-mpi.org\/faq\/?category=running#mpirun-hostfile\" rel=\"noopener noreferrer nofollow\">hostfile<\/a>.<\/p>\n<\/li>\n<li>\n<p><code>-bind-to none<\/code>: \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e\u00a0OpenMPI \u043d\u0435\u00a0\u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 CPU (\u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u0440\u0435\u0434\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p><code>-map-by ob1 -mca btl ^openib<\/code>: \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f\u00a0\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 TCP, \u0432\u043c\u0435\u0441\u0442\u043e RDMA, \u0441\u00a0\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0443\u00a0OpenMPI \u0435\u0441\u0442\u044c \u0440\u044f\u0434 \u043f\u0440\u043e\u0431\u043b\u0435\u043c, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0438\u0445, \u043e\u0431\u044b\u0447\u043d\u043e \u043a\u00a0segfault.<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u0442\u044c \u0435\u0449\u0451 \u043f\u0430\u0440\u0430 \u0432\u0435\u0449\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>mpirun<\/code> \u0441\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438.<\/p>\n<ul>\n<li>\n<p>\u041c\u0430\u0441\u0442\u0435\u0440\u2011\u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u00a0\u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0439 \u043f\u0430\u0440\u043e\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e \u0432\u0441\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c. \u0414\u043b\u044f\u00a0\u044d\u0442\u043e\u0433\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <code>ssh-keygen<\/code> \u043d\u0430\u00a0\u043c\u0430\u0441\u0442\u0435\u0440\u2011\u0441\u0435\u0440\u0432\u0435\u0440\u0435, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 <code>~\/.ssh\/authorized_keys<\/code> \u043d\u0430\u00a0\u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b (\u0438\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <code>ssh-copy-id -i master-public-key username@worker-ip<\/code> \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0441\u00a0\u043f\u0430\u0440\u043e\u043b\u0435\u043c).<\/p>\n<\/li>\n<li>\n<p>\u0422\u0430\u043a\u0436\u0435, \u043a\u0430\u043a\u00a0\u0438 <code>torch.distributed.launch<\/code>, <code>mpirun<\/code> \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0430\u0432\u0434\u0430, \u043f\u043e\u0434\u00a0\u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438:<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"bash\">LOCAL_RANK = int(os.environ['OMPI_COMM_WORLD_LOCAL_RANK']) WORLD_SIZE = int(os.environ['OMPI_COMM_WORLD_SIZE']) WORLD_RANK = int(os.environ['OMPI_COMM_WORLD_RANK'])<\/code><\/pre>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442\u00a0\u0436\u0435 \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u043a\u0430\u043a\u00a0\u043f\u0440\u0438\u00a0\u043f\u043e\u043c\u043e\u0449\u0438 <code>torch.distributed.launch<\/code> \u0442\u0430\u043a \u0438 <code>mpirun<\/code> , \u043f\u0440\u0438\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0447\u0442\u043e\u00a0\u043e\u043d \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<h2>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432 Lambda Cloud<\/h2>\n<p>\u041f\u0440\u0438\u00a0\u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435 \u0432\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u00a0\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0\u0441\u0435\u043a\u0443\u043d\u0434\u0443) \u0434\u043e\u043b\u0436\u043d\u0430 \u0440\u0430\u0441\u0442\u0438\u00a0\u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0441\u00a0\u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 GPU. \u041d\u0430\u00a0\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u043d\u0435\u00a0\u0442\u0430\u043a \u0438\u0437\u2011\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u00a0\u0443\u0437\u043a\u0438\u043c \u043c\u0435\u0441\u0442\u043e\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 GPU.<\/p>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 \u0432\u00a0Lambda Cloud, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u00a0\u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0434\u043e 100Gbps \u043f\u0440\u0438\u00a0\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438. \u0412\u00a0\u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043e\u0442\u00a0\u0440\u043e\u0441\u0442\u0430 \u0447\u0438\u0441\u043b\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432, \u043e\u0431\u0443\u0447\u0430\u044f <code>ResNet152<\/code> \u043d\u0430 <code>CIFAR10<\/code>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/773\/7d4\/88d\/7737d488da48bcd3e98c6250af1fd616.png\" alt=\"\u041f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439\/\u0441\u0435\u043a.\" title=\"\u041f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439\/\u0441\u0435\u043a.\" width=\"1882\" height=\"424\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/773\/7d4\/88d\/7737d488da48bcd3e98c6250af1fd616.png\"\/><\/p>\n<div><figcaption>\u041f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439\/\u0441\u0435\u043a.<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f\u00a0\u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u0432\u044b\u0448\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0430 \u043a\u0430\u043a\u00a0\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0431\u0430\u0442\u0447\u0430 (<code>8192 x 4 = 32768<\/code>) \u043a\u00a0\u0441\u0440\u0435\u0434\u043d\u0435\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 (1.4266\u00a0\u0441\u0435\u043a\u0443\u043d\u0434\u044b \u0434\u043b\u044f 2-\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043d\u0430 2-\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445). \u0421\u0438\u043d\u0438\u0439 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0433\u0440\u0430\u0444\u0438\u043a\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u0430\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u00a0\u043b\u0438\u043d\u0435\u0439\u043d\u043e \u043f\u0440\u0438\u00a0\u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u0447\u0438\u0441\u043b\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0441 1\u00a0\u0434\u043e 4-\u0445. \u0421\u0432\u0435\u0442\u043b\u043e\u2011\u0441\u0438\u043d\u0438\u0439 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0432\u00a0\u043f\u0440\u0430\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043d\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c\u044e, \u043a\u0430\u043a\u00a0\u0435\u0441\u043b\u0438\u00a0\u0431\u044b \u044d\u0444\u0444\u0435\u043a\u0442 \u043e\u0442\u00a0\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u00a0\u0431\u044b\u043b \u0438\u0434\u0435\u0430\u043b\u0435\u043d. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e\u00a0\u0442\u0430\u043a\u043e\u0439 \u044d\u0444\u0444\u0435\u043a\u0442\u00a0\u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043f\u0440\u0438\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0430\u0442\u0447\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (8192\u00a0\u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u00a0\u043e\u0434\u043d\u0438 GPU), \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 (ResNet152) \u0438 \u0432\u0441\u0435\u0433\u043e \u0434\u0432\u0443\u0445 \u0443\u0437\u043b\u043e\u0432. \u0411\u0430\u0442\u0447\u0438 \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u043b\u0438\u00a0\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0443\u0437\u043b\u043e\u0432 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u00a0\u0431\u044b \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 GPU, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u0421\u0435\u0440\u0432\u0435\u0440\u044b Lambda Cloud Reserved \u0438\u043b\u0438\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440 Lambda Echelon (\u0438 \u0442\u043e \u0438 \u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e 1600\u00a0Gbps) \u043c\u043e\u0433\u0443\u0442\u00a0\u0431\u044b\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0434\u043b\u044f\u00a0\u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0434\u0430\u0451\u0442 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u00ab\u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c\u00bb \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 PyTorch \u043f\u0440\u0438\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0437\u043b\u043e\u0432 \u0438 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0438 \u043a\u0430\u043a\u00a0\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u00a0PyTorch.<\/p>\n<p>\u041a\u043e\u0434 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 <a href=\"https:\/\/github.com\/LambdaLabsML\/examples\/tree\/main\/pytorch\/distributed\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/a>.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/753276\/\"> https:\/\/habr.com\/ru\/articles\/753276\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p><em>\u0413\u043b\u0443\u0431\u043e\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0432\u0441\u0451 \u0440\u0435\u0436\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432.<\/em><\/p>\n<p><em>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0445\u0430\u0431\u0440\u0430\u0441\u0441\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u0441\u0442\u0430 \u0438\u0437 \u0431\u043b\u043e\u0433\u0430 <\/em><a href=\"https:\/\/lambdalabs.com\/\" rel=\"noopener noreferrer nofollow\"><em>LambdaLabs<\/em><\/a><em>, \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0435\u0439\u0441\u044f \u043d\u0430 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0434\u043b\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u041e\u043d \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 PyTorch \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u0430\u0445.<\/em><\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/64d25f7b120b821486c9879e\" data-style=\"\" id=\"64d25f7b120b821486c9879e\" width=\"\"><\/div>\n<p><a href=\"https:\/\/pytorch.org\/\" rel=\"noopener noreferrer nofollow\">PyTorch <\/a>\u0437\u0430\u0434\u0443\u043c\u0430\u043d \u043a\u0430\u043a\u00a0\u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u043d \u0434\u0430\u0436\u0435 \u0432\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u0430\u0434\u0430\u0447. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043d \u0441\u0442\u0430\u043b <a href=\"https:\/\/paperswithcode.com\/trends\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u043c\u044b\u043c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0434\u043b\u044f\u00a0\u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/a> \u0441\u0440\u0435\u0434\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0434\u0430\u043b\u0435\u043a\u043e \u043f\u043e\u0437\u0430\u0434\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0437\u0430\u00a0\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/pytorch.org\/tutorials\/beginner\/dist_overview.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432<\/a> \u0438 <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u00a0\u0431\u043b\u043e\u0433\u0430\u0445<\/a>, \u043d\u0435\u00a0\u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e\u00a0\u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c PyTorch \u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <strong>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0443\u0437\u043b\u043e\u0432<\/strong>.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0446\u0435\u043b\u044c \u044d\u0442\u043e\u0433\u043e \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043a\u0440\u0430\u0442\u043a\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u00a0\u0432\u00a0PyTorch <strong>\u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c<\/strong> \u0438 <strong>\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c<\/strong> \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u044b \u0438\u0441\u0445\u043e\u0434\u0438\u043c \u0438\u0437\u00a0\u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u00a0\u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0438\u043c\u0435\u0435\u0442 \u043e\u043f\u044b\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f PyTorch \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439, \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e <a href=\"https:\/\/pytorch.org\/tutorials\/intermediate\/ddp_tutorial.html\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/a> \u0438 \u0445\u043e\u0447\u0435\u0442\u00a0\u0431\u044b\u0441\u0442\u0440\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u0435\u043b \u043c\u0435\u0436\u0434\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u0437\u0430\u0434\u0430\u0447 \u043d\u0430\u00a0\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0438\u0445 \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445. \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437\u00a0\u044d\u0442\u043e\u0433\u043e, \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430:<\/p>\n<ul>\n<li>\n<p>\u043e\u0431\u0449\u0438\u0445 \u0438\u0434\u0435\u044f\u0445 \u043e\u00a0\u0442\u043e\u043c, \u043a\u0430\u043a\u00a0\u043f\u043e\u0434\u00a0\u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u00a0PyTorch;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432\u00a0\u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0442\u043e\u043c, \u043a\u0430\u043a\u00a0\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>torch.distributed.launch<\/code>, <code>torchrun<\/code> \u0438<code>mpirun<\/code> .<\/p>\n<\/li>\n<\/ul>\n<h2>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c \u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e PyTorch<\/h2>\n<p>\u0418\u0434\u0435\u044f, \u043b\u0435\u0436\u0430\u0449\u0430\u044f \u0432\u00a0\u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e PyTorch, \u043f\u0440\u043e\u0441\u0442\u043e\u00a0\u2014 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u0421\u0443\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u0442\u0430\u00a0\u0436\u0435 \u0441\u0430\u043c\u0430\u044f, \u043a\u0430\u043a\u00a0\u0443\u00a0MPI, \u0442\u043e \u0435\u0441\u0442\u044c, \u0447\u0442\u043e\u2011\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>mpirun -n 3 echo hello world<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0442\u0440\u0438\u0436\u0434\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u00a0\u0432\u044b\u0432\u043e\u0434\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u00abhello world\u00bb:<\/p>\n<pre><code class=\"bash\">ubuntu@ubuntu-desktop:~$ mpirun -n 3 echo hello world hello world hello world hello world<\/code><\/pre>\n<p>\u041d\u043e\u00a0\u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432\u00a0PyTorch \u043e\u0442\u00a0\u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441 <code>mpirun<\/code>.<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u00a0\u0430\u043f\u043f\u0430\u0440\u0430\u0442\u043d\u043e\u043c\u0443 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u0435\u043b\u044e (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, GPU), \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c <strong>\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439<\/strong> \u043f\u0440\u0438\u00a0\u043f\u0440\u044f\u043c\u043e\u043c \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0435 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c <strong>\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u044e<\/strong> \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u00a0\u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0448\u0430\u0433\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e\u00a0\u0431\u044b\u043b\u043e \u0430\u043a\u043a\u0443\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u0432 \u0438 \u0437\u0430\u0442\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f\u00a0\u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f\u00a0\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 PyTorch \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u044b \u043a\u00a0\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u00bb (<code>torch.distributed.init_process_group<\/code>), \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0438\u0445 \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0\u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>nccl<\/code>), \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0432\u0430\u0448 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u043c\u043e\u0433\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0440\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 (\u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>torch.utils.data.distributed.DistributedSampler<\/code> \u0438 <code>torch.nn.parallel.DistributedDataParallel<\/code>).<\/p>\n<p>\u0415\u0449\u0451 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0451 \u0432\u043e\u0435\u0434\u0438\u043d\u043e: <code>WORLD_SIZE<\/code>, <code>WORLD_RANK<\/code> \u0438 <code>LOCAL_RANK<\/code> . \u0418\u0445 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0434\u043b\u044f\u00a0\u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0439 \u043a\u0430\u043a \u00ab\u043e\u0431\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e GPU \u0432\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435\u00bb, \u00ab\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 GPU\u00bb \u0438 \u00ab\u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043b\u044f\u00a0\u0443\u0437\u043b\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 GPU\u00bb. \u041a\u0430\u043a\u00a0\u0432\u044b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c, \u043e\u043d\u0438 \u0441\u043b\u0443\u0436\u0430\u0442 \u0434\u043b\u044f\u00a0\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0430\u00a0\u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0436\u0438\u0437\u043d\u0438 \u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e.<\/p>\n<h2>\u041f\u0438\u0448\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u00a0PyTorch<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u00a0\u0440\u044f\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 PyTorch, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0437\u043b\u043e\u0432. \u041d\u0430\u0447\u043d\u0451\u043c \u0441\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u00a0PyTorch Distributed Data Parallel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043d\u0430\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0443\u0437\u043b\u0430\u0445. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u043c, \u043a\u0430\u043a\u00a0\u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u044b\u0442 \u043d\u0430\u00a0\u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 ResNet.<\/p>\n<p>\u0412\u00a0\u0446\u0435\u043b\u044f\u0445 \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <code>2xA600<\/code> \u0432\u00a0Lambda Cloud. \u041d\u043e\u00a0\u0442\u0435\u00a0\u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 \u0434\u043b\u044f\u00a0on\u2011prem \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0441\u00a0\u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u0434\u0432\u0443\u043c\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f\u00a0\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 <a href=\"https:\/\/lambdalabs.com\/gpu-cluster\/echelon\" rel=\"noopener noreferrer nofollow\">Lambda Echelon<\/a>.<\/p>\n<p>\u042d\u0442\u0438 \u0434\u0432\u0430 \u0443\u0437\u043b\u0430 <code>2xA600<\/code> (\u0441 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 <code>104.171.200.62<\/code> \u0438 <code>104.171.200.182<\/code>) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c 4\u00a0\u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 (\u043f\u043e 2\u00a0\u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b).<\/p>\n<h3>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u0435\u0442 \u0442\u0435\u043d\u0437\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438. \u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430\u00a0\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c <a href=\"https:\/\/pytorch.org\/tutorials\/intermediate\/dist_tuto.html\" rel=\"noopener noreferrer nofollow\">\u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0435<\/a> \u043f\u043e\u00a0PyTorch, \u043d\u043e\u00a0\u043c\u044b \u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b\u0438 (\u0447\u0442\u043e\u0431\u044b \u043d\u0430\u043c \u043d\u0435\u00a0\u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u0441\u044f \u043e\u00a0\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043d\u043e\u0433\u043e\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043d\u043e\u0441\u0442\u0438 \u0432\u00a0PyTorch) \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438, \u0430\u00a0\u043d\u0435\u00a0\u0432\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e (\u0432\u0435\u0434\u044c \u0432\u00a0\u044d\u0442\u043e\u043c\u2011\u0442\u043e \u0432\u0441\u044f \u0441\u0443\u0442\u044c, \u0442\u0430\u043a \u0432\u0435\u0434\u044c?).<\/p>\n<pre><code class=\"python\">import os import argparse  import torch import torch.distributed as dist  # Environment variables set by torch.distributed.launch LOCAL_RANK = int(os.environ['LOCAL_RANK']) WORLD_SIZE = int(os.environ['WORLD_SIZE']) WORLD_RANK = int(os.environ['RANK'])  def run(backend):     tensor = torch.zeros(1)          # Need to put tensor on a GPU device for nccl backend     if backend == 'nccl':         device = torch.device(\"cuda:{}\".format(LOCAL_RANK))         tensor = tensor.to(device)      if WORLD_RANK == 0:         for rank_recv in range(1, WORLD_SIZE):             dist.send(tensor=tensor, dst=rank_recv)             print('worker_{} sent data to Rank {}\\n'.format(0, rank_recv))     else:         dist.recv(tensor=tensor, src=0)         print('worker_{} has received data from rank {}\\n'.format(WORLD_RANK, 0))  def init_processes(backend):     dist.init_process_group(backend, rank=WORLD_RANK, world_size=WORLD_SIZE)     run(backend)  if __name__ == \"__main__\":      parser = argparse.ArgumentParser()     parser.add_argument(\"--local_rank\", type=int, help=\"Local rank. Necessary for using the torch.distributed.launch utility.\")     parser.add_argument(\"--backend\", type=str, default=\"nccl\", choices=['nccl', 'gloo'])     args = parser.parse_args()      init_processes(backend=args.backend)<\/code><\/pre>\n<p>\u041a\u043e\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 4\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 <code>worker_0<\/code> \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0442\u0435\u043d\u0437\u043e\u0440 \u043d\u0430\u00a0GPU 0\u00a0\u0443\u0437\u043b\u0430 104.171.200.62, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0441\u044b\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u043c\u0441\u044f \u0442\u0440\u0451\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c. \u041a\u0430\u043a\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0442\u0435\u043d\u0437\u043e\u0440, \u043e\u043d \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"bash\"># output from node 104.171.200.62 worker_0 sent data to Rank 1 worker_0 sent data to Rank 2 worker_0 sent data to Rank 3 worker_1 has received data from rank 0  # output from node 104.171.200.182 worker_2 has received data from rank 0 worker_3 has received data from rank 0<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435, \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u00a0\u044d\u0442\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>dist.init_process_group(backend, rank=WORLD_RANK, world_size=WORLD_SIZE)<\/code>. \u041a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d \u043a\u0430\u043a <code>worker_$WORLD_RANK<\/code> , \u0432\u0441\u0435\u0433\u043e \u0432\u00a0\u0433\u0440\u0443\u043f\u043f\u0435 \u0431\u0443\u0434\u0435\u0442 <code>$WORLD_SIZE<\/code> \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u00a0\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>run<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e <code>WORLD_RANK<\/code> \u0438 <code>WORLD_SIZE<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u00a0\u0432\u044b\u0437\u043e\u0432\u0435 <code>dist.init_process_group<\/code> \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 \u0447\u0442\u043e <code>LOCAL_RANK<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u00a0\u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>run<\/code> \u0447\u0442\u043e\u0431\u044b \u0430\u0441\u0441\u043e\u0446\u0438\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 GPU. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u043c\u043e\u0436\u043d\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u043e\u0442\u00a0\u0442\u043e\u0433\u043e, \u043d\u0430\u00a0\u043a\u0430\u043a\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u0442\u043e \u0447\u0442\u043e\u00a0\u0438\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f GPU. <\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>backend<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 (nccl, gloo \u0438\u00a0\u0442.\u00a0\u043f.) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f\u00a0\u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438. PyTorch \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u043d\u043e\u00a0\u0432\u044b\u043d\u0443\u0436\u0434\u0435\u043d \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u00a0\u044d\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f\u00a0\u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043c\u0435\u0442\u0438\u043c \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>local_rank<\/code> \u0432\u00a0\u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u043a\u0430\u043a \u043d\u0435\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f. \u041c\u044b \u0435\u0433\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u043a\u043e\u0434\u00a0\u0431\u044b\u043b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 <code>torch.distributed.launch<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e\u00a0\u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>local_rank<\/code>.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0430\u043c \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0433\u0434\u0435 \u043c\u044b \u0437\u0430\u0434\u0430\u0451\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f\u00a0\u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 <strong>\u0441\u043d\u0430\u0440\u0443\u0436\u0438<\/strong> \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0438 \u043c\u044b \u044d\u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u043f\u043e\u0437\u0436\u0435, \u0432\u00a0\u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043f\u043e\u0441\u0432\u044f\u0449\u0451\u043d\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0438\u0434\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u044f\u0441\u043d\u0438\u043c, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u00a0\u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<ul>\n<li>\n<p><code>LOCAL_RANK<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 <strong>\u0432\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u0437\u043b\u0430<\/strong>. \u0412\u00a0\u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0443\u0437\u0435\u043b \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 GPU, \u0442\u0430\u043a \u0447\u0442\u043e <code>LOCAL_RANK<\/code> \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 0\u00a0\u0438\u043b\u0438 1. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0447\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 GPU \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>device = torch.device(\"cuda:{}\".format(LOCAL_RANK))<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>WORLD_SIZE<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0423\u00a0\u043d\u0430\u0441 \u0434\u0432\u0430 \u0443\u0437\u043b\u0430 \u0438 \u043f\u043e\u00a0\u0434\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043d\u0430\u00a0\u043a\u0430\u0436\u0434\u043e\u043c, \u0442\u0430\u043a \u0447\u0442\u043e <code>WORLD_SIZE=4<\/code>. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>dist.init_process_group<\/code> \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0412\u00a0\u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0447\u0442\u043e\u0431\u044b <code>worker_0<\/code> \u043c\u043e\u0433 \u0440\u0430\u0437\u043e\u0441\u043b\u0430\u0442\u044c \u0442\u0435\u043d\u0437\u043e\u0440 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p> <code>RANK<\/code> (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043b\u044f\u00a0\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043b\u0438 \u0432 <code>WORLD_RANK<\/code>) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432\u00a0\u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 (\u0432\u0441\u0435\u0445 \u0443\u0437\u043b\u043e\u0432 \u0432\u043c\u0435\u0441\u0442\u0435). \u0422\u0430\u043a \u043a\u0430\u043a <code>WORLD_SIZE<\/code> \u0443\u00a0\u043d\u0430\u0441 4, \u0442\u043e <code>RANK<\/code> (\u0438\u043b\u0438 <code>WORLD_RANK<\/code>) \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c <code>0<\/code>, <code>1<\/code>, <code>2<\/code> \u0438\u043b\u0438 <code>3<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3>\u041e\u0431\u0443\u0447\u0430\u0435\u043c ResNet<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 PyTorch, \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043f\u043e\u00a0\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0443\u0437\u043b\u0430\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a\u00a0\u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u043c\u0443 <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u0434\u0443 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f ResNet \u043e\u0442\u00a0Lei Mao<\/a>. \u041c\u044b \u043d\u0435\u00a0\u0431\u0443\u0434\u0435\u043c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u00a0\u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0441\u00a0\u0442\u0435\u043c, \u0447\u0442\u043e\u00a0\u043c\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438 \u0432\u044b\u0448\u0435 \u0432\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430\u00a0\u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u043e\u0447\u043a\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439.<\/p>\n<p>\u0420\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0434\u043b\u044f\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432\u00a0PyTorch.<\/p>\n<ul>\n<li>\n<p><code>torch.distributed.init_process_group(backend=\"nccl\")<\/code> <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f\u00a0ResNet<\/a>  \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u0443\u00a0\u0436\u0435 \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f\u00a0\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0435\u00a0\u0443\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0438 <code>rank<\/code> \u043d\u0438 <code>world_size<\/code>. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e <a href=\"https:\/\/pytorch.org\/docs\/stable\/distributed.html#torch.distributed.init_process_group\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 PyTorch<\/a> \u043e\u043d\u0438 \u043d\u0435\u00a0\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0438\u0437\u00a0\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>WORLD_SIZE<\/code> \u0438 <code>RANK<\/code>. \u0422\u0430\u043a \u0447\u0442\u043e\u00a0\u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u044b.<\/p>\n<\/li>\n<li>\n<p><code>device = torch.device(\"cuda:{}\".format(local_rank))<\/code> : \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0431\u0440\u0430\u0442\u044c GPU \u0434\u043b\u044f\u00a0\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u0412 <a href=\"https:\/\/leimao.github.io\/blog\/PyTorch-Distributed-Training\/\" rel=\"noopener noreferrer nofollow\">\u0441\u043a\u0440\u0438\u043f\u0442\u0435 ResNet<\/a> \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e\u00a0\u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441\u00a0\u043d\u0430\u0448\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0448\u0430\u0433\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e.<\/p>\n<ul>\n<li>\n<p><code>ddp_model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[local_rank], output_device=local_rank)<\/code>: \u0441\u043a\u0440\u0438\u043f\u0442 ResNet \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0443\u044e \u0432\u00a0\u043c\u0438\u0440\u0435 PyTorch \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u043d\u0430\u0434 <strong>ResNet<\/strong>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043c\u043e\u0433\u043b\u0430\u00a0\u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u00a0\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435.<\/p>\n<\/li>\n<li>\n<p><code>train_sampler =<\/code><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-351591","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=351591"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351591\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}