{"id":4599,"date":"2022-06-24T20:32:30","date_gmt":"2022-06-24T12:32:30","guid":{"rendered":"http:\/\/139.9.1.231\/?p=4599"},"modified":"2022-06-24T20:32:32","modified_gmt":"2022-06-24T12:32:32","slug":"apex","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/06\/24\/apex\/","title":{"rendered":"NVIDIA\u8bad\u7ec3\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u52a0\u901f:APEX\u5e93"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5728\u8dd1\u76ee\u6807\u68c0\u6d4b\u548c\u56fe\u50cf\u5206\u7c7b\u6a21\u578b\uff0c\u53d1\u73b0\u5f88\u591a\u65f6\u5019\u6559\u7a0b\u91cc\u9700\u8981 \u5b89\u88c5apex\u5e93\uff0c\u4e8e\u662f\u6211\u5c31\u53bb\u7f51\u4e0a\u641c\u7d22\u4e00\u4e0b\u8fd9\u4e2a\uff0c\u53d1\u73b0apex\u5927\u6709\u6765\u5934\uff1b<\/p>\n\n\n\n<p>\u5b98\u65b9\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/nvidia.github.io\/apex\/amp.html\">https:\/\/nvidia.github.io\/apex\/amp.html<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/docs.nvidia.com\/deeplearning\/performance\/mixed-precision-training\/index.html\">https:\/\/docs.nvidia.com\/deeplearning\/performance\/mixed-precision-training\/index.html<\/a><\/p>\n\n\n\n<p><strong>APEX<\/strong>\u00a0\u662f\u6765\u81ea\u82f1\u4f1f\u8fbe (NVIDIA) \u7684\u4e00\u4e2a\u5f88\u597d\u7528\u7684\u6df1\u5ea6\u5b66\u4e60\u52a0\u901f\u5e93\u3002\u7531\u82f1\u4f1f\u8fbe\u5f00\u6e90\uff0c\u5b8c\u7f8e\u652f\u6301PyTorch\u6846\u67b6\uff0c\u7528\u4e8e<strong>\u6539\u53d8\u6570\u636e\u683c\u5f0f\u6765\u51cf\u5c0f\u6a21\u578b\u663e\u5b58\u5360\u7528<\/strong>\u7684\u5de5\u5177\u3002\u5176\u4e2d\u6700\u6709\u4ef7\u503c\u7684\u662f\u00a0<strong>amp (Automatic Mixed Precision)\u00a0<\/strong>\uff0c\u5c06\u6a21\u578b\u7684\u5927\u90e8\u5206\u64cd\u4f5c\u90fd\u7528\u00a0<strong>Float16<\/strong>\u00a0\u6570\u636e\u7c7b\u578b\u6d4b\u8bd5\uff0c<strong>\u4e00\u4e9b\u7279\u522b\u64cd\u4f5c<\/strong>\u4ecd\u7136\u4f7f\u7528\u00a0<strong>Float32<\/strong>\u3002\u5e76\u4e14\u7528\u6237\u4ec5\u4ec5\u901a\u8fc7\u4e09\u884c\u4ee3\u7801\u5373\u53ef\u5b8c\u7f8e\u5c06\u81ea\u5df1\u7684\u8bad\u7ec3\u4ee3\u7801\u8fc1\u79fb\u5230\u8be5\u6a21\u578b\u3002\u5b9e\u9a8c\u8bc1\u660e\uff0c\u4f7f\u7528 Float16 \u4f5c\u4e3a\u5927\u90e8\u5206\u64cd\u4f5c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5e76\u6ca1\u6709\u964d\u4f4e\u53c2\u6570\uff0c\u5728\u4e00\u4e9b\u5b9e\u9a8c\u4e2d\uff0c\u53cd\u800c\u7531\u4e8e\u53ef\u4ee5\u589e\u5927 Batch size\uff0c\u5e26\u6765\u7cbe\u5ea6\u4e0a\u7684\u63d0\u5347\uff0c\u4ee5\u53ca\u8bad\u7ec3\u901f\u5ea6\u4e0a\u7684\u63d0\u5347\u3002<\/p>\n\n\n\n<p><strong>\u4f7f\u7528\u7406\u7531<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528\u7cbe\u5ea6\u4f4e\u4e8e32\u4f4d<a href=\"https:\/\/so.csdn.net\/so\/search?q=%E6%B5%AE%E7%82%B9&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">\u6d6e\u70b9<\/a>\u7684\u6570\u503c\u683c\u5f0f\u6709\u8bb8\u591a\u597d\u5904\u3002\u9996\u5148\uff0c\u5b83\u4eec\u9700\u8981\u66f4\u5c11\u7684\u5185\u5b58\uff0c\u4ece\u800c\u80fd\u591f\u8bad\u7ec3\u548c\u90e8\u7f72\u66f4\u5927\u7684\u795e\u7ecf\u7f51\u7edc\u3002\u5176\u6b21\uff0c\u5b83\u4eec\u9700\u8981\u8f83\u5c11\u7684\u5185\u5b58\u5e26\u5bbd\uff0c\u4ece\u800c\u52a0\u5feb\u6570\u636e\u4f20\u8f93\u64cd\u4f5c\u3002\u7b2c\u4e09\uff0c\u6570\u5b66\u8fd0\u7b97\u5728\u964d\u4f4e\u7cbe\u5ea6\u65b9\u9762\u8fd0\u884c\u5f97\u66f4\u5feb\uff0c\u7279\u522b\u662f\u5728\u5177\u6709TensorCore\u652f\u6301\u7684GPU\u4e0a\u3002\u6df7\u5408\u7cbe\u5ea6\u8bad\u7ec3\uff08Mixed Precision Training\uff09\u5b9e\u73b0\u4e86\u6240\u6709\u8fd9\u4e9b\u597d\u5904\uff0c\u540c\u65f6\u786e\u4fdd\u4e0e\u5b8c\u5168\u7cbe\u5ea6\u8bad\u7ec3\u76f8\u6bd4\uff0c\u4e0d\u4f1a\u4e22\u5931\u7279\u5b9a\u4efb\u52a1\u7684\u51c6\u786e\u6027\u3002\u5b83\u8fd9\u6837\u505a\u7684\u65b9\u6cd5\u662f\u8bc6\u522b\u9700\u8981\u5b8c\u5168\u7cbe\u5ea6\u7684\u6b65\u9aa4\uff0c\u53ea\u5bf9\u8fd9\u4e9b\u6b65\u9aa4\u4f7f\u752832\u4f4d\u6d6e\u70b9\uff0c\u800c\u5728\u5176\u4ed6\u5730\u65b9\u4f7f\u752816\u4f4d\u6d6e\u70b9\u3002<\/p>\n\n\n\n<p>\u5728PyTorch\u4e2d\u7684\u4f7f\u7528\uff1a<br>\u9996\u5148\u9700\u8981\u5b89\u88c5\u5176apex\u5e93\uff08\u6211\u8fd8\u6ca1\u88c5\u8fc7\uff09\uff0c\u5176github\u5730\u5740\uff1ahttps:\/\/github.com\/NVIDIA\/apex\u3002<br>\u7136\u540e\u5728\u8bad\u7ec3\u7684\u811a\u672c\uff08\u4ee3\u7801\uff09\u4e2d\u7b80\u5355\u6dfb\u52a0\u51e0\u53e5\u5c31\u53ef\u4ee5\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from apex import amp\n\namp.init()\namp.init_trainer(trainer)\nwith amp.scale_loss(loss, trainer) as scaled_loss:\n   autograd.backward(scaled_loss) <\/code><\/pre>\n\n\n\n<h2>APEX\u7684\u914d\u7f6e<\/h2>\n\n\n\n<p>\u524d\u63d0\u662f\u4f60\u5b89\u88c5\u597d\u4e86CUDA\u548cCUDNN\uff0c\u4ee5\u53ca\u4f60\u7684\u7cfb\u7edf\u662fUbuntu\u7cfb\u7edf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/NVIDIA\/apex\ncd apex\npip install -v --no-cache-dir --global-option=\"--cpp_ext\" --global-option=\"--cuda_ext\" <\/code><\/pre>\n\n\n\n<p>Apex \u8fd8\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u652f\u6301\u4ec5 Python \u6784\u5efa (Pytorch 0.4 \u9700\u8981)\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install -v --disable-pip-version-check --no-cache-dir .\/<\/code><\/pre>\n\n\n\n<p><strong>\u5b89\u88c5\u4e4b\u540e\uff0cclone\u4e0b\u6765\u7684apex\u6587\u4ef6\u5939\u5c31\u53ef\u4ee5\u5220\u9664\u4e86\u3002<\/strong><\/p>\n\n\n\n<p>\u67e5\u770b\u80fd\u5426\u6b63\u786e\u5bfc\u5165apex\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from apex import amp<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u8dd1\u76ee\u6807\u68c0\u6d4b\u548c\u56fe\u50cf\u5206\u7c7b\u6a21\u578b\uff0c\u53d1\u73b0\u5f88\u591a\u65f6\u5019\u6559\u7a0b\u91cc\u9700\u8981 \u5b89\u88c5apex\u5e93\uff0c\u4e8e\u662f\u6211\u5c31\u53bb\u7f51\u4e0a\u641c\u7d22\u4e00\u4e0b\u8fd9\u4e2a\uff0c\u53d1\u73b0ape &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/06\/24\/apex\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">NVIDIA\u8bad\u7ec3\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u52a0\u901f:APEX\u5e93<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,4],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4599"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=4599"}],"version-history":[{"count":9,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4599\/revisions"}],"predecessor-version":[{"id":4608,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/4599\/revisions\/4608"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=4599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=4599"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=4599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}