{"id":379850,"date":"2024-06-25T09:00:38","date_gmt":"2024-06-25T09:00:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=379850"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=379850","title":{"rendered":"<span>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439<\/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<p><strong>Multi gpu training overview<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 VRAM, \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c\u0438 (\u0438\u043b\u0438 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c\u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c) \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c.<br \/> \u041d\u0438\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043f\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 GPU \u0438\u043b\u0438 \u043d\u043e\u0434\u0430\u043c\u0438.<\/p>\n<p><strong>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c 3 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f<\/strong><\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438, \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0432\u043b\u0435\u0437\u0430\u044e\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0439 GPU<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438, \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0432\u043b\u0435\u0437\u0430\u044e\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0439 GPU<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0441\u043b\u043e\u0439 (\u0442\u0435\u043d\u0437\u043e\u0440), \u0432\u044b\u0445\u043e\u0434\u043d\u0430\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0441 \u043d\u0435\u0433\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u0432\u043b\u0435\u0437\u0430\u0435\u0442 \u0432 \u0441\u0430\u043c\u0443\u044e \u0431\u043e\u043b\u044c\u0448\u0443\u044e GPU<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0431\u0430\u0442\u0447 \u0441\u0430\u0439\u0437, \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0435\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c<br \/> \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 gpu \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e, \u0432\u0435\u0434\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043d\u0435 \u0432\u043b\u0435\u0437\u0430\u0435\u0442 \u0432 \u043e\u0434\u043d\u0443 GPU<\/p>\n<p><strong>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439\u00a01.<\/strong><\/p>\n<ul>\n<li>\n<p>DP<\/p>\n<\/li>\n<li>\n<p>DDP<\/p>\n<\/li>\n<li>\n<p>ZeRO<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439\u00a02.<\/strong><\/p>\n<ul>\n<li>\n<p>Pipeline Parallel<\/p>\n<\/li>\n<li>\n<p>Tensor Parallel<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439\u00a03.<\/strong><\/p>\n<ul>\n<li>\n<p>Tensor parallel<\/p>\n<\/li>\n<\/ul>\n<h2>\u0418\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/h2>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432 \u0442\u043e\u0440\u0447 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 (gpu \u0438\u043b\u0438 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430). \u0422\u0430\u043a \u043a\u0430\u043a, \u043a\u0430\u043a \u044f \u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043d\u0438\u043c\u0438 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0430, \u0434\u0443\u043c\u0430\u044e \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e <s>\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f<\/s> \u043f\u0440\u0438\u0432\u044b\u043a\u0430\u043d\u0438\u044f \u043a \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u0442\u043e\u0440\u0447\u0430<\/p>\n<p><em>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 (\u043d\u043e\u0434\u0430\u043c\u0438)<\/em><\/p>\n<pre><code class=\"python\">import torch   import torch.distributed as dist      dist.init_process_group(backend=\"gloo\", # CPU only backend # https:\/\/pytorch.org\/docs\/stable\/distributed.html init_method=\"tcp:\/\/node1_ip:8551\",  rank=0, # \u043d\u043e\u043c\u0435\u0440 \u043d\u043e\u0434\u044b world_size=2) # \u0447\u0438\u0441\u043b\u043e \u043d\u043e\u0434  t = torch.tensor([1.0]*10) dist.send(tensor=t,            dst=1) # \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 1 \u043d\u043e\u0434\u0443   # ------ second node -------- dist.init_process_group(backend=\"gloo\", # https:\/\/pytorch.org\/docs\/stable\/distributed.html init_method=\"tcp:\/\/node1_ip:8551\",  rank=1, world_size=2) tensor = torch.tensor([0.0]*10)   dist.recv(tensor=tensor, src=0)   print(f'rank 1 received tensor {tensor} from rank 0') <\/code><\/pre>\n<h2>DP &amp; DDP<\/h2>\n<p><a href=\"https:\/\/pytorch.org\/docs\/stable\/distributed.html#module-torch.distributed.tensor.parallel.ddp\" rel=\"noopener noreferrer nofollow\">\u041e\u0432\u0435\u0440\u0432\u044c\u044e \u0432 \u0434\u043e\u043a\u0435 \u0442\u043e\u0440\u0447\u0430<\/a>  <a href=\"https:\/\/github.com\/pytorch\/examples\/blob\/main\/distributed\/ddp-tutorial-series\/multinode.py\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/a> <a href=\"https:\/\/lightning.ai\/docs\/pytorch\/stable\/clouds\/cluster_intermediate_1.html\" rel=\"noopener noreferrer nofollow\">DDP \u0432 3 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0434\u043b\u044f lightning<\/a><\/p>\n<p>DataParallel \u0438 DistributedDataParallel \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0441\u043f\u0438\u0448\u0435\u043c \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u0435\u043f<\/p>\n<p><strong>DDP:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0439 \u043c\u0438\u043d\u0438\u0431\u0430\u0442\u0447 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u0435\u0441\u0430\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043d\u044b, \u0432\u0441\u0435 \u043d\u043e\u0434\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u044e\u0442 \u0438\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0437\u0430\u0442\u0435\u043c \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u044e\u0442<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0438 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0447\u0435\u043c\u0443 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0435 \u0440\u0430\u0437\u0431\u0435\u0433\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<p><strong>DP:<\/strong><\/p>\n<ul>\n<li>\n<p>GPU 0 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0431\u0430\u0442\u0447 \u0438 \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0438\u043d\u0438\u0431\u0430\u0442\u0447 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 GPU.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 GPU 0 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 GPU.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0434\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 forward \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 y \u043d\u0430 GPU0 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0441\u0441 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0442 GPU 0 \u043a\u043e \u0432\u0441\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c, \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 backward<\/p>\n<\/li>\n<li>\n<p>\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0441 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 GPU 0 \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b<br \/> <strong>+<\/strong><\/p>\n<ul>\n<li>\n<p>DDP \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432 5 \u0440\u0430\u0437 \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u0431\u043c\u0435\u043d\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u043e\u043d \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432\u0441\u0435 \u0433\u043f\u0443 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a DP \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u0442 GPU:0 <\/p>\n<\/li>\n<\/ul>\n<p><strong>&#8212;<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0449\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e, \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440 \u043d\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u0449\u0430\u0435\u0442\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e DDP \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442 \u043e\u0442 \u043d\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 (?)<\/p>\n<\/li>\n<li>\n<p>DP \u043f\u043e \u0447\u0435\u0441\u0442\u043d\u043e\u043c\u0443 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u0431\u0430\u0442\u0447\u0443 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0433\u043f\u0443, \u0430 DDP \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0438\u043d\u0438 \u0431\u0430\u0442\u0447\u0430. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0435\u0439\u0441\u0430\u0445, \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u043a\u043e\u0433\u0434\u0430 \u043b\u043e\u0441\u0441 \u043f\u043e \u0431\u0430\u0442\u0447\u0443 != \u0441\u0443\u043c\u043c\u0435 \u043b\u043e\u0441\u043e\u0432 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u0434\u0435, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0435 DP, \u0447\u0435\u043c DDP \u0438\u0437 torch.dist<\/p>\n<\/li>\n<\/ul>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0430 torch<\/em><\/p>\n<p>1) \u041e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 `model = DistributedDataParallel(model, device_ids=[local_rank])` <\/p>\n<p>2) \u041d\u0430\u043b\u0430\u0434\u0438\u0442\u044c  communication group  \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 (\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044c\u0435\u043a\u0442 dist)<\/p>\n<p>3) <\/p>\n<pre><code class=\"python\">import torch   import torch.distributed as dist   # ... for inp, label in dataloader:   optimizer.zero_grad()   out = model(inp)   loss = loss_fun(out, lable)   loss.backward()    # --start--  \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0440\u044d\u0438\u043d \u0441\u0442\u0435\u043f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b for param in model.parameters():   dist.all_reduce(param.grad.data, op=dist.reduce_op.SUM)   param.grad.data \/= dist.get_world_size()   # --end--    optimizer.step()<\/code><\/pre>\n<h2>Pipeline paralelism (model paralelism)<\/h2>\n<p><a href=\"https:\/\/pytorch.org\/docs\/stable\/pipeline.html\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0430 \u0442\u043e\u0440\u0447\u0430<\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5dc\/a46\/c1f\/5dca46c1f77386511ae3f0fe4eba63f4.png\" width=\"1563\" height=\"1053\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5dc\/a46\/c1f\/5dca46c1f77386511ae3f0fe4eba63f4.png\"\/><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/806\/09b\/2f5\/80609b2f537c112d56614f6d9bb732be.png\" width=\"586\" height=\"165\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/806\/09b\/2f5\/80609b2f537c112d56614f6d9bb732be.png\"\/><\/figure>\n<p><strong>model paralelism:<\/strong><br \/> \u042d\u0442\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e \u0441\u043b\u043e\u044f\u043c \u043c\u0435\u0436\u0434\u0443 GPU, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c forward \u0438 backward pass-\u044b, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0433\u043f\u0443, \u0437\u0430\u0442\u0435\u043c, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0435\u043f\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b (\u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u043e\u0434\u0430\u043c\u0438)<br \/> <strong>pipeline paralelism:<\/strong><br \/> \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0433\u043f\u0443 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0435\u0442, \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f 4\u0445 \u0433\u043f\u0443, \u043a\u0430\u043a \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 &#8212; \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u044f ~80%).<br \/> \u042d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0440\u0435\u0448\u0430\u0435\u0442 pipeline \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c &#8212; \u043c\u044b \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0431\u0430\u0442\u0447 \u043d\u0430 \u043c\u0438\u043d\u0438\u0431\u0430\u0442\u0447\u0438 \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9bf\/769\/a2d\/9bf769a2d67ad67c46d9cd56e91ae187.png\" width=\"678\" height=\"204\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9bf\/769\/a2d\/9bf769a2d67ad67c46d9cd56e91ae187.png\"\/><\/figure>\n<p>\u041d\u0430\u0442\u0438\u0432\u043d\u043e \u0442\u043e\u0440\u0447 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u044d\u0442\u043e nn.Sequential, \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0439 \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u0438 \u0444\u043e\u0440\u0432\u0430\u0440\u0434\u0430\u043c\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0435\u0435 \u043c\u0435\u0436\u0434\u0443 gpu \u0432\u0440\u0443\u0447\u043d\u0443\u044e<br \/> \u0422\u0430\u043a\u0436\u0435 \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440 \u0441\u0435\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043b\u044c\u0437\u044f \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043f\u043e \u0441\u043b\u043e\u044f\u043c \u0438\u0437-\u0437\u0430 skip connection \u0438 \u0432\u0441\u044f\u043a\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u044d\u043a\u0437\u043e\u0442\u0438\u043a\u0438 \u0432 \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 torch<\/em><\/p>\n<pre><code class=\"python\"># init rpc os.environ['MASTER_ADDR'] = 'localhost' os.environ['MASTER_PORT'] = '29500' torch.distributed.rpc.init_rpc('worker', rank=0, world_size=1)  # Build pipe. fc1 = nn.Linear(16, 8).cuda(0) fc2 = nn.Linear(8, 4).cuda(1) model = nn.Sequential(fc1, fc2) model = Pipe(model, chunks=8) input = torch.rand(16, 16).cuda(0) output_rref = model(input)<\/code><\/pre>\n<h2>Tensor parallelism<\/h2>\n<p><a href=\"https:\/\/pytorch.org\/docs\/stable\/distributed.tensor.parallel.html\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0430<\/a> <a href=\"https:\/\/github.com\/pytorch\/pytorch\/blob\/main\/torch\/distributed\/_tensor\/README.md\" rel=\"noopener noreferrer nofollow\">\u0413\u0438\u0442\u0445\u0430\u0431<\/a><\/p>\n<p>\u041f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0435\u0437\u0442\u044c \u043d\u0430 \u043e\u0434\u043d\u0443 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Embedding \u0441\u043b\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0432 128_000 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0430 hidden_dim = 8192 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0430\u0434\u0430\u043c\u0430 \u0432 fp16 \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0441\u0438\u0442\u044c \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0433\u0438\u0433\u0430\u0431\u0430\u0439\u0442.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 &#8212; \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0442\u0435\u043d\u0437\u043e\u0440 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043f\u0443.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a29\/97a\/2b9\/a2997a2b993c82c1abd06488c142b387.png\" width=\"976\" height=\"250\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a29\/97a\/2b9\/a2997a2b993c82c1abd06488c142b387.png\"\/><\/figure>\n<p>\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e <img decoding=\"async\" class=\"formula inline\" source=\"\\forall\" alt=\"\\forall\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8b\/8b1\/8b141f94d4371ad99206ca92a896986d.svg\" width=\"auto\" height=\"auto\"\/> \u043f\u043e\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\sigma : R \\rightarrow R\" alt=\"\\sigma : R \\rightarrow R\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f4\/f40\/f4036a40bd48ff15bb0569cf04bf75e4.svg\" width=\"auto\" height=\"auto\"\/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"Z = \\sigma(Ax)\\cdot B = B_1\\sigma(A_1 x) + B_2\\sigma(A_2x)\" alt=\"Z = \\sigma(Ax)\\cdot B = B_1\\sigma(A_1 x) + B_2\\sigma(A_2x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/02a\/258\/e78\/02a258e782e0f56cebe7d3a61e45c543.svg\" width=\"341\" height=\"22\"\/><\/p>\n<p>(\u044d\u0442\u043e \u0436\u0435 \u043e\u0431\u043e\u0431\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043b\u044e\u0431\u0443\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u0441\u043b\u043e\u0435\u0432 \u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438.<\/p>\n<p><strong>\u041e\u0434\u043d\u0430\u043a\u043e:<\/strong><\/p>\n<ol>\n<li>\n<p>\u042d\u0442\u043e \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0433\u043f\u0443<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/668\/f66\/a2f\/668f66a2fad0e9b854c0457099b5560e.png\" alt=\"\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u043e\u0440\u0447\u0430\" title=\"\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u043e\u0440\u0447\u0430\" width=\"1160\" height=\"192\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/668\/f66\/a2f\/668f66a2fad0e9b854c0457099b5560e.png\"\/><\/p>\n<div><figcaption>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u043e\u0440\u0447\u0430<\/figcaption><\/div>\n<\/figure>\n<\/li>\n<\/ol>\n<h4>ZeRO<\/h4>\n<p><a href=\"https:\/\/arxiv.org\/pdf\/1910.02054\" rel=\"noopener noreferrer nofollow\">arxiv<\/a><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a0b\/3ee\/e99\/a0b3eee999c552c55b6c0578680e8389.png\" width=\"1762\" height=\"638\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a0b\/3ee\/e99\/a0b3eee999c552c55b6c0578680e8389.png\"\/><\/figure>\n<p>\u0421\u043f\u043e\u0441\u043e\u0431 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c DDP (baseline) \u043e\u0442 \u043c\u0430\u0439\u043a\u043e\u0432<br \/> \u041a\u0430\u0436\u0434\u0430\u044f \u0433\u043f\u0443, \u0432\u043c\u0435\u0441\u0442\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0435 \u0447\u0430\u0441\u0442\u044c, \u0430 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u0430\u0440\u0442\u043e\u0447\u0435\u043a.<\/p>\n<p>\u0421\u043d\u0438\u0436\u0430\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/p>\n<h2>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432<\/h2>\n<p>\u041d\u0438\u043a\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0438\u043f\u043c\u0430\u0439\u043d\u0434 \u043f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0434\u0430\u0442\u0430\u0446\u0435\u043d\u0442\u0440\u0430\u0445, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e,<br \/> \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0446\u0435\u043d\u0442\u0440\u0430 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 PP, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e \u0441\u0435\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 (DDP).<\/p>\n<h2>\u0427\u0442\u043e \u0435\u0449\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c<\/h2>\n<p>1) \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0435\u0441\u044c \u041b\u041b\u041c, \u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 &#8212; <a href=\"https:\/\/github.com\/microsoft\/DeepSpeed\" rel=\"noopener noreferrer nofollow\"><em>DeepSpeed<\/em><\/a><em> , \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u0438\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0442\u043e\u0440\u0447\u0430<\/em><\/p>\n<p>2) \u041a\u043b\u0430\u0441\u0441\u043d\u0430\u044f <a href=\"https:\/\/medium.com\/@eeyuhao\/pytorch-distributed-a-bottom-up-perspective-e3159ee2c2e7\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043d\u0430 \u043c\u0435\u0434\u0438\u0443\u043c\u0435<\/p>\n<p>3) <a href=\"https:\/\/huggingface.co\/docs\/transformers\/en\/perf_train_gpu_many\" rel=\"noopener noreferrer nofollow\">\u041e\u0432\u0435\u0440\u0432\u044c\u044e<\/a> \u043e\u0442 huggingface \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u041b\u041b\u041c <\/p>\n<p>4) <a href=\"https:\/\/lightning.ai\/docs\/pytorch\/stable\/accelerators\/gpu_intermediate.html\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u0434\u0435\u043e \u043e\u0442 \u0442\u043e\u0440\u0447 \u043b\u0430\u0439\u0442\u043d\u0438\u043d\u0433<\/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\/824322\/\"> https:\/\/habr.com\/ru\/articles\/824322\/<\/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<p><strong>Multi gpu training overview<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 VRAM, \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c\u0438 (\u0438\u043b\u0438 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c\u0438 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c) \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c.<br \/> \u041d\u0438\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043f\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 GPU \u0438\u043b\u0438 \u043d\u043e\u0434\u0430\u043c\u0438.<\/p>\n<p><strong>\u0413\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c 3 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f<\/strong><\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438, \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0432\u043b\u0435\u0437\u0430\u044e\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0439 GPU<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438, \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0432\u043b\u0435\u0437\u0430\u044e\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e\u0439 GPU<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0441\u043b\u043e\u0439 (\u0442\u0435\u043d\u0437\u043e\u0440), \u0432\u044b\u0445\u043e\u0434\u043d\u0430\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u044f \u0441 \u043d\u0435\u0433\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u0432\u043b\u0435\u0437\u0430\u0435\u0442 \u0432 \u0441\u0430\u043c\u0443\u044e \u0431\u043e\u043b\u044c\u0448\u0443\u044e GPU<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0431\u0430\u0442\u0447 \u0441\u0430\u0439\u0437, \u0447\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0435\u0433\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c<br \/> \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 gpu \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e, \u0432\u0435\u0434\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043d\u0435 \u0432\u043b\u0435\u0437\u0430\u0435\u0442 \u0432 \u043e\u0434\u043d\u0443 GPU<\/p>\n<p><strong>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439\u00a01.<\/strong><\/p>\n<ul>\n<li>\n<p>DP<\/p>\n<\/li>\n<li>\n<p>DDP<\/p>\n<\/li>\n<li>\n<p>ZeRO<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439\u00a02.<\/strong><\/p>\n<ul>\n<li>\n<p>Pipeline Parallel<\/p>\n<\/li>\n<li>\n<p>Tensor Parallel<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439\u00a03.<\/strong><\/p>\n<ul>\n<li>\n<p>Tensor parallel<\/p>\n<\/li>\n<\/ul>\n<h2>\u0418\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/h2>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u0432 \u0442\u043e\u0440\u0447 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 (gpu \u0438\u043b\u0438 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430). \u0422\u0430\u043a \u043a\u0430\u043a, \u043a\u0430\u043a \u044f \u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043d\u0438\u043c\u0438 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u0430, \u0434\u0443\u043c\u0430\u044e \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e <s>\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f<\/s> \u043f\u0440\u0438\u0432\u044b\u043a\u0430\u043d\u0438\u044f \u043a \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c \u0442\u043e\u0440\u0447\u0430<\/p>\n<p><em>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0435\u043d\u0437\u043e\u0440\u0430 \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 (\u043d\u043e\u0434\u0430\u043c\u0438)<\/em><\/p>\n<pre><code class=\"python\">import torch   import torch.distributed as dist      dist.init_process_group(backend=\"gloo\", # CPU only backend # https:\/\/pytorch.org\/docs\/stable\/distributed.html init_method=\"tcp:\/\/node1_ip:8551\",  rank=0, # \u043d\u043e\u043c\u0435\u0440 \u043d\u043e\u0434\u044b world_size=2) # \u0447\u0438\u0441\u043b\u043e \u043d\u043e\u0434  t = torch.tensor([1.0]*10) dist.send(tensor=t,            dst=1) # \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043d\u0430 1 \u043d\u043e\u0434\u0443   # ------ second node -------- dist.init_process_group(backend=\"gloo\", # https:\/\/pytorch.org\/docs\/stable\/distributed.html init_method=\"tcp:\/\/node1_ip:8551\",  rank=1, world_size=2) tensor = torch.tensor([0.0]*10)   dist.recv(tensor=tensor, src=0)   print(f'rank 1 received tensor {tensor} from rank 0') <\/code><\/pre>\n<h2>DP &amp; DDP<\/h2>\n<p><a href=\"https:\/\/pytorch.org\/docs\/stable\/distributed.html#module-torch.distributed.tensor.parallel.ddp\" rel=\"noopener noreferrer nofollow\">\u041e\u0432\u0435\u0440\u0432\u044c\u044e \u0432 \u0434\u043e\u043a\u0435 \u0442\u043e\u0440\u0447\u0430<\/a>  <a href=\"https:\/\/github.com\/pytorch\/examples\/blob\/main\/distributed\/ddp-tutorial-series\/multinode.py\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438<\/a> <a href=\"https:\/\/lightning.ai\/docs\/pytorch\/stable\/clouds\/cluster_intermediate_1.html\" rel=\"noopener noreferrer nofollow\">DDP \u0432 3 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0434\u043b\u044f lightning<\/a><\/p>\n<p>DataParallel \u0438 DistributedDataParallel \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u0440\u0430\u0441\u043f\u0438\u0448\u0435\u043c \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u0435\u043f<\/p>\n<p><strong>DDP:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0439 \u043c\u0438\u043d\u0438\u0431\u0430\u0442\u0447 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u0435\u0441\u0430\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043d\u044b, \u0432\u0441\u0435 \u043d\u043e\u0434\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u044e\u0442 \u0438\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439, \u0437\u0430\u0442\u0435\u043c \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u044e\u0442<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0438 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0447\u0435\u043c\u0443 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0435 \u0440\u0430\u0437\u0431\u0435\u0433\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<p><strong>DP:<\/strong><\/p>\n<ul>\n<li>\n<p>GPU 0 \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0431\u0430\u0442\u0447 \u0438 \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0438\u043d\u0438\u0431\u0430\u0442\u0447 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 GPU.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441 GPU 0 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 GPU.<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0434\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 forward \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 y \u043d\u0430 GPU0 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>\u041b\u043e\u0441\u0441 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0442 GPU 0 \u043a\u043e \u0432\u0441\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c, \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 backward<\/p>\n<\/li>\n<li>\n<p>\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0441 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 GPU 0 \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b<br \/> <strong>+<\/strong><\/p>\n<ul>\n<li>\n<p>DDP \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0432 5 \u0440\u0430\u0437 \u043c\u0435\u043d\u044c\u0448\u0435 \u043e\u0431\u043c\u0435\u043d\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u043e\u043d \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432\u0441\u0435 \u0433\u043f\u0443 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u043a DP \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0435\u0442 GPU:0 <\/p>\n<\/li>\n<\/ul>\n<p><strong>&#8212;<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0449\u0435 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e, \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440 \u043d\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0431\u0449\u0430\u0435\u0442\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e DDP \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442 \u043e\u0442 \u043d\u0435 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 (?)<\/p>\n<\/li>\n<li>\n<p>DP \u043f\u043e \u0447\u0435\u0441\u0442\u043d\u043e\u043c\u0443 \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u0431\u0430\u0442\u0447\u0443 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0433\u043f\u0443, \u0430 DDP \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043c\u0438\u043d\u0438 \u0431\u0430\u0442\u0447\u0430. \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u0435\u0439\u0441\u0430\u0445, \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u043a\u043e\u0433\u0434\u0430 \u043b\u043e\u0441\u0441 \u043f\u043e \u0431\u0430\u0442\u0447\u0443 != \u0441\u0443\u043c\u043c\u0435 \u043b\u043e\u0441\u043e\u0432 \u043f\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043a\u043e\u0434\u0435, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u0440\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0435 DP, \u0447\u0435\u043c DDP \u0438\u0437 torch.dist<\/p>\n<\/li>\n<\/ul>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0430 torch<\/em><\/p>\n<p>1) \u041e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432 `model = DistributedDataParallel(model, device_ids=[local_rank])` <\/p>\n<p>2) \u041d\u0430\u043b\u0430\u0434\u0438\u0442\u044c  communication group  \u043c\u0435\u0436\u0434\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 (\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044c\u0435\u043a\u0442 dist)<\/p>\n<p>3) <\/p>\n<pre><code class=\"python\">import torch   import torch.distributed as dist   # ... for inp, label in dataloader:   optimizer.zero_grad()   out = model(inp)   loss = loss_fun(out, lable)   loss.backward()    # --start--  \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0440\u044d\u0438\u043d \u0441\u0442\u0435\u043f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b for param in model.parameters():   dist.all_reduce(param.grad.data, op=dist.reduce_op.SUM)   param.grad.data \/= dist.get_world_size()   # --end--    optimizer.step()<\/code><\/pre>\n<h2>Pipeline paralelism (model paralelism)<\/h2>\n<p><a href=\"https:\/\/pytorch.org\/docs\/stable\/pipeline.html\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0430 \u0442\u043e\u0440\u0447\u0430<\/a><\/p>\n<figure class=\"full-width\"><\/figure>\n<figure class=\"full-width\"><\/figure>\n<p><strong>model paralelism:<\/strong><br \/> \u042d\u0442\u0430 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e \u0441\u043b\u043e\u044f\u043c \u043c\u0435\u0436\u0434\u0443 GPU, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c forward \u0438 backward pass-\u044b, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 \u0438 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0433\u043f\u0443, \u0437\u0430\u0442\u0435\u043c, \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u0435\u043f\u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b (\u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u043e\u0434\u0430\u043c\u0438)<br \/> <strong>pipeline paralelism:<\/strong><br \/> \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043c\u043e\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0433\u043f\u0443 \u043f\u0440\u043e\u0441\u0442\u0430\u0438\u0432\u0430\u0435\u0442, \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f 4\u0445 \u0433\u043f\u0443, \u043a\u0430\u043a \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 &#8212; \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u044f ~80%).<br \/> \u042d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0440\u0435\u0448\u0430\u0435\u0442 pipeline \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c &#8212; \u043c\u044b \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0431\u0430\u0442\u0447 \u043d\u0430 \u043c\u0438\u043d\u0438\u0431\u0430\u0442\u0447\u0438 \u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041d\u0430\u0442\u0438\u0432\u043d\u043e \u0442\u043e\u0440\u0447 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u044d\u0442\u043e nn.Sequential, \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0439 \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u0438 \u0444\u043e\u0440\u0432\u0430\u0440\u0434\u0430\u043c\u0438 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0435\u0435 \u043c\u0435\u0436\u0434\u0443 gpu \u0432\u0440\u0443\u0447\u043d\u0443\u044e<br \/> \u0422\u0430\u043a\u0436\u0435 \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440 \u0441\u0435\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043b\u044c\u0437\u044f \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043f\u043e \u0441\u043b\u043e\u044f\u043c \u0438\u0437-\u0437\u0430 skip connection \u0438 \u0432\u0441\u044f\u043a\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u044d\u043a\u0437\u043e\u0442\u0438\u043a\u0438 \u0432 \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 torch<\/em><\/p>\n<pre><code class=\"python\"># init rpc os.environ['MASTER_ADDR'] = 'localhost' os.environ['MASTER_PORT'] = '29500' torch.distributed.rpc.init_rpc('worker', rank=0, world_size=1)  # Build pipe. fc1 = nn.Linear(16, 8).cuda(0) fc2 = nn.Linear(8, 4).cuda(1) model = nn.Sequential(fc1, fc2) model = Pipe(model, chunks=8) input = torch.rand(16, 16).cuda(0) output_rref = model(input)<\/code><\/pre>\n<h2>Tensor parallelism<\/h2>\n<p><a href=\"https:\/\/pytorch.org\/docs\/stable\/distributed.tensor.parallel.html\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0430<\/a> <a href=\"https:\/\/github.com\/pytorch\/pytorch\/blob\/main\/torch\/distributed\/_tensor\/README.md\" rel=\"noopener noreferrer nofollow\">\u0413\u0438\u0442\u0445\u0430\u0431<\/a><\/p>\n<p>\u041f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0435\u0439\u0440\u043e\u0441\u0435\u0442\u0435\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u043d\u0437\u043e\u0440\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0435\u0437\u0442\u044c \u043d\u0430 \u043e\u0434\u043d\u0443 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Embedding \u0441\u043b\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0435\u0440\u0430 \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0432 128_000 \u0442\u043e\u043a\u0435\u043d\u043e\u0432, \u0430 hidden_dim = 8192 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043c\u0438\u043b\u043b\u0438\u0430\u0440\u0434\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0430\u0434\u0430\u043c\u0430 \u0432 fp16 \u0431\u0443\u0434\u0435\u0442 \u0432\u0435\u0441\u0438\u0442\u044c \u0434\u0435\u0441\u044f\u0442\u043a\u0438 \u0433\u0438\u0433\u0430\u0431\u0430\u0439\u0442.<\/p>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 &#8212; \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0442\u0435\u043d\u0437\u043e\u0440 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u043f\u0443.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e  \u043f\u043e\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <\/p>\n<p>(\u044d\u0442\u043e \u0436\u0435 \u043e\u0431\u043e\u0431\u0449\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043b\u044e\u0431\u0443\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u0441\u043b\u043e\u0435\u0432 \u0438 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438.<\/p>\n<p><strong>\u041e\u0434\u043d\u0430\u043a\u043e:<\/strong><\/p>\n<ol>\n<li>\n<p>\u042d\u0442\u043e \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043a\u0430\u043d\u0430\u043b \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0433\u043f\u0443<\/p>\n<\/li>\n<li>\n<figure class=\"full-width\">\n<div><figcaption>\u0421\u043a\u0440\u0438\u043d\u0448\u043e\u0442 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0442\u043e\u0440\u0447\u0430<\/figcaption><\/div>\n<\/figure>\n<\/li>\n<\/ol>\n<h4>ZeRO<\/h4>\n<p><a href=\"https:\/\/arxiv.org\/pdf\/1910.02054\" rel=\"noopener noreferrer nofollow\">arxiv<\/a><\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0421\u043f\u043e\u0441\u043e\u0431 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c DDP (baseline) \u043e\u0442 \u043c\u0430\u0439\u043a\u043e\u0432<br \/> \u041a\u0430\u0436\u0434\u0430\u044f \u0433\u043f\u0443, \u0432\u043c\u0435\u0441\u0442\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0439 \u0440\u0435\u043f\u043b\u0438\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0435 \u0447\u0430\u0441\u0442\u044c, \u0430 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u0430\u0440\u0442\u043e\u0447\u0435\u043a.<\/p>\n<p>\u0421\u043d\u0438\u0436\u0430\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0431\u043e\u043b\u0435\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043a \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f<\/p>\n<h2>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432<\/h2>\n<p>\u041d\u0438\u043a\u0442\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043e\u0434\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0438\u043f\u043c\u0430\u0439\u043d\u0434 \u043f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0434\u0430\u0442\u0430\u0446\u0435\u043d\u0442\u0440\u0430\u0445, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e,<br \/> \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0446\u0435\u043d\u0442\u0440\u0430 \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 PP, \u0430 \u0437\u0430\u0442\u0435\u043c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e \u0441\u0435\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 (DDP).<\/p>\n<h2>\u0427\u0442\u043e \u0435\u0449\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c<\/h2>\n<p>1) \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0435\u0441\u044c \u041b\u041b\u041c, \u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 &#8212; <a href=\"https:\/\/github.com\/microsoft\/DeepSpeed\" rel=\"noopener noreferrer nofollow\"><em>DeepSpeed<\/em><\/a><em> , \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u0438\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0435 \u0442\u043e\u0440\u0447\u0430<\/em><\/p>\n<p>2) \u041a\u043b\u0430\u0441\u0441\u043d\u0430\u044f <a href=\"https:\/\/medium.com\/@eeyuhao\/pytorch-distributed-a-bottom-up-perspective-e3159ee2c2e7\" rel=\"noopener noreferrer nofollow\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043d\u0430 \u043c\u0435\u0434\u0438\u0443\u043c\u0435<\/p>\n<p>3) <a href=\"https:\/\/huggingface.co\/docs\/transformers\/en\/perf_train_gpu_many\" rel=\"noopener noreferrer nofollow\">\u041e\u0432\u0435\u0440\u0432\u044c\u044e<\/a> \u043e\u0442 huggingface \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u041b\u041b\u041c <\/p>\n<p>4) <a href=\"https:\/\/lightning.ai\/docs\/pytorch\/stable\/accelerators\/gpu_intermediate.html\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u0434\u0435\u043e \u043e\u0442 \u0442\u043e\u0440\u0447 \u043b\u0430\u0439\u0442\u043d\u0438\u043d\u0433<\/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\/824322\/\"> https:\/\/habr.com\/ru\/articles\/824322\/<\/a><br \/><\/br><\/br><\/p>\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-379850","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379850","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=379850"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379850\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}