{"id":511,"date":"2026-07-08T03:04:36","date_gmt":"2026-07-07T19:04:36","guid":{"rendered":"https:\/\/tech-renaissance.cn\/blog\/?p=511"},"modified":"2026-07-08T22:04:33","modified_gmt":"2026-07-08T14:04:33","slug":"memoryplan%e4%b8%8e%e6%98%be%e5%ad%98%e5%88%86%e5%8c%ba%ef%bc%9a%e6%a1%86%e6%9e%b6%e7%9a%84%e7%81%b5%e9%ad%82%e8%ae%be%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/tech-renaissance.cn\/blog\/index.php\/2026\/07\/08\/511\/","title":{"rendered":"(15) MemoryPlan\u4e0e\u663e\u5b58\u5206\u533a\uff1a\u6846\u67b6\u7684\u7075\u9b42\u8bbe\u8ba1"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u2014\u2014\u201c\u4e00\u4e2a\u4eba\u7528AI\u5982\u4f55\u5199\u51fa\u6bd4PyTorch\u66f4\u5feb\u7684\u81ea\u7814\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u201d\u7cfb\u5217\u6587\u7ae0\u4e4b\u5341\u4e94<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u4e00\u7bc7\u6211\u4eec\u8bb2\u4e86 <code>ComputationGraph<\/code> \u4e0e <code>GraphAtlas<\/code>\uff1a\u540c\u4e00\u4efd\u96f6\u5f62\u72b6\u7684\u56fe\u62d3\u6251\uff0c\u5982\u4f55\u88ab\u591a\u4e2a\u8bad\u7ec3\/\u9a8c\u8bc1\u53d8\u4f53\u5171\u4eab\u590d\u7528\u3002\u90a3\u662f\u4e00\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u8bbe\u8ba1\uff0c\u4f46\u5b83\u8fd8\u53ea\u662f\u8ba8\u8bba\u201c\u56fe\u957f\u4ec0\u4e48\u6837\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56fe\u8981\u8dd1\u8d77\u6765\uff0c\u7ec8\u7a76\u8981\u843d\u5230\u771f\u5b9e\u7684\u663e\u5b58\u4e0a\u3002\u5f20\u91cf\u653e\u5728\u54ea\u91cc\u3001\u5360\u591a\u5c11\u5b57\u8282\u3001\u751f\u547d\u5468\u671f\u6709\u591a\u957f\u3001\u4e0d\u540c\u53d8\u4f53\u4e4b\u95f4\u5730\u5740\u80fd\u4e0d\u80fd\u5bf9\u9f50\u2014\u2014\u8fd9\u4e9b\u95ee\u9898\u4e0d\u89e3\u51b3\uff0c\u518d\u597d\u7684\u56fe\u4e5f\u53ea\u662f\u4e00\u5f20\u753b\u5728\u7eb8\u4e0a\u7684\u62d3\u6251\u3002\u5bf9 Tech-Renaissance \u800c\u8a00\uff0c\u663e\u5b58\u7ba1\u7406\u4e0d\u662f\u8fd0\u884c\u65f6\u7684\u4e00\u4ef6\u201c\u540e\u52e4\u4e8b\u52a1\u201d\uff0c\u800c\u662f\u6574\u4e2a\u6846\u67b6\u7684\u7075\u9b42\u8bbe\u8ba1\u4e4b\u4e00\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e00\u7bc7\u6211\u4eec\u5c31\u6765\u8bb2 <code>MemoryPlan<\/code>\uff0c\u4ee5\u53ca\u5b83\u80cc\u540e\u90a3\u5957\u628a\u663e\u5b58\u6309\u8bed\u4e49\u9759\u6001\u5206\u533a\u7684\u8bbe\u8ba1\u601d\u60f3\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u663e\u5b58\u7ba1\u7406\uff1a\u88ab\u4f4e\u4f30\u7684\u6027\u80fd\u74f6\u9888<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6df1\u5ea6\u5b66\u4e60\u8bad\u7ec3\u662f\u4e00\u4e2a\u9ad8\u5ea6\u5185\u5b58\u5bc6\u96c6\u7684\u4efb\u52a1\u3002\u4e00\u4e2a\u73b0\u4ee3\u5377\u79ef\u7f51\u7edc\uff0c\u4e0d\u4ec5\u9700\u8981\u5b58\u50a8\u6a21\u578b\u6743\u91cd\uff0c\u8fd8\u9700\u8981\u4e3a\u6bcf\u4e00\u5c42\u7684\u4e2d\u95f4\u7279\u5f81\u56fe\u3001\u53cd\u5411\u68af\u5ea6\u3001\u4f18\u5316\u5668\u52a8\u91cf\u3001BN \u7edf\u8ba1\u91cf\u3001\u4e34\u65f6\u7f13\u51b2\u533a\u3001\u8f93\u5165\u6570\u636e\u7b49\u9884\u7559\u5927\u91cf\u663e\u5b58\u3002\u4ee5 ResNet-50 \u4e3a\u4f8b\uff0c\u6743\u91cd\u672c\u8eab\u53ef\u80fd\u53ea\u6709\u51e0\u5341 MB\uff0c\u4f46\u8bad\u7ec3\u65f6\u7684\u7279\u5f81\u56fe\u3001\u68af\u5ea6\u548c\u4f18\u5316\u5668\u72b6\u6001\u53ef\u4ee5\u8f7b\u677e\u5360\u5230\u51e0\u4e2a GB\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e3b\u6d41\u6846\u67b6\u91cc\uff0c\u8fd9\u4e9b\u663e\u5b58\u901a\u5e38\u7531\u8fd0\u884c\u65f6\u7684\u7f13\u5b58\u5206\u914d\u5668\u6309\u9700\u7ba1\u7406\u3002PyTorch \u7684 CUDA Caching Allocator \u5c31\u662f\u4e00\u4e2a\u5178\u578b\u4ee3\u8868\uff1a\u5b83\u9884\u5148\u5411 CUDA \u9a71\u52a8\u7533\u8bf7\u4e00\u4e9b\u5927\u6bb5\u5185\u5b58\uff0c\u7136\u540e\u5728\u81ea\u5df1\u7684\u6c60\u5b50\u91cc\u628a\u5c0f\u5757\u5207\u7ed9\u7528\u6237\uff0c\u907f\u514d\u6bcf\u6b21 <code>cudaMalloc<\/code> \u90fd\u8d70\u9a71\u52a8\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u5728\u901a\u7528\u6027\u4e0a\u505a\u5f97\u5f88\u597d\uff0c\u4e5f\u652f\u6491\u4e86 PyTorch \u7075\u6d3b\u591a\u53d8\u7684\u52a8\u6001\u56fe\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u7f13\u5b58\u5206\u914d\u5668\u5e76\u4e0d\u662f\u514d\u8d39\u7684\u3002\u5b83\u6709\u51e0\u4e2a\u7ed3\u6784\u6027\u95ee\u9898\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e00\uff0c\u5206\u914d\u5ef6\u8fdf\u3002<\/strong> \u867d\u7136\u6bd4 <code>cudaMalloc<\/code> \u5feb\uff0c\u4f46\u9ad8\u9891\u7387\u7684\u5c0f\u5f20\u91cf\u7533\u8bf7\/\u91ca\u653e\u4ecd\u7136\u9700\u8981\u8d70\u5206\u914d\u5668\u903b\u8f91\uff0c\u6d89\u53ca\u9501\u7ade\u4e89\u3001\u7a7a\u95f2\u5757\u67e5\u627e\u3001\u5757\u5408\u5e76\u7b49\u64cd\u4f5c\u3002\u5f53\u6a21\u578b\u5f88\u6df1\u3001\u7b97\u5b50\u5f88\u788e\u65f6\uff0c\u8fd9\u90e8\u5206\u5f00\u9500\u4f1a\u7d2f\u79ef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e8c\uff0c\u5185\u5b58\u788e\u7247\u3002<\/strong> \u5206\u914d\u5668\u6309\u8bf7\u6c42\u5927\u5c0f\u5207\u5206\u5185\u5b58\uff0c\u957f\u671f\u8fd0\u884c\u540e\u5bb9\u6613\u51fa\u73b0\u201c\u5c0f\u6d1e\u201d\u2014\u2014\u603b\u7a7a\u95f2\u5185\u5b58\u8db3\u591f\uff0c\u4f46\u6ca1\u6709\u8db3\u591f\u5927\u7684\u8fde\u7eed\u5757\u6ee1\u8db3\u4e00\u6b21\u65b0\u7533\u8bf7\u3002PyTorch \u7528\u6237\u5e94\u8be5\u5bf9\u4e0b\u9762\u8fd9\u79cd\u62a5\u9519\u4e0d\u964c\u751f\uff1a&#8221;CUDA out of memory. Tried to allocate 2.00 GiB (GPU 0; 15.90 GiB total capacity; 11.20 GiB already allocated; 2.30 GiB free; 14.10 GiB reserved in total by PyTorch)\u3002&#8221; \u8fd9\u6b63\u662f\u788e\u7247\u7684\u5178\u578b\u75c7\u72b6\uff1a\u5206\u914d\u5668\u4fdd\u7559\u7684\u663e\u5b58\u8fdc\u5927\u4e8e\u5b9e\u9645\u4f7f\u7528\u91cf\uff0c\u7a7a\u95f2\u603b\u91cf\u4e5f\u5927\u4e8e\u8bf7\u6c42\u91cf\uff0c\u5374\u62ff\u4e0d\u51fa\u4e00\u5757\u6ee1\u8db3\u8bf7\u6c42\u7684\u8fde\u7eed\u7a7a\u95f4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e09\uff0c\u5730\u5740\u4e0d\u7a33\u5b9a\u3002<\/strong> \u7f13\u5b58\u5206\u914d\u5668\u503e\u5411\u4e8e\u590d\u7528\u4e4b\u524d\u91ca\u653e\u7684\u5757\uff0c\u4f46\u590d\u7528\u5e76\u4e0d\u4fdd\u8bc1\u540c\u4e00\u5757\u5730\u5740\u3002\u5bf9 CUDA Graph \u6765\u8bf4\uff0c\u8fd9\u662f\u4e00\u4e2a\u81f4\u547d\u95ee\u9898\uff1aCUDA Graph \u5728\u6355\u83b7\u65f6\u4f1a\u628a\u6240\u6709\u8f93\u5165\u8f93\u51fa\u6307\u9488\u6309\u503c\u8bb0\u5f55\u4e0b\u6765\uff0c\u91cd\u653e\u65f6\u8981\u6c42\u8fd9\u4e9b\u5730\u5740\u5fc5\u987b\u5b8c\u5168\u76f8\u540c\u3002\u5982\u679c\u5206\u914d\u5668\u7ed9\u4e86\u4e0d\u540c\u7684\u5730\u5740\uff0c\u56fe\u5c31\u4f1a\u91cd\u653e\u5931\u8d25\uff0c\u751a\u81f3\u9759\u9ed8\u8bbf\u95ee\u975e\u6cd5\u5730\u5740\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u56db\uff0c\u65e0\u6cd5\u505a\u5168\u5c40\u6279\u91cf\u4f18\u5316\u3002<\/strong> \u8fd0\u884c\u65f6\u5206\u914d\u5668\u770b\u5230\u7684\u662f\u4e00\u6b21\u4e00\u6b21\u5b64\u7acb\u7684\u7533\u8bf7\u8bf7\u6c42\uff0c\u5b83\u4e0d\u77e5\u9053\u201c\u8fd9\u4e9b\u5f20\u91cf\u90fd\u662f BN \u7684 running mean\u201d\uff0c\u4e5f\u4e0d\u77e5\u9053\u201c\u8fd9\u4e9b\u68af\u5ea6\u5e94\u8be5\u4e00\u6b21\u6027\u6e05\u96f6\u201d\u3002\u5b83\u53ea\u80fd\u9010\u4e2a\u5757\u5730\u7ba1\u7406\uff0c\u56e0\u6b64\u65e0\u6cd5\u50cf\u7f16\u8bd1\u5668\u90a3\u6837\u505a\u8de8\u5f20\u91cf\u7684\u6279\u91cf\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u95ee\u9898\u7684\u5171\u540c\u6839\u6e90\u5728\u4e8e\uff1a<strong>\u663e\u5b58\u662f\u5728\u8fd0\u884c\u65f6\u88ab\u201c\u4e34\u65f6\u51b3\u5b9a\u201d\u600e\u4e48\u653e\u7684<\/strong>\u3002\u90a3\u4e48\uff0c\u5982\u679c\u628a\u8fd9\u4ef6\u4e8b\u63d0\u524d\u5230\u7f16\u8bd1\u671f\u51b3\u5b9a\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5c31\u662f\u9759\u6001\u663e\u5b58\u89c4\u5212\u7684\u57fa\u672c\u601d\u60f3\uff1a\u5728\u8bad\u7ec3\u5f00\u59cb\u4e4b\u524d\uff0c\u6839\u636e\u6a21\u578b\u7ed3\u6784\u3001\u4f18\u5316\u5668\u7c7b\u578b\u3001\u7cbe\u5ea6\u6a21\u5f0f\u3001\u8f93\u5165\u5206\u8fa8\u7387\uff0c\u4e00\u6b21\u6027\u7b97\u51fa\u6bcf\u4e2a\u5f20\u91cf\u5e94\u8be5\u653e\u5728\u54ea\u91cc\u3001\u5360\u591a\u5c11\u5b57\u8282\u3001\u751f\u547d\u5468\u671f\u5982\u4f55\u3002\u8fd0\u884c\u65f6\u53ea\u6309\u8fd9\u5f20\u201c\u56fe\u7eb8\u201d\u8bbf\u95ee\u56fa\u5b9a\u504f\u79fb\uff0c\u4e0d\u518d\u505a\u52a8\u6001\u5206\u914d\u3002\u7c7b\u4f3c\u7684\u9759\u6001\u89c4\u5212\u601d\u60f3\u5728\u4e00\u4e9b\u5de5\u4e1a\u754c\u6846\u67b6\u548c\u5b66\u672f\u7814\u7a76\u9879\u76ee\u4e2d\u90fd\u6709\u63a2\u7d22\uff0c\u800c Tech-Renaissance \u628a\u5b83\u505a\u6210\u4e86\u4e00\u4e2a\u975e\u5e38\u5f7b\u5e95\u7684\u8bbe\u8ba1\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Tech-Renaissance \u7684\u663e\u5b58\u54f2\u5b66\uff1a\u6309\u8bed\u4e49\u9759\u6001\u5206\u533a<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tech-Renaissance \u5bf9\u663e\u5b58\u7684\u6838\u5fc3\u5047\u8bbe\u53ef\u4ee5\u6982\u62ec\u4e3a\u4e00\u53e5\u8bdd\uff1a<strong>\u8fd0\u884c\u671f\u4e0d\u505a\u52a8\u6001\u663e\u5b58\u5206\u914d<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e0d\u662f\u8bf4\u6211\u4eec\u5728\u8fd0\u884c\u65f6\u5b8c\u5168\u4e0d\u8c03\u7528 CUDA API\uff0c\u800c\u662f\u8bf4\u6240\u6709\u5f20\u91cf\u7684\u903b\u8f91\u4f4d\u7f6e\u90fd\u5728\u7f16\u8bd1\u671f\u7531 <code>MemoryPlan<\/code> \u786e\u5b9a\u3002\u8fd0\u884c\u65f6\u7684\u663e\u5b58\u6c60\u7531 <code>ArenaKeeper<\/code> \u4e00\u6b21\u6027\u5206\u914d\uff0c\u4e4b\u540e\u6240\u6709 <code>DTensor<\/code> \u53ea\u662f\u8fd9\u4e2a\u6c60\u5b50\u91cc\u7684\u4e00\u4e2a <code>(offset, stride, shape)<\/code> \u63cf\u8ff0\u7b26\u3002\u6bcf\u4e2a\u7b97\u5b50\u8981\u8bbf\u95ee\u6570\u636e\u65f6\uff0c\u901a\u8fc7 <code>ArenaKeeper::ptr_at(rank, offset)<\/code> \u628a\u504f\u79fb\u89e3\u6790\u6210\u771f\u5b9e\u6307\u9488\u2014\u2014\u8fd9\u4e2a\u89e3\u6790\u662f O(1) \u7684\uff0c\u4e14\u6ca1\u6709\u9501\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u57fa\u4e8e\u8fd9\u4e2a\u524d\u63d0\uff0c\u6211\u4eec\u8fdb\u4e00\u6b65\u505a\u4e86\u4e00\u4ef6\u4e8b\uff1a<strong>\u628a\u663e\u5b58\u6309\u8bed\u4e49\u5206\u533a<\/strong>\u3002\u4e0d\u662f\u6309\u5f20\u91cf\u7684\u5927\u5c0f\u6216\u751f\u547d\u5468\u671f\u7b80\u5355\u5806\u653e\uff0c\u800c\u662f\u6309\u5f20\u91cf\u5728\u8bad\u7ec3\u6d41\u7a0b\u4e2d\u7684\u8bed\u4e49\u89d2\u8272\uff0c\u628a\u5b83\u4eec\u7ec4\u7ec7\u5230\u4e0d\u540c\u7684 Region \u91cc\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u5206\u533a\u7684\u4ef7\u503c\u5728\u54ea\u91cc\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60f3\u8c61\u4e00\u4e0b\uff0c\u5982\u679c\u4f60\u628a\u5168\u6a21\u578b\u7684\u6240\u6709 BN \u504f\u7f6e\u68af\u5ea6\u8fde\u7eed\u653e\u5728\u4e00\u8d77\uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u7528\u4e00\u4e2a kernel\u3001\u4e00\u6b21\u904d\u5386\uff0c\u628a\u5b83\u4eec\u5168\u90e8\u6e05\u96f6\uff0c\u800c\u4e0d\u7528\u7ba1\u8fd9\u4e9b\u68af\u5ea6\u5206\u522b\u5c5e\u4e8e\u7b2c\u51e0\u5c42\u3001\u53eb\u4ec0\u4e48\u540d\u5b57\u3002\u5982\u679c\u4f60\u628a FP32 \u4e3b\u6743\u91cd\u548c FP16 \u8ba1\u7b97\u6743\u91cd\u6309\u5b8c\u5168\u76f8\u540c\u7684\u987a\u5e8f\u6392\u5e03\uff0c\u90a3\u4e48\u4f60\u5c31\u53ef\u4ee5\u7528\u4e00\u6b21 RangeOp \u5b8c\u6210\u5168\u6a21\u578b\u7684\u7cbe\u5ea6\u8f6c\u6362\u3002\u5982\u679c\u4f60\u628a\u6743\u91cd\u533a\u548c\u52a8\u91cf\u533a\u4e00\u4e00\u5bf9\u5e94\uff0c\u90a3\u4e48\u4f18\u5316\u5668\u66f4\u65b0\u5c31\u53ef\u4ee5\u6309 Region \u6279\u91cf\u6267\u884c\uff0c\u800c\u4e0d\u662f\u9010\u53c2\u6570\u5faa\u73af\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5c31\u662f\u201c\u6309\u8bed\u4e49\u5206\u533a\u201d\u7684\u7cbe\u9ad3\uff1a<strong>\u540c\u8bed\u4e49\u7684\u5f20\u91cf\u4e0d\u4ec5\u5728\u903b\u8f91\u4e0a\u540c\u7c7b\uff0c\u5728\u7269\u7406\u5185\u5b58\u4e0a\u4e5f\u540c\u7c7b<\/strong>\u3002\u5b83\u8ba9\u201c\u65e0\u89c6\u5f20\u91cf\u8fb9\u754c\u7684\u6279\u91cf\u64cd\u4f5c\u201d\u6210\u4e3a\u53ef\u80fd\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001Region\uff1a\u4e00\u5f20\u8be6\u7ec6\u7684\u663e\u5b58\u5730\u56fe<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 <code>include\/renaissance\/core\/types.h<\/code> \u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u663e\u5b58\u533a\u57df\u679a\u4e3e <code>Region<\/code>\u3002\u5b83\u7684\u6570\u7ec4\u5927\u5c0f\u7531 <code>NUM_REGIONS<\/code> \u7ed9\u51fa\uff0c\u5f53\u524d\u503c\u4e3a 69\uff1b\u5176\u4e2d\u5b9e\u9645\u547d\u540d\u7684\u8bed\u4e49 Region \u4e3a 68 \u4e2a\uff08\u6309\u4eba\u7c7b\u9605\u8bfb\u4e60\u60ef\u7f16\u53f7 001\u2013068\uff09\uff0c<code>DEFAULT<\/code> \u662f 001 \u7684\u522b\u540d\uff0c\u6700\u540e\u4e00\u4e2a\u69fd\u4f4d\u662f\u6570\u7ec4\u8fb9\u754c\u54e8\u5175\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b Region \u6309\u7167\u56fa\u5b9a\u987a\u5e8f\u4ece\u4f4e\u5730\u5740\u6392\u5230\u9ad8\u5730\u5740\uff0c\u8986\u76d6\u8bad\u7ec3\u6d41\u7a0b\u4e2d\u51e0\u4e4e\u6240\u6709\u53ef\u80fd\u51fa\u73b0\u7684\u5f20\u91cf\u7c7b\u578b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ \u7b80\u5316\u793a\u610f\uff0c\u5b8c\u6574\u5b9a\u4e49\u89c1 include\/renaissance\/core\/types.h\nenum class Region : uint8_t {\n    \/\/ B \u7cfb\u5217\uff1aBN \u7edf\u8ba1\u91cf\uff08001\u2013004\uff09\n    B_PREV_MEAN  = 0,\n    B_PREV_VAR,\n    B_NEXT_MEAN,\n    B_NEXT_VAR,\n\n    \/\/ W \u7cfb\u5217\uff1a\u4e3b\u6a21\u578b\u6743\u91cd\uff08005\u2013012\uff09\n    W_EQ_BIAS,        \/\/ \u4ec5\u5f53 bn_folded=true \u65f6\u542f\u7528\n    W_EQ_SCALE,\n    W_BN_BIAS,\n    W_BN_WEIGHT,\n    W_FC_BIAS,\n    W_FC_WEIGHT,\n    W_FIRST_CONV,\n    W_DEEP_CONV,\n\n    \/\/ E \u7cfb\u5217\uff1aEMA \u6743\u91cd\uff08013\u2013021\uff09\n    E_BN_BIAS, E_BN_WEIGHT, E_FC_BIAS, E_FC_WEIGHT,\n    E_FIRST_CONV, E_DEEP_CONV,\n    E_FC_WEIGHT_FP16, E_FIRST_CONV_FP16, E_DEEP_CONV_FP16,\n\n    \/\/ A \u7cfb\u5217\uff1aAMP FP16 \u8ba1\u7b97\u6743\u91cd\uff08022\u2013024\uff09\n    A_FC_WEIGHT, A_FIRST_CONV, A_DEEP_CONV,\n\n    \/\/ G \u7cfb\u5217\uff1a\u68af\u5ea6\uff08025\u2013030 \u4e3a FP32\uff0c032\u2013034 \u4e3a FP16\uff09\n    G_BN_BIAS, G_BN_WEIGHT, G_FC_BIAS, G_FC_WEIGHT,\n    G_FIRST_CONV, G_DEEP_CONV,\n\n    R_RESULT,                  \/\/ 031\uff1aloss\/top1\/top5 \u7ed3\u679c\u533a\n\n    G_FC_WEIGHT_FP16,\n    G_FIRST_CONV_FP16,\n    G_DEEP_CONV_FP16,\n\n    \/\/ M\/V\/N \u7cfb\u5217\uff1a\u4e00\u9636\/\u4e8c\u9636\u52a8\u91cf\u3001LARS \u8303\u6570\uff08035\u2013049\uff09\n    M_BN_BIAS, ..., M_DEEP_CONV,\n    V_BN_BIAS, ..., V_DEEP_CONV,\n    N_FC_WEIGHT, N_FIRST_CONV, N_DEEP_CONV,\n\n    \/\/ I \u7cfb\u5217\uff1aA\/B \u53cc\u7f13\u51b2\u8f93\u5165\uff08050\u2013053\uff09\n    I_A_LABEL, I_A_DATA, I_B_LABEL, I_B_DATA,\n\n    \/\/ F \u7cfb\u5217\uff1a\u7279\u5f81\u56fe\u4e0e\u68af\u5ea6\u69fd\uff08054\u2013057\uff09\n    F_FEATURE_FP32, F_GRAD_SLOT_FP32,\n    F_FEATURE_FP16, F_GRAD_SLOT_FP16,\n\n    \/\/ S \u7cfb\u5217\uff1a\u6807\u91cf\u4e0e\u63a9\u7801\uff08058\u2013062\uff09\n    S_SCALAR_FP32, S_SCALAR_FP16, S_SCALAR_INT32, S_SCALAR_INT8, S_MASK,\n\n    \/\/ T \u7cfb\u5217\uff1a\u4e34\u65f6\u5f20\u91cf\uff08063\u2013066\uff09\n    T_TEMP_FP32, T_TEMP_FP16, T_TEMP_INT32, T_TEMP_INT8,\n\n    \/\/ R \u7cfb\u5217\uff1a\u7ed3\u679c\u533a\uff08031, 067, 068\uff09\n    R_PREDICTED_LABEL,        \/\/ 067\n    R_RESULT_ACCUMULATED,     \/\/ 068\n\n    DEFAULT = B_PREV_MEAN,\n    NUM_REGIONS = 69\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u91cc\uff0c\u6ce8\u91ca\u4e2d\u7684\u201c001\u3001002\u2026\u2026\u201d\u662f\u4e3a\u4e86\u65b9\u4fbf\u4eba\u7c7b\u9605\u8bfb\uff0c\u771f\u6b63\u7684\u679a\u4e3e\u503c\u4ece 0 \u5f00\u59cb\u3002\u4e3a\u4ec0\u4e48\u8981\u5206\u5f97\u8fd9\u4e48\u7ec6\uff1f\u56e0\u4e3a\u5206\u5f97\u7ec6\uff0c\u624d\u80fd\u7cbe\u786e\u63a7\u5236\u521d\u59cb\u5316\u3001\u5bf9\u9f50\u3001\u6279\u91cf\u64cd\u4f5c\u548c\u8de8\u53d8\u4f53\u4e00\u81f4\u6027\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>W_BN_WEIGHT<\/code> \u4e0e <code>W_BN_BIAS<\/code> \u5206\u5f00\uff0c\u662f\u56e0\u4e3a BN \u7684\u7f29\u653e\u53c2\u6570\u901a\u5e38\u521d\u59cb\u5316\u4e3a 1.0\uff0c\u504f\u7f6e\u521d\u59cb\u5316\u4e3a 0.0\uff1b<\/li>\n\n\n\n<li><code>G_FIRST_CONV<\/code> \u4e0e <code>G_DEEP_CONV<\/code> \u5206\u5f00\uff0c\u662f\u56e0\u4e3a\u9996\u5c42\u5377\u79ef\u7684\u8f93\u5165\u901a\u9053\u6570\u901a\u5e38\u5f88\u5c11\uff08\u5982 RGB \u7684 3 \u901a\u9053\uff09\uff0c\u800c\u6df1\u5c42\u5377\u79ef\u901a\u9053\u6570\u5f88\u5927\uff0c\u4e24\u8005\u5728 AMP padding \u548c\u901a\u4fe1\u7b56\u7565\u4e0a\u9700\u8981\u533a\u522b\u5bf9\u5f85\uff1b<\/li>\n\n\n\n<li><code>G_BN_BIAS<\/code> \u5230 <code>G_FIRST_CONV<\/code> \u8fde\u7eed\u6392\u5217\uff0c\u6784\u6210\u68af\u5ea6\u901a\u4fe1\u7684\u201c\u6876 2\u201d\uff1b<code>G_DEEP_CONV<\/code> \u5355\u72ec\u4f5c\u4e3a\u201c\u6876 1\u201d\uff0c\u76f4\u63a5\u5bf9\u5e94\u4e86 NCCL AllReduce \u7684\u4e24\u6876\u5206\u6cd5\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b Region \u4e0d\u662f\u53ef\u9009\u7684\u88c5\u9970\uff0c\u800c\u662f\u7f16\u8bd1\u5668\u548c\u8fd0\u884c\u65f6\u5171\u540c\u9075\u5b88\u7684\u89c4\u5219\u3002\u6bcf\u4e2a <code>DTensor<\/code> \u521b\u5efa\u65f6\u90fd\u5fc5\u987b\u58f0\u660e\u81ea\u5df1\u5c5e\u4e8e\u54ea\u4e2a Region\uff0c\u4e0d\u80fd\u4e71\u653e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001DTensor\uff1a\u4e0d\u6301\u6709\u5185\u5b58\u7684\u63cf\u8ff0\u7b26<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Tech-Renaissance \u4e2d\uff0c\u53c2\u4e0e\u8ba1\u7b97\u7684\u57fa\u672c\u5355\u4f4d\u4e0d\u662f\u4f20\u7edf\u610f\u4e49\u4e0a\u7684 <code>Tensor<\/code>\uff0c\u800c\u662f <code>DTensor<\/code>\uff0c\u5373 <code>DistributedTensor<\/code>\u3002<code>DTensor<\/code> \u7684\u8bbe\u8ba1\u975e\u5e38\u5173\u952e\uff1a\u5b83<strong>\u53ea\u5b58\u5f62\u72b6\u3001\u504f\u79fb\u3001stride\u3001\u6570\u636e\u7c7b\u578b\u548c Region\uff0c\u4e0d\u6301\u6709\u4efb\u4f55\u5b9e\u9645\u5185\u5b58<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u8bbe\u8ba1\u5728 <code>include\/renaissance\/tensor\/distributed_tensor.h<\/code> \u7684\u6ce8\u91ca\u91cc\u5199\u5f97\u5f88\u6e05\u695a\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">DTensor \u662f\u4e00\u4e2a\u7eaf\u865a\u62df\u6982\u5ff5\uff1a\u53ea\u5b58\u5f62\u72b6\/\u504f\u79fb\u91cf\/stride\uff0c\u4e0d\u6301\u6709\u5185\u5b58\u3001\u4e0d\u5b58\u6307\u9488\u3002\u540c\u4e00\u4e2a DTensor \u6307\u4ee3\u6240\u6709\u5361\u4e0a\u76f8\u540c\u7684\u7269\u7406\u5185\u5b58\u533a\u57df\uff0c\u5e03\u5c40\u5b8c\u5168\u76f8\u540c\uff0c\u4f46\u6570\u636e\u53ef\u4ee5\u6709\u522b\u3002<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">struct DistributedTensor {\n    int32_t  id      = -1;\n    Shape    shape;                   \/\/ [N, H, W, C] \u903b\u8f91\u7ef4\u5ea6\n    DType    dtype   = DType::FP32;\n    Region   region  = Region::DEFAULT;\n    \/\/ ... stride \u7f13\u5b58 ...\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DTensor<\/code> \u7684 <code>offset_<\/code> \u5728 <code>MemoryPlan::finalize()<\/code> \u4e4b\u524d\u662f <code>-1<\/code>\uff0cfinalize \u4e4b\u540e\u624d\u5199\u5165\u771f\u5b9e\u7684\u5b57\u8282\u504f\u79fb\u3002\u6240\u6709\u5361\u4e0a\u7684\u540c\u4e00\u4e2a <code>DTensor<\/code> \u62e5\u6709\u5b8c\u5168\u76f8\u540c\u7684 offset\uff0c\u53ea\u662f\u6570\u636e\u5185\u5bb9\u53ef\u4ee5\u4e0d\u540c\u2014\u2014\u8fd9\u6b63\u662f\u201c\u4e00\u5f20\u56fe\u7eb8\uff0c\u516b\u5361\u5171\u4eab\u201d\u7684\u542b\u4e49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>DTensor<\/code> \u8fd8\u6709\u4e00\u4e2a\u6838\u5fc3\u8bbe\u8ba1\u662f <code>slot_bytes_<\/code>\uff1a\u5b83\u8868\u793a\u8fd9\u4e2a\u5f20\u91cf\u5728\u7269\u7406\u5185\u5b58\u4e2d\u5360\u636e\u7684\u69fd\u4f4d\u5927\u5c0f\uff0c\u4e0d\u4e00\u5b9a\u662f <code>nbytes()<\/code>\u3002<code>slot_bytes_<\/code> \u7efc\u5408\u8003\u8651\u4e86\u901a\u9053 padding\u3001\u672b\u5c3e\u9884\u7559\u7684 16 \u5b57\u8282\u3001\u4ee5\u53ca 256 \u5b57\u8282\u5bf9\u9f50\u3002\u8ba1\u7b97\u89c4\u5219\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">uint64_t DistributedTensor::compute_slot_bytes(\n    const Shape&amp; shape, DType dtype, Region region) noexcept\n{\n    \/\/ 1. \u6839\u636e dtype + region \u51b3\u5b9a C \u901a\u9053\u5bf9\u9f50\u56e0\u5b50\n    uint8_t alignment = 1;\n    if (dtype == DType::FP16) {\n        if (region == Region::I_A_DATA || region == Region::I_B_DATA)\n            alignment = 4;                         \/\/ \u8f93\u5165\u7f13\u51b2\u533a AMP \u5bf9\u9f50\u5230 4\n        else if (region == Region::F_FEATURE_FP16 ||\n                 region == Region::F_GRAD_SLOT_FP16)\n            alignment = 8;                         \/\/ \u7279\u5f81\u56fe AMP \u5bf9\u9f50\u5230 8\uff08Tensor Core\uff09\n    } else if (dtype == DType::INT8 &amp;&amp; region == Region::S_MASK) {\n        alignment = 8;                             \/\/ \u63a9\u7801 INT8 \u5bf9\u9f50\u5230 8\n    }\n\n    int64_t padded_c = align_up(shape.c(), alignment);\n    uint64_t elems = shape.n() * shape.h() * shape.w() * padded_c;\n\n    \/\/ 2. \u8ba1\u7b97\u69fd\u4f4d\n    if (dtype == DType::FP16) {\n        return align_up_256(elems * 2 + 16);\n    } else if (dtype == DType::INT8) {\n        return align_up_256(elems * 1 + 16);\n    } else {\n        \/\/ FP32 \/ INT32\uff1a\u69fd\u4f4d = 2 \u00d7\uff08FP16 \u7b49\u6548\u69fd\u4f4d\uff09\n        return 2 * align_up_256(elems * 2 + 16);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8fd9\u6bb5\u4f2a\u4ee3\u7801\u4e2d\uff0c<code>shape<\/code> \u662f\u903b\u8f91\u7ef4\u5ea6\uff08\u672a padding \u7684 NHWC\uff09\uff0c<code>dtype<\/code> \u662f\u6570\u636e\u7c7b\u578b\uff0c<code>region<\/code> \u51b3\u5b9a\u5bf9\u9f50\u9700\u6c42\u3002\u6ce8\u610f\u51e0\u4e2a\u5173\u952e\u7ec6\u8282\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>FP32 \u69fd\u4f4d\u662f FP16 \u7b49\u6548\u69fd\u4f4d\u7684\u4e24\u500d<\/strong>\u3002\u8fd9\u4e0d\u662f\u6d6a\u8d39\uff0c\u800c\u662f\u6709\u6df1\u610f\u7684\u2014\u2014\u7531\u4e8e offset \u548c slot \u90fd\u4fdd\u6301\u4e25\u683c\u7684\u500d\u7387\u5173\u7cfb\uff0cFP32 \u4e0e FP16 \u4e4b\u95f4\u7684\u6574\u533a\u7c7b\u578b\u8f6c\u6362\u53ef\u4ee5\u7528\u4e00\u4e2a <code>RangeOp<\/code> \u5b8c\u6210\uff0c\u4e0d\u9700\u8981\u9010\u5c42\u5904\u7406\u3002\u8fd9\u662f\u6846\u67b6\u901f\u5ea6\u5feb\u7684\u4e00\u4e2a\u6839\u672c\u539f\u56e0\u3002<\/li>\n\n\n\n<li><strong>\u672b\u5c3e\u9884\u7559 16 \u5b57\u8282<\/strong> \u662f\u4e3a\u4e86\u6ee1\u8db3 XNNPACK \u5728 CPU \u8def\u5f84\u4e0a\u7684\u5bf9\u9f50\u8981\u6c42\u3002<\/li>\n\n\n\n<li><strong>\u5916\u90e8 <code>align_up_256<\/code><\/strong> \u4fdd\u8bc1\u4e86\u6240\u6709\u5f20\u91cf\u9996\u5730\u5740 256 \u5b57\u8282\u5bf9\u9f50\uff0c\u8fd9\u662f CUDA \u5168\u5c40\u5185\u5b58\u8bbf\u95ee\u7684\u6700\u4f73\u5b9e\u8df5\u3002<\/li>\n\n\n\n<li><strong>C \u901a\u9053\u5bf9\u9f50<\/strong> \u4e3b\u8981\u5bf9 FP16 \u8f93\u5165\u7f13\u51b2\uff084\uff09\u3001FP16 \u7279\u5f81\u56fe\/\u68af\u5ea6\u69fd\uff088\uff09\u751f\u6548\uff1b<code>S_MASK<\/code> \u533a\u57df\u7684 INT8 \u5f20\u91cf\u5728 CUDA \u8def\u5f84\u4e0b\u4e5f\u5bf9\u9f50\u5230 8\u3002\u5176\u4f59\u60c5\u5f62\uff08\u5c24\u5176\u662f FP32 \u4e0e CPU \u8def\u5f84\uff09\u4fdd\u6301\u7d27\u51d1\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u7ea6\u675f\u5355\u72ec\u770b\u6709\u4e9b\u201c\u5947\u602a\u201d\uff0c\u4f46\u7ec4\u5408\u5728\u4e00\u8d77\u5c31\u5f62\u6210\u4e86\u4e00\u5957\u4e25\u683c\u800c\u4e00\u81f4\u7684\u5185\u5b58\u5951\u7ea6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001MemoryPlan\uff1a\u4e00\u904d\u7ebf\u6027\u7d2f\u52a0\u5e03\u5c40\u5f15\u64ce<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>MemoryPlan<\/code> \u662f\u663e\u5b58\u5e03\u5c40\u7684\u552f\u4e00\u6743\u5a01\uff0c\u5b9a\u4e49\u5728 <code>include\/renaissance\/graph\/memory_plan.h<\/code>\u3002\u5b83\u7684\u6838\u5fc3\u7b97\u6cd5\u975e\u5e38\u7b80\u5355\uff1a\u6309 Region \u987a\u5e8f\u4ece <code>B_PREV_MEAN<\/code> \u8d70\u5230\u6700\u540e\u4e00\u4e2a\u69fd\u4f4d\uff0c\u5728\u6bcf\u4e2a Region \u5185\u90e8\u6309\u5206\u914d\u987a\u5e8f\u628a <code>DTensor<\/code> \u7684 slot \u7d2f\u52a0\u8d77\u6765\uff0c<code>finalize()<\/code> \u65f6\u4e00\u6b21\u6027\u5199\u5165\u6240\u6709 offset\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MemoryPlan::finalize() {\n    TR_CHECK(!finalized_, ValueError, \"MemoryPlan already finalized\");\n    validate_config();\n\n    uint64_t cursor = 0;\n\n    \/\/ \u7ebf\u6027\u904d\u5386\u6240\u6709 Region \u69fd\u4f4d\n    for (size_t ri = 0;\n         ri &lt; static_cast&lt;size_t>(Region::NUM_REGIONS);\n         ++ri) {\n        auto&amp; info = region_infos_[ri];\n        info.base_offset = cursor;\n\n        for (int32_t dt_id : region_dt_ids_[ri]) {\n            auto&amp; entry = entries_[id_to_idx_.at(dt_id)];\n            entry.dt.offset_ = cursor;\n            cursor += entry.dt.slot_bytes();\n        }\n\n        info.total_bytes = cursor - info.base_offset;\n    }\n\n    total_bytes_ = cursor;\n\n    validate_region_order();\n    validate_contiguity();\n    validate_layer_correspondence();\n    validate_alignment();\n\n    finalized_ = true;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u903b\u8f91\u5f88\u7b80\u5355\uff1a\u7ef4\u62a4\u4e00\u4e2a <code>cursor<\/code> \u6e38\u6807\uff0c\u4ece 0 \u5f00\u59cb\u4f9d\u6b21\u8d70\u8fc7\u6bcf\u4e2a Region\u3002\u6bcf\u4e2a Region \u5185\u90e8\uff0c\u6309\u5206\u914d\u987a\u5e8f\u6392\u5217\u8be5 Region \u4e2d\u7684\u6240\u6709 <code>DTensor<\/code>\u3002\u6bcf\u4e2a <code>DTensor<\/code> \u7684 <code>offset_<\/code> \u88ab\u8d4b\u503c\u4e3a\u5f53\u524d\u7684 <code>cursor<\/code>\uff0c\u7136\u540e <code>cursor<\/code> \u524d\u79fb <code>slot_bytes()<\/code> \u4e2a\u5b57\u8282\u3002\u8d70\u5b8c\u6240\u6709 Region \u540e\uff0c<code>total_bytes_<\/code> \u5c31\u662f\u603b\u663e\u5b58\u9700\u6c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u7b97\u6cd5\u4e4b\u6240\u4ee5\u6210\u7acb\uff0c\u662f\u56e0\u4e3a<strong>\u6240\u6709\u5206\u914d\u90fd\u5728 <code>finalize()<\/code> \u4e4b\u524d\u5b8c\u6210<\/strong>\u3002\u5728 <code>PLANNING<\/code> \u9636\u6bb5\uff0cArchPlan \u548c Compiler \u4f1a\u904d\u5386\u6240\u6709\u9700\u8981\u5206\u914d\u7684\u5f20\u91cf\uff0c\u901a\u8fc7 <code>MemoryPlan<\/code> \u7684\u8bed\u4e49\u5316\u5206\u914d\u63a5\u53e3\u6ce8\u518c\u5230\u5bf9\u5e94\u7684 Region \u4e2d\u3002<code>finalize()<\/code> \u4e00\u65e6\u8c03\u7528\uff0c\u5e03\u5c40\u5c31\u6c38\u4e45\u9501\u5b9a\uff0c\u4e4b\u540e\u4e0d\u80fd\u518d\u5206\u914d\u4efb\u4f55\u65b0\u5f20\u91cf\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>MemoryPlan<\/code> \u63d0\u4f9b\u4e86\u8bed\u4e49\u5316\u7684\u5206\u914d\u63a5\u53e3\uff0c\u6bd4\u5982 <code>alloc_bn_stats<\/code>\u3001<code>alloc_fc_weight<\/code>\u3001<code>alloc_momentum_first_conv<\/code> \u7b49\u3002\u8fd9\u4e9b\u63a5\u53e3\u5185\u90e8\u786c\u7f16\u7801\u4e86\u5bf9\u5e94\u7684 Region\uff0c\u675c\u7edd\u4e86\u201c\u628a BN \u504f\u7f6e\u653e\u5230\u6743\u91cd\u533a\u201d\u8fd9\u79cd\u9519\u8bef\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DTensor MemoryPlan::alloc_fc_weight(const Shape&amp; shape) {\n    return alloc_impl(shape, DType::FP32, Region::W_FC_WEIGHT);\n}\n\nDTensor MemoryPlan::alloc_momentum_first_conv(const Shape&amp; shape) {\n    return alloc_impl(shape, DType::FP32, Region::M_FIRST_CONV);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86\u9488\u5bf9\u6a21\u578b\u53c2\u6570\u7684\u8bed\u4e49\u63a5\u53e3\uff0c<code>MemoryPlan<\/code> \u8fd8\u63d0\u4f9b\u4e86 <code>alloc_baseline_dtensors()<\/code>\uff0c\u4e00\u6b21\u6027\u5206\u914d\u6240\u6709\u8bad\u7ec3\u57fa\u7840\u8bbe\u65bd\u5f20\u91cf\uff1a\u8f93\u5165\u53cc\u7f13\u51b2 <code>I_A_LABEL\/I_A_DATA\/I_B_LABEL\/I_B_DATA<\/code>\u3001SoftmaxCE \u4e13\u7528\u7684\u4e34\u65f6\u6807\u7b7e\u533a\u3001\u5b66\u4e60\u7387\/loss\/top1\/top5\/NaN \u6807\u5fd7\u7b49\u6807\u91cf\u3001\u4ee5\u53ca\u5404\u4f18\u5316\u5668\u9700\u8981\u7684 beta\/beta2\/weight decay \u7b49\u3002\u8fd9\u4e9b\u5f20\u91cf\u62e5\u6709\u56fa\u5b9a\u7684 <code>BaselineIds<\/code>\uff0c\u8fd0\u884c\u65f6\u53ef\u4ee5\u6309 ID \u76f4\u63a5\u7d22\u5f15\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u54ea\u4e9b Region \u4f1a\u771f\u6b63\u88ab\u542f\u7528\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e76\u4e0d\u662f\u6240\u6709 68 \u4e2a\u8bed\u4e49 Region \u5728\u6bcf\u6b21\u8bad\u7ec3\u91cc\u90fd\u4f1a\u542f\u7528\u3002<code>MemoryPlan<\/code> \u901a\u8fc7 <code>is_condition_enabled()<\/code> \u65b9\u6cd5\uff0c\u6839\u636e <code>PlanConfig<\/code> \u548c <code>GlobalRegistry<\/code> \u4e2d\u7684\u5168\u5c40\u914d\u7f6e\u51b3\u5b9a\u67d0\u4e2a Region \u662f\u5426\u5141\u8bb8\u5206\u914d\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Region<\/th><th>\u542f\u7528\u6761\u4ef6<\/th><\/tr><\/thead><tbody><tr><td><code>W_EQ_BIAS<\/code>\u3001<code>W_EQ_SCALE<\/code><\/td><td><code>PlanConfig::bn_folded == true<\/code>\uff08CBR \u878d\u5408\u5c06 BN \u6298\u53e0\u8fdb\u5377\u79ef\u540e\u4ea7\u751f\u7684\u7b49\u4ef7\u53c2\u6570\uff09<\/td><\/tr><tr><td><code>E_BN_BIAS<\/code> \u2026 <code>E_DEEP_CONV<\/code>\uff08FP32 EMA\uff09<\/td><td><code>PlanConfig::has_ema == true<\/code><\/td><\/tr><tr><td><code>E_FC_WEIGHT_FP16<\/code> \u2026 <code>E_DEEP_CONV_FP16<\/code><\/td><td><code>has_ema == true<\/code> \u4e14 AMP \u5f00\u542f<\/td><\/tr><tr><td><code>A_FC_WEIGHT<\/code> \u2026 <code>A_DEEP_CONV<\/code><\/td><td>AMP \u5f00\u542f<\/td><\/tr><tr><td><code>G_FC_WEIGHT_FP16<\/code> \u2026 <code>G_DEEP_CONV_FP16<\/code><\/td><td>AMP \u5f00\u542f<\/td><\/tr><tr><td><code>F_FEATURE_FP32<\/code>\u3001<code>F_GRAD_SLOT_FP32<\/code><\/td><td>AMP \u5173\u95ed<\/td><\/tr><tr><td><code>F_FEATURE_FP16<\/code>\u3001<code>F_GRAD_SLOT_FP16<\/code><\/td><td>AMP \u5f00\u542f<\/td><\/tr><tr><td><code>S_SCALAR_FP16<\/code><\/td><td>AMP \u5f00\u542f<\/td><\/tr><tr><td><code>M_<\/code> \/ <code>V_<\/code> \/ <code>N_<\/code> \u7cfb\u5217<\/td><td>\u901a\u5e38\u59cb\u7ec8\u542f\u7528\uff0c\u4f46 <code>validate_layer_correspondence<\/code> \u4f1a\u6839\u636e\u5b9e\u9645\u4f18\u5316\u5668\u7c7b\u578b\u68c0\u67e5\u6570\u91cf\u662f\u5426\u5339\u914d<\/td><\/tr><tr><td><code>I_<\/code> \/ <code>S_MASK<\/code> \/ <code>T_<\/code> \u7cfb\u5217<\/td><td>\u59cb\u7ec8\u542f\u7528<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5957\u6761\u4ef6\u673a\u5236\u8ba9 <code>MemoryPlan<\/code> \u65e2\u80fd\u8986\u76d6 SGD\u3001AdamW\u3001LARS \u7b49\u4e0d\u540c\u4f18\u5316\u5668\uff0c\u4e5f\u80fd\u5728 FP32 \u4e0e AMP \u6a21\u5f0f\u4e4b\u95f4\u5207\u6362\uff0c\u800c\u4e0d\u9700\u8981\u4e3a\u6bcf\u79cd\u7ec4\u5408\u5199\u72ec\u7acb\u7684\u5e03\u5c40\u4ee3\u7801\u3002\u88ab\u5173\u95ed\u7684 Region \u5728 <code>finalize()<\/code> \u65f6\u4f1a\u81ea\u7136\u53d8\u6210\u7a7a\u533a\uff08<code>total_bytes == 0<\/code>\uff09\uff0c\u540e\u7eed RangeOp \u4e5f\u4f1a\u901a\u8fc7 <code>is_region_populated()<\/code> \u8df3\u8fc7\u5b83\u4eec\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u8de8\u53d8\u4f53\u4e00\u81f4\u6027\uff1a\u4e3a\u4ec0\u4e48\u540c\u4e00\u5f20\u56fe\u80fd\u670d\u52a1\u591a\u4e2a\u5206\u8fa8\u7387<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 <code>Compiler::compile()<\/code> \u7684\u7b2c\u4e09\u9636\u6bb5 <code>create_memory_plans<\/code> \u4e2d\uff0c\u6211\u4eec\u4f1a\u4e3a 6 \u4e2a\u53d8\u4f53\uff08<code>train_base<\/code>\u3001<code>train_last<\/code>\u3001<code>train_lowres<\/code>\u3001<code>train_lowres_last<\/code>\u3001<code>val_base<\/code>\u3001<code>val_last<\/code>\uff09\u5206\u522b\u521b\u5efa\u72ec\u7acb\u7684 <code>MemoryPlan<\/code>\u3002\u8fd9\u4e9b\u53d8\u4f53\u53ef\u80fd\u6709\u4e0d\u540c\u7684 batch size \u6216\u5206\u8fa8\u7387\uff0c\u56e0\u6b64\u540c\u4e00\u4e2a\u903b\u8f91\u5f20\u91cf\u5728\u4e0d\u540c\u53d8\u4f53\u4e2d\u7684\u5f62\u72b6\u53ef\u80fd\u4e0d\u540c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u8fd9\u91cc\u6709\u4e00\u4e2a\u5173\u952e\u8981\u6c42\uff1a<strong>\u540c\u4e00\u4e2a <code>DTensor<\/code> ID \u5728\u4e0d\u540c\u53d8\u4f53\u4e2d\u5fc5\u987b\u6709\u76f8\u540c\u7684 offset<\/strong>\u3002\u5426\u5219\uff0c\u96f6\u5f62\u72b6\u7684 <code>ComputationGraph<\/code> \u5c31\u65e0\u6cd5\u590d\u7528\u2014\u2014\u56fe\u8282\u70b9\u91cc\u53ea\u5b58\u4e86 <code>DTensor<\/code> ID\uff0c\u5982\u679c ID \u76f8\u540c\u4f46 offset \u4e0d\u540c\uff0c\u56fe\u7684\u91cd\u653e\u5c31\u4f1a\u51fa\u9519\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c<code>Compiler<\/code> \u5728\u7b2c\u4e8c\u9636\u6bb5 <code>compute_max_slot_bytes<\/code> \u4e2d\u4f1a\u5bf9\u6bcf\u4e2a <code>(layer, tensor)<\/code> \u4f4d\u7f6e\u8de8\u6240\u6709\u53d8\u4f53\u53d6\u6700\u5927\u7684 <code>slot_bytes<\/code>\u3002\u7b2c\u4e09\u9636\u6bb5\u5206\u914d\u65f6\uff0c\u628a\u8fd9\u4e2a\u6700\u5927\u503c\u4f20\u7ed9 <code>MemoryPlan<\/code> \u7684\u79c1\u6709\u91cd\u8f7d\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DTensor MemoryPlan::alloc(const Shape&amp; shape, DType dtype,\n                          Region region, uint64_t slot_bytes);<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void Compiler::compute_max_slot_bytes(\n    const std::vector&lt;std::vector&lt;std::vector&lt;TensorDesc>>>&amp; all_shapes,\n    std::vector&lt;std::vector&lt;uint64_t>>&amp; max_slots)\n{\n    size_t num_layers = all_shapes[0].size();\n    max_slots.resize(num_layers);\n\n    for (size_t l = 0; l &lt; num_layers; ++l) {\n        size_t num_tensors = all_shapes[0][l].size();\n        max_slots[l].resize(num_tensors, 0);\n\n        for (size_t t = 0; t &lt; num_tensors; ++t) {\n            uint64_t max_bytes = 0;\n            for (size_t s = 0; s &lt; all_shapes.size(); ++s) {\n                const auto&amp; desc = all_shapes[s][l][t];\n                max_bytes = std::max(max_bytes,\n                    DTensor::compute_slot_bytes(desc.shape, desc.dtype, desc.region));\n            }\n            max_slots[l][t] = max_bytes;\n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\uff0c\u5373\u4f7f\u67d0\u4e2a\u53d8\u4f53\u7684\u5b9e\u9645 shape \u6bd4\u8f83\u5c0f\uff0c\u5b83\u4ecd\u7136\u5360\u636e\u6700\u5927\u7684\u69fd\u4f4d\uff0c\u4ece\u800c\u4fdd\u8bc1\u6240\u6709\u53d8\u4f53\u7684 offset \u5b8c\u5168\u4e00\u81f4\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u7684\u4ee3\u4ef7\u662f\u5c11\u91cf\u5185\u5b58\u6d6a\u8d39\u2014\u2014\u5c0f\u53d8\u4f53\u7528\u4e86\u5927\u53d8\u4f53\u7684\u69fd\u4f4d\u2014\u2014\u4f46\u6362\u6765\u7684\u662f\u56fe\u62d3\u6251\u7684\u5b8c\u5168\u5171\u4eab\uff0c\u4ee5\u53ca CUDA Graph \u6355\u83b7\u7684\u7a33\u5b9a\u6027\u3002\u5bf9\u4e8e\u8bad\u7ec3\u6846\u67b6\u6765\u8bf4\uff0c\u8fd9\u662f\u4e00\u7b14\u975e\u5e38\u5212\u7b97\u7684\u4e70\u5356\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001\u5185\u5b58\u590d\u7528\uff1a\u751f\u547d\u5468\u671f\u7ba1\u7406\u7684\u827a\u672f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u6001\u5206\u914d\u5668\u9700\u8981\u5783\u573e\u56de\u6536\u6216\u5f15\u7528\u8ba1\u6570\u6765\u56de\u6536\u4e0d\u518d\u4f7f\u7528\u7684\u5185\u5b58\u3002<code>MemoryPlan<\/code> \u4e0d\u9700\u8981\uff0c\u56e0\u4e3a\u5b83\u5728\u7f16\u8bd1\u671f\u5c31\u77e5\u9053\u4e86\u6bcf\u4e2a\u5f20\u91cf\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\u3002\u4e0d\u8fc7\uff0c\u5b83\u4ecd\u7136\u53ef\u4ee5\u505a\u4e00\u79cd\u7f16\u8bd1\u671f\u7684\u3001\u5b89\u5168\u7684\u5185\u5b58\u590d\u7528\uff1a<strong>\u7279\u5f81\u56fe\u533a\u548c\u68af\u5ea6\u69fd\u533a\u7684\u590d\u7528<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\uff0c\u524d\u5411\u4f20\u64ad\u4ea7\u751f\u7684\u4e2d\u95f4\u7279\u5f81\u56fe\u9700\u8981\u5728\u53cd\u5411\u4f20\u64ad\u65f6\u4f7f\u7528\uff0c\u56e0\u6b64\u524d\u5411\u7279\u5f81\u56fe\u4e0d\u80fd\u7acb\u5373\u91ca\u653e\u3002<code>MemoryPlan<\/code> \u901a\u8fc7 <code>F_FEATURE_FP32\/F_FEATURE_FP16<\/code> \u533a\u57df\u5b58\u50a8\u524d\u5411\u7279\u5f81\u56fe\uff0c\u901a\u8fc7 <code>F_GRAD_SLOT_FP32\/F_GRAD_SLOT_FP16<\/code> \u533a\u57df\u5b58\u50a8\u53cd\u5411\u4f20\u64ad\u7684\u68af\u5ea6\u4e2d\u95f4\u7ed3\u679c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u952e\u5728\u4e8e\uff0c<strong>\u8fd9\u4e9b\u4e34\u65f6\u5b58\u50a8\u662f\u56fa\u5b9a\u5927\u5c0f\u7684\u69fd\u4f4d\uff0c\u800c\u4e0d\u662f\u52a8\u6001\u5206\u914d\u7684\u5806<\/strong>\u3002<code>MemoryPlan::alloc_grad_slot()<\/code> \u6700\u591a\u652f\u6301 4 \u4e2a\u68af\u5ea6\u69fd\uff08<code>slot_idx<\/code> \u53d6 0\u20133\uff09\u3002\u5982\u679c\u8bf7\u6c42\u7684\u69fd\u4f4d\u5df2\u7ecf\u88ab\u540c\u5f62\u72b6\u3001\u540c\u7c7b\u578b\u7684\u5f20\u91cf\u5360\u7528\uff0c\u5c31\u76f4\u63a5\u8fd4\u56de\u5df2\u6709\u7684 <code>DTensor<\/code>\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DTensor MemoryPlan::alloc_grad_slot(const Shape&amp; shape, DType dtype, int slot_idx) {\n    TR_CHECK(slot_idx >= 0 &amp;&amp; slot_idx &lt; 4, IndexError,\n             \"slot_idx=\" &lt;&lt; slot_idx);\n\n    int32_t existing = grad_slot_ids_[slot_idx];\n    if (existing >= 0) {\n        const auto&amp; dt = get_dtensor(existing);\n        TR_CHECK(dt.dtype == dtype, ValueError, \"dtype mismatch\");\n        TR_CHECK(dt.shape == shape, ShapeError, \"shape mismatch\");\n        return dt;   \/\/ \u590d\u7528\u5df2\u6709\u69fd\u4f4d\n    }\n\n    Region region = (dtype == DType::FP16)\n                        ? Region::F_GRAD_SLOT_FP16\n                        : Region::F_GRAD_SLOT_FP32;\n    DTensor dt = alloc_impl(shape, dtype, region);\n    grad_slot_ids_[slot_idx] = dt.id;\n    return dt;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u8bbe\u8ba1\u8ba9 <code>MemoryPlan<\/code> \u65e2\u80fd\u4fdd\u8bc1\u663e\u5b58\u4e0d\u8d85\u9650\uff0c\u53c8\u4e0d\u9700\u8981\u8fd0\u884c\u65f6\u7684\u5783\u573e\u56de\u6536\u3002\u5b83\u4e0d\u9700\u8981\u8ffd\u8e2a\u201c\u8fd9\u4e2a\u5f20\u91cf\u662f\u5426\u8fd8\u5728\u4f7f\u7528\u201d\uff0c\u56e0\u4e3a\u7f16\u8bd1\u671f\u5df2\u7ecf\u628a\u6240\u6709\u751f\u547d\u5468\u671f\u7684\u91cd\u53e0\u5173\u7cfb\u90fd\u5206\u6790\u6e05\u695a\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001RangeOp\uff1a\u65e0\u89c6\u5f20\u91cf\u8fb9\u754c\u7684\u6279\u91cf\u64cd\u4f5c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u9759\u6001\u5206\u533a\u5e26\u6765\u7684\u6700\u5927\u7ea2\u5229\u4e4b\u4e00\uff0c\u662f\u53ef\u4ee5\u505a\u201cRegion \u7ea7\u6279\u91cf\u64cd\u4f5c\u201d\uff0c\u4e5f\u5c31\u662f <code>RangeOp<\/code>\u3002\u5728 <code>ComputationGraph<\/code> \u4e2d\uff0c\u8282\u70b9\u53ef\u4ee5\u662f <code>COMPUTE<\/code>\uff08\u5355\u4e2a <code>DTensor<\/code> \u7ea7\uff09\uff0c\u4e5f\u53ef\u4ee5\u662f <code>RANGE<\/code>\uff08\u8fde\u7eed\u5185\u5b58\u8303\u56f4\u7ea7\uff09\u3002<code>RangeOp<\/code> \u4e0d\u64cd\u4f5c\u5355\u4e2a\u5f20\u91cf\uff0c\u800c\u64cd\u4f5c\u4e00\u6bb5\u8fde\u7eed\u7684\u5185\u5b58\u8303\u56f4\uff0c\u8303\u56f4\u7531 <code>(start_region, end_region)<\/code> \u51b3\u5b9a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>RangeOp<\/code> \u7684\u5b9a\u4e49\u5728 <code>include\/renaissance\/graph\/op_kind.h<\/code> \u4e2d\uff0c\u4e3b\u8981\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>H2D \u4f20\u8f93<\/strong>\uff1a<code>RANGE_H2D_COPY_A<\/code>\u3001<code>RANGE_H2D_COPY_B<\/code>\u3001<code>RANGE_H2D_COPY_DTENSOR<\/code><\/li>\n\n\n\n<li><strong>BN \u7edf\u8ba1\u91cf\u901a\u4fe1<\/strong>\uff1a<code>RANGE_BN_STATS_ALLREDUCE<\/code><\/li>\n\n\n\n<li><strong>\u4f18\u5316\u5668 Bias \u5757<\/strong>\uff1a<code>RANGE_UPDATE_BIAS_SGD<\/code>\u3001<code>RANGE_UPDATE_BIAS_MOMENTUM<\/code>\u3001<code>RANGE_UPDATE_BIAS_NESTEROV<\/code>\u3001<code>RANGE_UPDATE_BIAS_ADAM<\/code><\/li>\n\n\n\n<li><strong>\u4f18\u5316\u5668 Weight \u5757<\/strong>\uff1a<code>RANGE_UPDATE_WEIGHT_SGD<\/code>\u3001<code>RANGE_UPDATE_WEIGHT_MOMENTUM<\/code>\u3001<code>RANGE_UPDATE_WEIGHT_NESTEROV<\/code>\u3001<code>RANGE_UPDATE_WEIGHT_ADAM<\/code>\u3001<code>RANGE_UPDATE_WEIGHT_ADAMW<\/code><\/li>\n\n\n\n<li><strong>EMA \u7ef4\u62a4<\/strong>\uff1a<code>RANGE_EMA_PARAM_UPDATE<\/code>\u3001<code>RANGE_SEMA_SWITCH<\/code><\/li>\n\n\n\n<li><strong>\u901a\u7528\u5185\u5b58\u64cd\u4f5c<\/strong>\uff1a<code>RANGE_CLEAR<\/code>\u3001<code>RANGE_D2D_COPY<\/code><\/li>\n\n\n\n<li><strong>\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1a<code>RANGE_CAST_FP32_TO_FP16<\/code>\u3001<code>RANGE_CAST_FP16_TO_FP32<\/code><\/li>\n\n\n\n<li><strong>\u901a\u4fe1<\/strong>\uff1a<code>RANGE_SUM_ALLREDUCE<\/code>\u3001<code>RANGE_MEAN_ALLREDUCE<\/code><\/li>\n\n\n\n<li><strong>NaN \u68c0\u67e5\u4e0e\u6307\u6807<\/strong>\uff1a<code>RANGE_CHECK_NAN<\/code>\u3001<code>RANGE_GRAD_SCALING<\/code>\u3001<code>RANGE_ACCUM_METRICS<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u8bad\u7ec3\u524d\u7684\u68af\u5ea6\u6e05\u96f6\u53ef\u4ee5\u4e00\u6b21\u6027\u8986\u76d6\u6574\u4e2a\u68af\u5ea6\u533a\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">GraphNode zg_node;\nzg_node.kind = GraphNode::Kind::RANGE;\nzg_node.range_op = RangeOp::RANGE_CLEAR;\nzg_node.output_ranges.push_back(\n    memory_plan.region_range(Region::G_BN_BIAS,\n                             Region::G_DEEP_CONV_FP16));\ntrain_cg.append(GraphId::ZERO_GRAD, zg_node);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u6bd4\u5982\u4f18\u5316\u5668\u66f4\u65b0\u3002\u4f20\u7edf\u6846\u67b6\u91cc\uff0c\u4f18\u5316\u5668\u9700\u8981\u904d\u5386\u6bcf\u4e2a\u53c2\u6570\uff0c\u9010\u4e2a\u8c03\u7528 kernel \u66f4\u65b0\u6743\u91cd\u548c\u52a8\u91cf\u3002Tech-Renaissance \u628a\u540c\u7c7b\u578b\u7684\u6743\u91cd\u3001\u68af\u5ea6\u3001\u52a8\u91cf\u8fde\u7eed\u5b58\u653e\uff0c\u4e8e\u662f\u6743\u91cd\u66f4\u65b0\u53ef\u4ee5\u7528\u4e00\u4e2a <code>RangeOp<\/code> \u4e00\u6b21\u6027\u5b8c\u6210\u6574\u533a\u66f4\u65b0\u3002\u4ee5 AdamW \u4e3a\u4f8b\uff0cCompiler \u4f1a\u6784\u9020\u4e00\u4e2a\u8986\u76d6 <code>W_FC_WEIGHT<\/code> \u5230 <code>W_DEEP_CONV<\/code>\u3001\u5bf9\u5e94 <code>G_<\/code>\/<code>M_<\/code>\/<code>V_<\/code> \u8303\u56f4\u7684 RANGE \u8282\u70b9\uff0c\u5728\u4e00\u4e2a kernel \u91cc\u5b8c\u6210\u5168\u6a21\u578b\u53ef\u8bad\u7ec3\u6743\u91cd\u7684\u66f4\u65b0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b <code>RangeOp<\/code> \u7684\u5171\u540c\u7279\u70b9\u662f\uff1a<strong>\u5b83\u4eec\u4e0d\u611f\u77e5\u5f20\u91cf\u8fb9\u754c\uff0c\u53ea\u6309 Region \u8303\u56f4\u64cd\u4f5c<\/strong>\u3002\u7531\u4e8e\u540c Region \u7684\u5f20\u91cf\u5728\u7269\u7406\u4e0a\u8fde\u7eed\uff0c\u4e00\u4e2a kernel \u5c31\u80fd\u5b8c\u6210\u5168\u6a21\u578b\u540c\u7c7b\u578b\u5f20\u91cf\u7684\u5904\u7406\uff0c\u7701\u53bb\u4e86\u5927\u91cf\u5c0f kernel \u7684 launch \u5f00\u9500\u3002\u6240\u6709\u8303\u56f4\u5728\u7f16\u8bd1\u671f\u5199\u6210 Region ID\uff0c\u5728 CUDA Graph \u6355\u83b7\u65f6\u901a\u8fc7 <code>resolve_region_bounds()<\/code> \u89e3\u6790\u4e3a <code>(offset, size)<\/code>\uff0c\u8fd0\u884c\u65f6\u96f6\u67e5\u8868\u5f00\u9500\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u3001\u5e03\u5c40\u9501\u6b7b\u540e\u7684\u56db\u7ec4\u6821\u9a8c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>MemoryPlan::finalize()<\/code> \u5728\u5199\u5165\u6240\u6709 offset \u4e4b\u540e\u4f1a\u6267\u884c\u56db\u7ec4\u6821\u9a8c\u3002\u5b83\u4eec\u4e0d\u662f\u9632\u5fa1\u6027\u7f16\u7a0b\u7684\u70b9\u7f00\uff0c\u800c\u662f\u9759\u6001\u56fe\u6b63\u786e\u6027\u7684\u57fa\u77f3\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Region \u987a\u5e8f\u6821\u9a8c\uff08<code>validate_region_order<\/code>\uff09<\/strong>\uff1a\u786e\u4fdd\u5404 Region \u7684 <code>base_offset<\/code> \u6309\u679a\u4e3e\u987a\u5e8f\u4e25\u683c\u975e\u9012\u51cf\u3002\u5982\u679c\u4ee3\u7801\u9519\u8bef\u5730\u628a\u67d0\u4e2a Region \u7684\u5206\u914d\u987a\u5e8f\u63d0\u524d\u6216\u5ef6\u540e\uff0c\u8fd9\u91cc\u4f1a\u7acb\u5373\u62a5\u9519\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. \u8fde\u7eed\u6027\u6821\u9a8c\uff08<code>validate_contiguity<\/code>\uff09<\/strong>\uff1a\u786e\u4fdd\u9700\u8981\u88ab\u540c\u4e00\u4e2a <code>RangeOp<\/code> \u8986\u76d6\u7684 Region \u5728\u7269\u7406\u4e0a\u771f\u6b63\u76f8\u90bb\u3002\u4f8b\u5982 BN \u7edf\u8ba1\u91cf <code>B_PREV_MEAN<\/code> \u5230 <code>B_NEXT_VAR<\/code> \u5fc5\u987b\u8fde\u7eed\uff1b\u68af\u5ea6\u6876 2 <code>G_BN_BIAS<\/code> \u5230 <code>G_FIRST_CONV<\/code> \u5fc5\u987b\u8fde\u7eed\uff1b\u8f93\u5165\u7f13\u51b2\u533a <code>I_A_LABEL<\/code> \u5230 <code>I_B_DATA<\/code> \u5fc5\u987b\u8fde\u7eed\uff1bEMA FP16 \u6743\u91cd <code>E_FC_WEIGHT_FP16<\/code> \u5230 <code>E_DEEP_CONV_FP16<\/code> \u5fc5\u987b\u8fde\u7eed\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. \u5c42\u5bf9\u5e94\u5173\u7cfb\u6821\u9a8c\uff08<code>validate_layer_correspondence<\/code>\uff09<\/strong>\uff1a\u786e\u4fdd\u6743\u91cd\u3001\u68af\u5ea6\u3001\u4e00\u9636\u52a8\u91cf\u3001\u4e8c\u9636\u52a8\u91cf\u8fd9\u51e0\u4e2a\u7cfb\u5217\u4e2d\uff0c\u76f8\u540c\u5c42\u7c7b\u578b\u7684\u5f20\u91cf\u6570\u91cf\u4e00\u81f4\u3002\u4f8b\u5982\u5982\u679c <code>W_FC_WEIGHT + W_FIRST_CONV + W_DEEP_CONV<\/code> \u5171\u6709 <code>w_fp32<\/code> \u4e2a\u5f20\u91cf\uff0c\u90a3\u4e48\u5bf9\u5e94\u7684 FP32 \u68af\u5ea6\u3001AMP FP16 \u68af\u5ea6\uff08\u5982\u679c\u5f00\u542f AMP\uff09\u3001\u4e00\u9636\/\u4e8c\u9636\u52a8\u91cf\u4e5f\u5fc5\u987b\u5404\u6709\u76f8\u540c\u6570\u91cf\u3002LARS \u6a21\u5f0f\u4e0b\u8fd8\u4f1a\u989d\u5916\u68c0\u67e5 <code>N_<\/code> \u7cfb\u5217\u4e0e <code>W_<\/code> \u7cfb\u5217\u7684\u6570\u91cf\u5339\u914d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. \u5bf9\u9f50\u6821\u9a8c\uff08<code>validate_alignment<\/code>\uff09<\/strong>\uff1a\u786e\u4fdd\u6bcf\u4e2a <code>DTensor<\/code> \u7684 offset \u90fd\u662f 256 \u7684\u6574\u6570\u500d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u6821\u9a8c\u628a\u201c\u5f20\u91cf\u653e\u9519\u533a\u201d\u201c\u6570\u91cf\u5bf9\u4e0d\u4e0a\u201d\u201c\u5730\u5740\u6ca1\u5bf9\u9f50\u201d\u7b49\u9519\u8bef\u6321\u5728\u4e86\u8bad\u7ec3\u5f00\u59cb\u4e4b\u524d\u3002\u5728\u9759\u6001\u56fe\u7684\u4e16\u754c\u91cc\uff0c<strong>\u7f16\u8bd1\u671f\u7684\u9519\u8bef\u6bd4\u8fd0\u884c\u671f\u7684\u9519\u8bef\u597d\u6392\u67e5\u4e00\u4e07\u500d<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u4e00\u3001MemoryPlan \u4e0e CUDA Graph\u3001\u5206\u5e03\u5f0f\u3001\u786e\u5b9a\u6027\u8bad\u7ec3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u9759\u6001\u663e\u5b58\u89c4\u5212\u4e0d\u662f\u5b64\u7acb\u5b58\u5728\u7684\uff0c\u5b83\u662f Tech-Renaissance \u591a\u9879\u6838\u5fc3\u80fd\u529b\u7684\u5171\u540c\u5e95\u5ea7\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>CUDA Graph \u5168\u6355\u83b7\u3002<\/strong> CUDA Graph \u8981\u6c42\u6355\u83b7\u671f\u95f4\u6240\u6709\u5f20\u91cf\u5730\u5740\u56fa\u5b9a\uff0c\u4e14\u6355\u83b7\u540e\u4e0d\u80fd\u52a8\u6001\u5206\u914d\u3002<code>MemoryPlan<\/code> \u5728\u7f16\u8bd1\u671f\u5c31\u9501\u5b9a\u4e86\u6240\u6709\u5730\u5740\uff0c<code>ArenaKeeper<\/code> \u5728\u521d\u59cb\u5316\u65f6\u53ea\u5206\u914d\u4e00\u6b21\u663e\u5b58\u6c60\uff0c\u8fd0\u884c\u65f6\u53ea\u901a\u8fc7\u56fa\u5b9a\u504f\u79fb\u8bbf\u95ee\u3002\u56e0\u6b64 Tech-Renaissance \u53ef\u4ee5\u628a H2D \u4f20\u8f93\u3001\u524d\u5411\u3001\u53cd\u5411\u3001\u68af\u5ea6\u901a\u4fe1\u3001\u4f18\u5316\u5668\u66f4\u65b0\u3001BN \u7edf\u8ba1\u91cf\u540c\u6b65\u7b49\u5168\u90e8\u9636\u6bb5\u90fd\u6355\u83b7\u6210 CUDA Graph\uff0c\u800c\u4e0d\u9700\u8981\u50cf PyTorch <code>torch.compile<\/code> \u90a3\u6837\u53cd\u590d\u5904\u7406 graph break \u548c\u5730\u5740\u7a33\u5b9a\u6027\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5206\u5e03\u5f0f\u8bad\u7ec3\u3002<\/strong> \u5728\u591a\u5361\u6570\u636e\u5e76\u884c\u4e2d\uff0c\u6bcf\u5f20\u5361\u90fd\u6301\u6709\u5b8c\u6574\u7684\u6a21\u578b\u526f\u672c\uff0c\u540c\u4e00\u4efd <code>MemoryPlan<\/code> \u53ef\u4ee5\u5728\u6240\u6709 rank \u4e0a\u5171\u4eab\u3002\u56e0\u4e3a\u6bcf\u4e2a <code>DTensor<\/code> \u7684 offset \u5728\u6240\u6709 rank \u4e0a\u4e00\u81f4\uff0c\u68af\u5ea6 AllReduce \u548c BN \u7edf\u8ba1\u91cf\u540c\u6b65\u53ef\u4ee5\u76f4\u63a5\u6309 Region \u8303\u56f4\u53d1\u8d77\uff0c\u4e0d\u9700\u8981\u9010\u5f20\u91cf\u534f\u5546\u5730\u5740\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u786e\u5b9a\u6027\u8bad\u7ec3\u3002<\/strong> \u5f53\u663e\u5b58\u5e03\u5c40\u3001\u5f20\u91cf\u5730\u5740\u3001\u7b97\u5b50\u6267\u884c\u987a\u5e8f\u90fd\u5728\u7f16\u8bd1\u671f\u56fa\u5b9a\u540e\uff0c\u8bad\u7ec3\u7ed3\u679c\u7684\u53ef\u590d\u73b0\u6027\u5c31\u5927\u5927\u63d0\u9ad8\u4e86\u3002\u914d\u5408 Philox \u8ba1\u6570\u5668\u968f\u673a\u6570\u3001\u786e\u5b9a\u6027\u8ba1\u7b97\u5f15\u64ce\u9009\u62e9\u3001\u9759\u6001\u8c03\u5ea6\uff0cTech-Renaissance \u80fd\u591f\u5728\u76f8\u540c\u786c\u4ef6\u548c\u79cd\u5b50\u4e0b\u5f97\u5230\u9ad8\u5ea6\u4e00\u81f4\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u80fd\u529b\u90fd\u4e0d\u662f\u9760\u5355\u70b9\u4f18\u5316\u5b9e\u73b0\u7684\uff0c\u800c\u662f\u9760\u201c\u7f16\u8bd1\u671f\u786e\u5b9a\u4e00\u5207\u201d\u8fd9\u4e2a\u67b6\u6784\u9009\u62e9\u4e32\u8054\u8d77\u6765\u7684\u3002<code>MemoryPlan<\/code> \u5c31\u662f\u8fd9\u4e2a\u9009\u62e9\u7684\u7269\u7406\u843d\u70b9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u4e8c\u3001\u4e0e\u4e3b\u6d41\u6846\u67b6\u7684\u5bf9\u6bd4<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf4\u5230\u8fd9\u91cc\uff0c\u53ef\u80fd\u6709\u4eba\u4f1a\u95ee\uff1aPyTorch \u4e0d\u662f\u4e5f\u80fd\u505a CUDA Graph \u5417\uff1fTensorFlow\/JAX \u7684 XLA \u4e0d\u662f\u4e5f\u4f1a\u505a\u5185\u5b58\u89c4\u5212\u5417\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u662f\u7684\uff0c\u4f46\u5b83\u4eec\u7684\u8def\u5f84\u4e0d\u540c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PyTorch \u7684 CUDA Caching Allocator \u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u8fd0\u884c\u65f6\u6c60\u5316\u5206\u914d\u5668\uff0c\u5b83\u8ffd\u6c42\u7684\u662f\u201c\u5728\u52a8\u6001\u56fe\u7684\u524d\u63d0\u4e0b\u5c3d\u91cf\u51cf\u5c11\u5206\u914d\u5f00\u9500\u201d\u3002\u5b83\u901a\u8fc7\u5404\u79cd\u542f\u53d1\u5f0f\u7b56\u7565\u6765\u7f13\u89e3\u788e\u7247\u548c\u5ef6\u8fdf\uff0c\u4f46\u65e0\u6cd5\u4ece\u6839\u672c\u4e0a\u6d88\u9664\u52a8\u6001\u6027\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48 PyTorch \u5728\u914d\u5408 CUDA Graph \u65f6\u9700\u8981\u989d\u5916\u7684\u673a\u5236\uff08\u5982 private pool\u3001CUDA Graph Trees\uff09\u6765\u4fdd\u8bc1\u5730\u5740\u7a33\u5b9a\uff0c\u800c\u8fd9\u4e9b\u673a\u5236\u5728\u67d0\u4e9b\u590d\u6742\u573a\u666f\u4e0b\u4ecd\u53ef\u80fd\u5931\u6548\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">TensorFlow\/XLA \u548c JAX\/XLA \u786e\u5b9e\u4f1a\u505a\u9759\u6001\u5185\u5b58\u89c4\u5212\uff0c\u56e0\u4e3a XLA \u672c\u8eab\u5c31\u662f\u9759\u6001\u7f16\u8bd1\u5668\u3002\u4f46 XLA \u7684\u5185\u5b58\u89c4\u5212\u66f4\u591a\u662f\u201c\u5728\u5df2\u7ecf\u751f\u6210\u7684 HLO \u56fe\u4e0a\u505a\u5f20\u91cf\u751f\u547d\u5468\u671f\u5206\u6790\u548c\u5185\u5b58\u590d\u7528\u201d\uff0c\u5b83\u7684\u5206\u533a\u8bed\u4e49\u662f\u7f16\u8bd1\u5668\u5185\u90e8\u63a8\u5bfc\u51fa\u6765\u7684\uff0c\u4e0d\u50cf Tech-Renaissance \u8fd9\u6837\u628a <code>Region<\/code> \u4f5c\u4e3a\u6846\u67b6\u4e00\u7ea7\u7684\u663e\u5f0f\u62bd\u8c61\u66b4\u9732\u7ed9\u4f18\u5316\u5668\u3001\u901a\u4fe1\u3001\u521d\u59cb\u5316\u7b49\u6a21\u5757\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tech-Renaissance \u7684\u505a\u6cd5\u4ecb\u4e8e\u4e24\u8005\u4e4b\u95f4\uff0c\u53c8\u6709\u6240\u4e0d\u540c\uff1a\u6211\u4eec\u9009\u62e9\u9759\u6001\u56fe\u4f5c\u4e3a\u6846\u67b6\u7684\u6839\u672c\u8303\u5f0f\uff0c\u7136\u540e\u628a\u663e\u5b58\u6309\u8bed\u4e49\u663e\u5f0f\u5206\u533a\uff0c\u8ba9 <code>Region<\/code> \u6210\u4e3a\u8fde\u63a5\u7f16\u8bd1\u5668\u3001\u8fd0\u884c\u65f6\u3001\u7b97\u5b50\u3001\u4f18\u5316\u5668\u3001\u901a\u4fe1\u6a21\u5757\u7684\u5171\u540c\u8bed\u8a00\u3002\u8fd9\u4e0d\u662f\u8bf4\u5176\u4ed6\u6846\u67b6\u505a\u4e0d\u5230\u67d0\u4e9b\u529f\u80fd\uff0c\u800c\u662f\u8bf4\u6211\u4eec\u628a\u8fd9\u4e9b\u529f\u80fd\u5efa\u7acb\u5728\u4e00\u5957\u7edf\u4e00\u7684\u5185\u5b58\u5951\u7ea6\u4e4b\u4e0a\uff0c\u4ece\u800c\u8ba9\u6574\u4e2a\u7cfb\u7edf\u66f4\u7b80\u5355\u3001\u66f4\u53ef\u9884\u6d4b\u3001\u66f4\u6613\u4e8e\u505a\u5168\u5c40\u6279\u91cf\u4f18\u5316\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5341\u4e09\u3001\u5c0f\u7ed3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>MemoryPlan<\/code> \u548c\u663e\u5b58\u5206\u533a\uff0c\u662f Tech-Renaissance \u6846\u67b6\u8bbe\u8ba1\u4e2d\u6700\u6838\u5fc3\u7684\u57fa\u7840\u8bbe\u65bd\u4e4b\u4e00\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u7684\u57fa\u672c\u601d\u60f3\u662f\uff1a<strong>\u663e\u5b58\u4e0d\u5e94\u8be5\u6309\u9700\u52a8\u6001\u5206\u914d\uff0c\u800c\u5e94\u8be5\u6309\u8bed\u4e49\u9759\u6001\u89c4\u5212<\/strong>\u3002\u901a\u8fc7\u628a\u540c\u7c7b\u578b\u7684\u5f20\u91cf\uff08\u6743\u91cd\u3001\u68af\u5ea6\u3001\u52a8\u91cf\u3001BN \u7edf\u8ba1\u91cf\u3001\u8f93\u5165\u7f13\u51b2\u3001\u7279\u5f81\u56fe\u7b49\uff09\u8fde\u7eed\u6392\u5e03\u5728\u4e0d\u540c\u7684 Region \u91cc\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8fd0\u884c\u671f\u96f6\u52a8\u6001\u5206\u914d\uff0c\u6d88\u9664\u5206\u914d\u5ef6\u8fdf\u548c\u788e\u7247\uff1b<\/li>\n\n\n\n<li>\u6240\u6709\u5f20\u91cf\u5730\u5740\u5728\u7f16\u8bd1\u671f\u786e\u5b9a\uff0c\u6ee1\u8db3 CUDA Graph \u5168\u6355\u83b7\u7684\u8981\u6c42\uff1b<\/li>\n\n\n\n<li><code>DTensor<\/code> \u4f5c\u4e3a\u7eaf\u63cf\u8ff0\u7b26\uff0c\u8ba9\u4e00\u5f20 MemoryPlan \u53ef\u4ee5\u5728\u591a\u5361\u3001\u591a\u53d8\u4f53\u4e4b\u95f4\u5171\u4eab\uff1b<\/li>\n\n\n\n<li>\u540c Region \u6279\u91cf\u64cd\u4f5c\uff0c\u628a\u539f\u672c\u9010\u5c42\u9010\u53c2\u6570\u7684\u591a\u4e2a kernel \u5408\u5e76\u6210\u4e00\u4e2a\uff1b<\/li>\n\n\n\n<li>\u8de8\u53d8\u4f53 offset \u4e00\u81f4\uff0c\u8ba9\u96f6\u5f62\u72b6\u8ba1\u7b97\u56fe\u53ef\u4ee5\u771f\u6b63\u5171\u4eab\uff1b<\/li>\n\n\n\n<li>\u591a\u5361\u5e03\u5c40\u4e00\u81f4\uff0c\u8ba9\u5206\u5e03\u5f0f\u8bad\u7ec3\u53ef\u4ee5\u6309 Region \u76f4\u63a5\u901a\u4fe1\uff1b<\/li>\n\n\n\n<li>\u4e25\u683c\u7684\u5e03\u5c40\u6821\u9a8c\uff0c\u628a\u9519\u8bef\u6321\u5728\u8bad\u7ec3\u5f00\u59cb\u4e4b\u524d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e00\u5957\u8bbe\u8ba1\u7684\u4ee3\u4ef7\u662f\u727a\u7272\u4e86\u4e00\u4e9b\u8fd0\u884c\u65f6\u7684\u7075\u6d3b\u6027\uff1a\u4f60\u4e0d\u80fd\u5728\u8bad\u7ec3\u4e2d\u9014\u52a8\u6001\u6539\u53d8\u6a21\u578b\u7ed3\u6784\uff0c\u4e0d\u80fd\u968f\u5fc3\u6240\u6b32\u5730\u63d2\u5165\u65b0\u5f20\u91cf\uff0c\u8c03\u8bd5\u65f6\u4e5f\u5f97\u66f4\u50cf\u7f16\u8bd1 C++ \u7a0b\u5e8f\u90a3\u6837\u201c\u5148\u7f16\u8bd1\u3001\u518d\u8fd0\u884c\u201d\u3002\u4f46\u5bf9\u4e8e\u4e00\u4e2a\u4ee5\u8bad\u7ec3\u541e\u5410\u4e3a\u76ee\u6807\u7684\u751f\u4ea7\u7ea7\u6846\u67b6\u6765\u8bf4\uff0c\u8fd9\u662f\u503c\u5f97\u63a5\u53d7\u7684 trade-off\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u4e00\u7bc7\uff0c\u6211\u4eec\u4f1a\u4ece <code>MemoryPlan<\/code> \u8fdb\u4e00\u6b65\u4e0b\u6c89\uff0c\u4e13\u95e8\u8bb2 <code>DTensor<\/code>\uff1a\u8fd9\u4e2a\u201c\u4e0d\u6301\u6709\u5185\u5b58\u201d\u7684\u63cf\u8ff0\u7b26\uff0c\u5982\u4f55\u6210\u4e3a\u5206\u5e03\u5f0f\u8bad\u7ec3\u4e2d\u201c\u4e00\u5f20\u56fe\u7eb8\uff0c\u516b\u5361\u5171\u4eab\u201d\u7684\u5173\u952e\u62bd\u8c61\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u2014\u2014\u201c\u4e00\u4e2a\u4eba\u7528AI\u5982\u4f55\u5199\u51fa\u6bd4PyTorch\u66f4\u5feb\u7684\u81ea\u7814\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u201d\u7cfb\u5217\u6587\u7ae0\u4e4b\u5341\u4e94 \u4e0a\u4e00\u7bc7\u6211\u4eec\u8bb2\u4e86 Comput [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":698,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[15],"tags":[],"class_list":["post-511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-15"],"_links":{"self":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":3,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"predecessor-version":[{"id":720,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/511\/revisions\/720"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/media\/698"}],"wp:attachment":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}