{"id":505,"date":"2026-07-08T03:03:33","date_gmt":"2026-07-07T19:03:33","guid":{"rendered":"https:\/\/tech-renaissance.cn\/blog\/?p=505"},"modified":"2026-07-08T22:08:43","modified_gmt":"2026-07-08T14:08:43","slug":"computationgraph%e4%b8%8egraphatlas%ef%bc%9a%e4%b8%80%e4%bb%bd%e5%9b%be%e7%ba%b8%ef%bc%8c%e5%a4%9a%e5%a4%84%e5%a4%8d%e7%94%a8","status":"publish","type":"post","link":"https:\/\/tech-renaissance.cn\/blog\/index.php\/2026\/07\/08\/505\/","title":{"rendered":"(14) ComputationGraph\u4e0eGraphAtlas\uff1a\u4e00\u4efd\u56fe\u7eb8\uff0c\u591a\u5904\u590d\u7528"},"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\u56db<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u524d\u4e00\u7bc7\u6587\u7ae0\u91cc\uff0c\u6211\u4eec\u6cbf\u7740 ArchPlan \u4e0e\u7f16\u8bd1\u7ba1\u7ebf\u8d70\u5b8c\u4e86\u4ece BluePrint \u5230 LayerDescriptor \u7684\u53d8\u6362\u3002\u63a5\u4e0b\u6765 compiler \u8fd8\u8981\u505a\u4e00\u4ef6\u66f4\u91cd\u8981\u7684\u4e8b\uff1a\u628a\u8fd9\u4e9b\u63cf\u8ff0\u7f16\u8bd1\u6210<strong>\u53ef\u4ee5\u88ab GPU \u53cd\u590d\u6267\u884c\u7684\u8ba1\u5212<\/strong>\u3002\u8fd9\u4efd\u8ba1\u5212\u4e0d\u662f\u4e00\u5f20\u201c\u5927\u7f51\u201d\u4ece\u5934\u8dd1\u5230\u5c3e\uff0c\u800c\u662f\u88ab\u5207\u6210\u4e86\u8bb8\u591a\u6bb5\u2014\u2014H2D \u4f20\u8f93\u3001\u9996\u5c42\u524d\u5411\u3001\u6df1\u5c42\u524d\u53cd\u5411\u3001\u68af\u5ea6\u901a\u4fe1\u3001\u4f18\u5316\u5668\u66f4\u65b0\u3001BN \u7edf\u8ba1\u91cf\u540c\u6b65\u3001\u9a8c\u8bc1\u63a8\u7406\u2026\u2026\u6bcf\u4e00\u6bb5\u90fd\u53ef\u80fd\u56e0\u4e3a\u8f93\u5165\u5f62\u72b6\u4e0d\u540c\u800c\u9700\u8981\u4e0d\u540c\u7684 CUDA Graph\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u4e00\u4efd\u6a21\u578b\uff0c\u4e3a\u4ec0\u4e48\u9700\u8981\u90a3\u4e48\u591a\u5f20\u56fe\uff1f\u7b54\u6848\u5f88\u7b80\u5355\uff1a\u56e0\u4e3a\u8bad\u7ec3\u4e0d\u662f\u5355\u4e00\u573a\u666f\u3002\u4e00\u4e2a epoch \u91cc\u666e\u901a batch \u548c\u6700\u540e\u4e00\u4e2a\u4e0d\u5b8c\u6574\u7684 batch \u5f62\u72b6\u4e0d\u540c\uff1b\u6e10\u8fdb\u5f0f\u5206\u8fa8\u7387\u8bad\u7ec3\u4f1a\u8ba9\u524d\u671f\u548c\u540e\u671f\u7684\u8f93\u5165\u5c3a\u5bf8\u4e0d\u540c\uff1b\u8bad\u7ec3\u8981\u8dd1\u53cd\u5411\u4e0e\u4f18\u5316\u5668\uff0c\u9a8c\u8bc1\u53ea\u9700\u8981\u524d\u5411\uff1b\u591a\u5361\u901a\u4fe1\u56fe\u548c\u5355\u5361\u8ba1\u7b97\u56fe\u7684\u62d3\u6251\u4e5f\u4e0d\u4e00\u6837\u3002CUDA Graph \u8981\u6c42\u201c\u6355\u83b7\u4e00\u6b21\u3001\u91cd\u653e\u591a\u6b21\u201d\u65f6\u5f20\u91cf\u5730\u5740\u4e0e\u5f62\u72b6\u5b8c\u5168\u4e00\u81f4\uff0c\u53ea\u8981\u5f62\u72b6\u53d8\u4e86\u5c31\u8981\u91cd\u65b0\u6355\u83b7\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tech-Renaissance \u7684\u89e3\u6cd5\u662f\uff1a\u628a<strong>\u56fe\u62d3\u6251<\/strong>\u548c<strong>\u5f62\u72b6\/\u5185\u5b58\u5e03\u5c40<\/strong>\u5f7b\u5e95\u89e3\u8026\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ComputationGraph<\/code> \u53ea\u4fdd\u5b58\u96f6\u5f62\u72b6\u4fe1\u606f\u7684\u7b97\u5b50\u62d3\u6251\uff1b<\/li>\n\n\n\n<li><code>GraphAtlas<\/code> \u628a\u8fd9\u4efd\u62d3\u6251\u6620\u5c04\u5230\u4e0d\u540c\u53d8\u4f53\u3001\u4e0d\u540c\u5b50\u56fe\uff0c\u5e76\u6309 <code>(cg, gid, shape_id)<\/code> \u53bb\u91cd\u590d\u7528\uff1b<\/li>\n\n\n\n<li>\u8fd0\u884c\u65f6\u901a\u8fc7 O(1) \u6570\u7ec4\u7d22\u5f15\u76f4\u63a5\u62ff\u5230\u5bf9\u5e94\u7684 CUDA Graph \u6267\u884c\u53e5\u67c4\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5c31\u662f\u672c\u6587\u7684\u4e3b\u9898\uff1a<strong>\u4e00\u4efd\u56fe\u7eb8\uff0c\u591a\u5904\u590d\u7528<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4e3a\u4ec0\u4e48\u8981\u628a\u5f62\u72b6\u4ece\u8ba1\u7b97\u56fe\u91cc\u5265\u79bb\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba1\u7b97\u56fe\uff08Computational Graph\uff09\u63cf\u8ff0\u7684\u662f\u201c\u5148\u7b97\u4ec0\u4e48\u3001\u540e\u7b97\u4ec0\u4e48\uff0c\u8c01\u4f9d\u8d56\u8c01\u201d\u3002\u4f60\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u6210\u4e00\u9053\u83dc\u7684\u83dc\u8c31\uff1a\u83dc\u8c31\u53ea\u89c4\u5b9a\u6b65\u9aa4\u548c\u4f9d\u8d56\u5173\u7cfb\uff0c\u6bd4\u5982\u201c\u5148\u7092\u86cb\u518d\u7092\u996d\u201d\uff0c\u5b83\u4e0d\u5173\u5fc3\u4f60\u4eca\u5929\u7528\u7684\u662f\u5927\u76d8\u5b50\u8fd8\u662f\u5c0f\u76d8\u5b50\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e3b\u6d41\u6846\u67b6\u91cc\uff0c\u8ba1\u7b97\u56fe\u548c\u5f62\u72b6\u7684\u5173\u7cfb\u5927\u81f4\u6709\u51e0\u79cd\u505a\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>PyTorch Eager<\/strong> \u662f\u6700\u5178\u578b\u7684\u52a8\u6001\u56fe\u6267\u884c\u6a21\u5f0f\u3002\u6bcf\u4e2a\u7b97\u5b50\u90fd\u5728 Python \u5c42\u88ab\u89e6\u53d1\uff0c\u7ecf\u8fc7 dispatcher\u3001Autograd\u3001C++ kernel launch\uff0c\u9010\u4e2a\u63d0\u4ea4\u7ed9 GPU\u3002\u5f20\u91cf\u5bf9\u8c61\u672c\u8eab\u6301\u6709 shape\u3001stride\u3001dtype\u3001device \u7b49\u5168\u90e8\u4fe1\u606f\uff0c\u8ba1\u7b97\u56fe\u662f\u201c\u9690\u5f0f\u201d\u7684\u2014\u2014\u5b83\u53ea\u5728\u53cd\u5411\u4f20\u64ad\u65f6\u4e34\u65f6\u6784\u5efa\u3002\u8fd9\u79cd\u6a21\u5f0f\u7684\u4f18\u70b9\u662f\u7075\u6d3b\u3001\u8c03\u8bd5\u65b9\u4fbf\u3001\u652f\u6301\u4efb\u610f Python \u63a7\u5236\u6d41\uff1b\u4ee3\u4ef7\u662f host \u8c03\u5ea6\u5f00\u9500\u5927\uff0c\u5168\u5c40\u4f18\u5316\u7a7a\u95f4\u53d7\u9650\uff0c\u4e5f\u5f88\u96be\u76f4\u63a5\u505a CUDA Graph \u5168\u6355\u83b7\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>TensorFlow 1.x<\/strong> \u8d70\u4e86\u53e6\u4e00\u6761\u8def\uff1a\u5148\u6784\u5efa\u9759\u6001\u56fe\uff0c\u518d\u6267\u884c\u3002\u7528\u6237\u901a\u8fc7 <code>tf.Graph()<\/code> \u548c <code>tf.Session()<\/code> \u5b9a\u4e49\u8282\u70b9\u548c\u8fb9\uff0cshape \u4fe1\u606f\u5728\u6784\u56fe\u65f6\u5c31\u88ab\u6ce8\u5165\u3002\u8fd9\u79cd\u8bbe\u8ba1\u8ba9 XLA \u53ef\u4ee5\u505a\u975e\u5e38\u6fc0\u8fdb\u7684\u7b97\u5b50\u878d\u5408\u3001\u5e03\u5c40\u4f18\u5316\u548c\u5e38\u91cf\u6298\u53e0\u3002\u5230\u4e86 <strong>TensorFlow 2.x<\/strong>\uff0c\u867d\u7136\u9ed8\u8ba4\u53d8\u6210 Eager\uff0c\u4f46\u4ecd\u7136\u4fdd\u7559\u4e86 <code>tf.function<\/code> \u7528\u4e8e\u56fe\u6355\u83b7\u548c XLA \u7f16\u8bd1\u3002<strong>JAX<\/strong> \u5219\u66f4\u8fdb\u4e00\u6b65\uff0c\u5b83\u9f13\u52b1\u7528\u6237\u7528 <code>jax.jit<\/code> \u628a Python \u51fd\u6570\u7f16\u8bd1\u6210 XLA HLO\uff0c\u7531 XLA \u8d1f\u8d23\u540e\u7eed\u4f18\u5316\uff1b\u4f46 JAX \u7684\u7528\u6237\u901a\u5e38\u4e5f\u8981\u9762\u5bf9 tracing \u4e0e jit \u7684\u8bed\u4e49\u8fb9\u754c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>PyTorch torch.compile<\/strong> \u8bd5\u56fe\u517c\u987e\u4e24\u8fb9\uff1a\u5b83\u7528 TorchDynamo \u5728 Python \u89e3\u91ca\u5668\u5c42\u9762\u6355\u83b7 FX Graph\uff0c\u7136\u540e\u7528 AOT Autograd \u751f\u6210\u524d\u53cd\u5411\u56fe\uff0c\u518d\u7528 Inductor \u505a\u7b97\u5b50\u878d\u5408\u4e0e kernel \u751f\u6210\uff0c\u6700\u540e\u5c1d\u8bd5 CUDA Graph \u6355\u83b7\u3002\u8fd9\u662f\u4e00\u4e2a\u5de5\u7a0b\u4e0a\u975e\u5e38\u6709\u4ef7\u503c\u7684\u65b9\u5411\uff0c\u4f46\u5b83\u672c\u8d28\u4e0a\u662f\u5728\u52a8\u6001\u56fe\u4e4b\u4e0a\u201c\u4e8b\u540e\u8865\u9759\u6001\u4f18\u5316\u201d\u3002\u52a8\u6001\u5f62\u72b6\u3001Python \u526f\u4f5c\u7528\u3001\u6570\u636e\u4f9d\u8d56\u63a7\u5236\u6d41\u90fd\u53ef\u80fd\u9020\u6210 graph break\uff1b\u6bcf\u6b21 graph break \u90fd\u610f\u5473\u7740 host-device \u540c\u6b65\u548c\u4f18\u5316\u673a\u4f1a\u7684\u635f\u5931\u3002CUDA Graph \u8fd8\u8981\u6c42\u6355\u83b7\u65f6\u7684\u5730\u5740\u5728\u91cd\u653e\u65f6\u7a33\u5b9a\uff0cPyTorch \u7684\u7f13\u5b58\u5206\u914d\u5668\u9700\u8981\u901a\u8fc7 private pool\u3001CUDA Graph Trees \u7b49\u673a\u5236\u6765\u4fdd\u8bc1\uff0c\u590d\u6742\u5ea6\u5f88\u9ad8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tech-Renaissance \u4ece\u8bbe\u8ba1\u4e4b\u521d\u5c31\u9009\u62e9<strong>\u9759\u6001\u56fe\u7f16\u8bd1<\/strong>\u3002\u8fd9\u4e0d\u662f\u4e3a\u4e86\u201c\u9759\u6001\u800c\u9759\u6001\u201d\uff0c\u800c\u662f\u56e0\u4e3a\u6211\u4eec\u8981\u628a\u51e0\u4ef6\u4e8b\u4e00\u6b21\u6027\u505a\u5bf9\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>CUDA Graph \u5168\u6355\u83b7<\/strong>\uff1aCUDA Graph \u8981\u6c42\u6355\u83b7\u65f6\u7684\u5f20\u91cf\u5730\u5740\u3001\u5f62\u72b6\u3001kernel \u53c2\u6570\u5728\u91cd\u653e\u65f6\u5b8c\u5168\u4e00\u81f4\u3002\u5982\u679c\u56fe\u672c\u8eab\u5e26\u6709\u52a8\u6001 shape\uff0c\u6355\u83b7\u5c31\u65e0\u4ece\u8c08\u8d77\u3002<\/li>\n\n\n\n<li><strong>\u9759\u6001\u663e\u5b58\u89c4\u5212<\/strong>\uff1aMemoryPlan \u9700\u8981\u63d0\u524d\u77e5\u9053\u6bcf\u4e2a\u5f20\u91cf\u7684\u5927\u5c0f\u548c\u751f\u547d\u5468\u671f\uff0c\u624d\u80fd\u505a Region \u5206\u533a\u3002\u5982\u679c\u5f62\u72b6\u5728\u8fd0\u884c\u671f\u53d8\u5316\uff0c\u5206\u533a\u5c31\u65e0\u6cd5\u9759\u6001\u786e\u5b9a\u3002<\/li>\n\n\n\n<li><strong>\u786e\u5b9a\u6027\u8bad\u7ec3<\/strong>\uff1a\u5f62\u72b6\u56fa\u5b9a\u540e\uff0c\u8c03\u5ea6\u987a\u5e8f\u3001\u968f\u673a\u6570\u3001\u901a\u4fe1\u65f6\u5e8f\u90fd\u53ef\u4ee5\u88ab\u7cbe\u786e\u590d\u73b0\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u9759\u6001\u56fe\u4e0d\u7b49\u4e8e\u201c\u4e00\u79cd\u5f62\u72b6\u4e00\u5957\u56fe\u201d\u3002\u6211\u4eec\u53ef\u4ee5\u8ba9\u540c\u4e00\u4efd<strong>\u62d3\u6251<\/strong>\u670d\u52a1\u591a\u4e2a<strong>\u5f62\u72b6\u53d8\u4f53<\/strong>\uff0c\u53ea\u8981\u6bcf\u4e2a\u53d8\u4f53\u6709\u81ea\u5df1\u7684 MemoryPlan \u5c31\u884c\u3002\u8fd9\u6b63\u662f <code>ComputationGraph<\/code> \u7684\u8bbe\u8ba1\u51fa\u53d1\u70b9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001ComputationGraph\uff1a\u96f6\u5f62\u72b6\u4fe1\u606f\u7684\u7eaf\u62d3\u6251\u5bb9\u5668<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 <code>include\/renaissance\/graph\/computation_graph.h<\/code> \u4e2d\uff0c<code>ComputationGraph<\/code> \u88ab\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u7eaf\u7b97\u5b50\u62d3\u6251\u5bb9\u5668\u3002\u5934\u6587\u4ef6\u7684\u6ce8\u91ca\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\">\u6838\u5fc3\u7279\u5f81\uff1a\u96f6\u5f62\u72b6\u4fe1\u606f\u3002\u8282\u70b9\u4e2d\u53ea\u5b58 <code>(GraphNode, OpParams, tensor_id)<\/code>\uff1b<code>Shape \/ DType \/ Region<\/code> \u5168\u90e8\u4ece <code>MemoryPlan<\/code> \u7684 <code>DTensor<\/code> \u83b7\u53d6\uff1b\u4e00\u4efd\u56fe\u4f9b\u591a\u4e2a shape-only \u53d8\u4f53\u5171\u4eab\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u8bbe\u8ba1\u7684\u7cbe\u5999\u4e4b\u5904\u5728\u4e8e\uff1a<strong>\u56fe\u8282\u70b9\u4e0d\u5173\u5fc3\u81ea\u5df1\u64cd\u4f5c\u7684\u5f20\u91cf\u5177\u4f53\u957f\u4ec0\u4e48\u6837\uff0c\u53ea\u5173\u5fc3\u5168\u5c40\u5f20\u91cf ID<\/strong>\u3002\u771f\u6b63\u7684\u5f62\u72b6\u3001\u6570\u636e\u7c7b\u578b\u3001\u5185\u5b58\u533a\u57df\u504f\u79fb\u90fd\u5b58\u653e\u5728 <code>MemoryPlan<\/code> \u7684 <code>DTensor<\/code> \u63cf\u8ff0\u7b26\u91cc\u3002\u8fd0\u884c\u671f\u6355\u83b7\u65f6\uff0c\u628a\u540c\u4e00\u4efd <code>ComputationGraph<\/code> \u548c\u4e0d\u540c\u7684 <code>MemoryPlan<\/code> \u914d\u5bf9\uff0c\u5c31\u80fd\u5f97\u5230\u4e0d\u540c\u7684\u53ef\u6267\u884c CUDA Graph\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GraphNode<\/code> \u672c\u8eab\u662f\u4e00\u4e2a\u7531 <code>kind<\/code> \u9a71\u52a8\u7684\u8054\u5408\u4f53\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=\"\">struct GraphNode {\n    enum class Kind : uint8_t { COMPUTE, RANGE };\n    Kind kind = Kind::COMPUTE;\n\n    union {\n        ComputeOp compute_op;   \/\/ DTensor \u7ea7\u64cd\u4f5c\n        RangeOp   range_op;     \/\/ Region \u7ea7\u6279\u91cf\u64cd\u4f5c\n    };\n\n    OpParams params;                    \/\/ \u7b97\u5b50\u53c2\u6570\n    std::vector&lt;int32_t> input_ids;     \/\/ COMPUTE\uff1a\u8f93\u5165 DTensor \u5168\u5c40 ID\n    std::vector&lt;int32_t> output_ids;    \/\/ COMPUTE\uff1a\u8f93\u51fa DTensor \u5168\u5c40 ID\n    std::vector&lt;MemRange> input_ranges; \/\/ RANGE\uff1a\u9884\u8ba1\u7b97 (offset, size)\n    std::vector&lt;MemRange> output_ranges;\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>COMPUTE<\/code> \u8282\u70b9\u5bf9\u5e94\u4e00\u4e2a\u5177\u4f53\u7684\u7b97\u5b50\uff0c\u6bd4\u5982\u5377\u79ef\u3001BN\u3001ReLU\u3001\u77e9\u9635\u4e58\uff1b<code>RANGE<\/code> \u8282\u70b9\u5219\u5bf9\u5e94 Region \u7ea7\u6279\u91cf\u64cd\u4f5c\uff0c\u6bd4\u5982\u201c\u628a\u8fd9\u4e00\u6574\u6bb5\u68af\u5ea6\u6e05\u96f6\u201d\u3001\u201c\u5bf9\u8fd9\u4e00\u6574\u7247\u6743\u91cd\u505a AllReduce\u201d\u3002\u4e24\u79cd\u8282\u70b9\u90fd\u6ca1\u6709\u4efb\u4f55\u5f62\u72b6\u4fe1\u606f\uff0c\u53ea\u6709\u201c\u5bf9\u8c01\u64cd\u4f5c\u201d\u7684\u62bd\u8c61\u5f15\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ComputationGraph<\/code> \u5185\u90e8\u6309 <code>GraphId<\/code> \u5206\u6876\u5b58\u50a8\u8282\u70b9\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=\"\">class ComputationGraph {\npublic:\n    void append(GraphId gid, GraphNode node);\n    const std::vector&lt;GraphNode>&amp; nodes(GraphId gid) const;\n\nprivate:\n    std::array&lt;std::vector&lt;GraphNode>,\n               static_cast&lt;size_t>(GraphId::COUNT)> graphs_;\n    std::vector&lt;GraphNode> linear_nodes_;\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u610f\u5473\u7740\uff0c\u53ea\u8981\u6a21\u578b\u7ed3\u6784\u4e0d\u53d8\uff0c\u7f16\u8bd1\u5668\u53ea\u9700\u8981\u6784\u5efa\u4e00\u6b21 <code>ComputationGraph<\/code>\uff1b\u4e4b\u540e\u65e0\u8bba\u662f\u628a <code>batch_size<\/code> \u4ece 128 \u5207\u6362\u5230 71\uff0c\u8fd8\u662f\u628a\u5206\u8fa8\u7387\u4ece 224 \u5207\u6362\u5230 128\uff0c\u90fd\u53ea\u9700\u8981\u91cd\u65b0\u63a8\u5bfc\u5f62\u72b6\u3001\u5206\u914d\u65b0\u7684 <code>MemoryPlan<\/code>\uff0c\u800c\u4e0d\u9700\u8981\u91cd\u65b0\u62fc\u63a5\u56fe\u62d3\u6251\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u524d <code>GraphId<\/code> \u679a\u4e3e\u5171\u6709 <code>33<\/code> \u4e2a\u6807\u8bc6\uff08<code>GraphId::COUNT == 33<\/code>\uff09\uff0c\u8986\u76d6\u4e86\u8bad\u7ec3\/\u9a8c\u8bc1\u6d41\u7a0b\u4e2d\u7684\u5404\u4e2a\u9636\u6bb5\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>TRANSFER_A \/ TRANSFER_B<\/code>\uff1aH2D \u53cc\u7f13\u51b2\u5f02\u6b65\u4f20\u8f93\uff1b<\/li>\n\n\n\n<li><code>FIRST_LAYER_FWD_A \/ FIRST_LAYER_FWD_B<\/code>\uff1a\u9996\u5c42\u524d\u5411\uff08A\/B \u53cc\u7f13\u51b2\uff09\uff1b<\/li>\n\n\n\n<li><code>DEEP_FWD_BWD<\/code>\uff1a\u6df1\u5c42\u524d\u5411 + \u53cd\u5411\u878d\u5408\uff1b<\/li>\n\n\n\n<li><code>FIRST_LAYER_BWD_A \/ FIRST_LAYER_BWD_B<\/code>\uff1a\u9996\u5c42\u53cd\u5411\uff1b<\/li>\n\n\n\n<li><code>ZERO_GRAD \/ FIRST_COMM \/ DEEP_COMM \/ STATS_COMM<\/code>\uff1a\u68af\u5ea6\u6e05\u96f6\u4e0e\u901a\u4fe1\uff1b<\/li>\n\n\n\n<li><code>OPTIMIZER \/ EMA_UPDATE \/ UPDATE_STATS<\/code>\uff1a\u4f18\u5316\u5668\u4e0e BN \u7edf\u8ba1\u91cf\u66f4\u65b0\uff1b<\/li>\n\n\n\n<li><code>INF_MAIN_A \/ INF_MAIN_B \/ INF_EMA_A \/ INF_EMA_B<\/code>\uff1a\u4e3b\u6a21\u578b\u4e0e EMA \u6a21\u578b\u63a8\u7406\uff1b<\/li>\n\n\n\n<li>\u7b49\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 <code>DeepLearningTask<\/code> \u7684\u56fe\u96c6\u91cc\uff0c\u53ea\u6709\u90a3\u4e9b <code>train_cg_<\/code> \u6216 <code>infer_cg_<\/code> \u4e2d\u786e\u5b9e\u5305\u542b\u8282\u70b9\u7684\u5b50\u56fe\u624d\u4f1a\u88ab\u586b\u5165\u3002\u4f8b\u5982 <code>SIMPLE_TASK_GRAPH<\/code> \u662f\u7559\u7ed9 <code>SimpleTask<\/code> \u7684\u901a\u7528\u69fd\u4f4d\uff0cLARS \u76f8\u5173\u7684\u4e09\u4e2a\u5b50\u56fe\u5728\u4e0d\u542f\u7528 LARS \u4f18\u5316\u5668\u65f6\u4e3a\u7a7a\uff1b\u8fd9\u4e9b\u7a7a\u69fd\u4f4d\u4f1a\u5728 <code>pre_capture<\/code> \u9636\u6bb5\u88ab\u76f4\u63a5\u8df3\u8fc7\u3002\u5728\u542f\u7528\u5168\u90e8\u529f\u80fd\u7684\u5b8c\u6574\u914d\u7f6e\u4e0b\uff0c\u901a\u5e38\u4f1a\u6709 22 \u5f20 shape \u65e0\u5173\u5b50\u56fe\u30015 \u5f20\u8bad\u7ec3 shape \u76f8\u5173\u5b50\u56fe\u548c 4 \u5f20\u9a8c\u8bc1 shape \u76f8\u5173\u5b50\u56fe\u88ab\u586b\u5145\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001GraphAtlas\uff1a\u53d8\u4f53\u4e0e\u5b50\u56fe\u7684\u6620\u5c04\u8868<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u8bf4 <code>ComputationGraph<\/code> \u662f\u201c\u56fe\u7eb8\u201d\uff0c\u90a3\u4e48 <code>GraphAtlas<\/code> \u5c31\u662f\u201c\u56fe\u7eb8\u7d22\u5f15\u8868 + \u53bb\u91cd\u7f13\u5b58\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>GraphAtlas<\/code> \u5728 <code>include\/renaissance\/graph\/graph_atlas.h<\/code> \u4e2d\u5b9a\u4e49\uff0c\u672c\u8d28\u4e0a\u662f\u4e00\u5f20 <code>6 \u53d8\u4f53 \u00d7 33 \u5b50\u56fe<\/code> \u7684\u6620\u5c04\u8868\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=\"\">class GraphAtlas {\npublic:\n    static constexpr size_t kMaxVariants = 6;\n    static constexpr size_t kMaxGraphIds = static_cast&lt;size_t>(GraphId::COUNT);\n\n    struct Slot {\n        const ComputationGraph* cg = nullptr;     \/\/ \u5171\u4eab\u62d3\u6251\u6307\u9488\n        const MemoryPlan*       mp = nullptr;     \/\/ \u53d8\u4f53\u7279\u6709 MemoryPlan\n        ShapeId                 shape_id{};       \/\/ \u53bb\u91cd\u952e\n        StreamKind              stream_kind = StreamKind::COMP_1;\n        int32_t                 captured_idx = -1; \/\/ \u6355\u83b7\u540e\u586b\u5165\n    };\n\n    int32_t index(size_t variant, GraphId gid) const noexcept;\n\nprivate:\n    std::array&lt;std::array&lt;Slot, kMaxGraphIds>, kMaxVariants> table_;\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e2a Slot \u8bb0\u5f55\u4e86\u4e09\u6837\u4e1c\u897f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>cg<\/strong>\uff1a\u6307\u5411\u5171\u4eab\u7684 <code>ComputationGraph<\/code>\uff08\u56fe\u7eb8\uff09\uff1b<\/li>\n\n\n\n<li><strong>mp<\/strong>\uff1a\u6307\u5411\u8be5\u53d8\u4f53\u81ea\u5df1\u7684 <code>MemoryPlan<\/code>\uff08\u5e03\u5c40\uff09\uff1b<\/li>\n\n\n\n<li><strong>shape_id<\/strong>\uff1a\u7528\u4f5c\u53bb\u91cd\u952e\uff0c\u51b3\u5b9a\u8fd9\u5f20\u56fe\u7eb8 + \u8fd9\u4e2a\u5e03\u5c40\u662f\u5426\u9700\u8981\u5355\u72ec\u6355\u83b7\u4e00\u6b21 CUDA Graph\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u9700\u8981 6 \u4e2a\u53d8\u4f53\uff1f\u5728 <code>include\/renaissance\/graph\/compile_spec.h<\/code> \u4e2d\u53ef\u4ee5\u770b\u5230\u5b9a\u4e49\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=\"\">\/\/ variant 0: train_base         \u2014 train_res_begin \u00d7 standard_batch\n\/\/ variant 1: train_last         \u2014 train_res_begin \u00d7 last_batch\n\/\/ variant 2: train_lowres       \u2014 train_res_end   \u00d7 standard_batch\n\/\/ variant 3: train_lowres_last  \u2014 train_res_end   \u00d7 last_batch\n\/\/ variant 4: val_base           \u2014 val_res         \u00d7 standard_batch\n\/\/ variant 5: val_last           \u2014 val_res         \u00d7 val_last_batch<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9 6 \u4e2a\u53d8\u4f53\u8986\u76d6\u4e86\u8bad\u7ec3\u8fc7\u7a0b\u4e2d\u6240\u6709\u53ef\u80fd\u51fa\u73b0\u7684\u5f62\u72b6\u7ec4\u5408\uff1a\u4e24\u79cd\u8bad\u7ec3\u5206\u8fa8\u7387 \u00d7 \u4e24\u79cd batch \u5927\u5c0f\uff0c\u518d\u52a0\u4e0a\u9a8c\u8bc1\u7684\u4e24\u79cd batch \u5927\u5c0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56fe\u96c6\u7684\u5b9e\u9645\u586b\u5145\u903b\u8f91\u5728 <code>src\/task\/deep_learning_task.cpp<\/code> \u7684 <code>DeepLearningTask::build_graph_atlas()<\/code> \u4e2d\u5b8c\u6210\u3002\u6838\u5fc3\u903b\u8f91\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=\"\">GraphAtlas DeepLearningTask::build_graph_atlas() {\n    GraphAtlas atlas;\n    for (size_t v = 0; v &lt; GraphAtlas::kMaxVariants; ++v) {\n        const MemoryPlan* mp = variant_memory_plans_[v].get();\n        bool is_train_var = (v &lt;= 3);\n        ShapeId variant_shape = variant_compile_specs_[v].get_shape_id();\n\n        for (uint8_t gi = 0; gi &lt; static_cast&lt;uint8_t>(GraphId::COUNT); ++gi) {\n            GraphId gid = static_cast&lt;GraphId>(gi);\n\n            \/\/ \u8bad\u7ec3\u53d8\u4f53\u4e0d\u586b\u7eaf\u63a8\u7406\u56fe\uff0c\u9a8c\u8bc1\u53d8\u4f53\u4e0d\u586b\u8bad\u7ec3\u56fe\n            if (is_train_var) {\n                if (is_inference_graph(gid) &amp;&amp; !is_shape_invariant_graph(gid)) continue;\n            } else {\n                if (is_train_graph(gid) &amp;&amp; !is_inference_graph(gid) &amp;&amp;\n                    !is_shape_invariant_graph(gid)) continue;\n            }\n\n            \/\/ \u9009\u62e9\u8bad\u7ec3\u56fe\u8fd8\u662f\u63a8\u7406\u56fe\n            const ComputationGraph* cg = nullptr;\n            if (train_cg_ &amp;&amp; !train_cg_->nodes(gid).empty()) cg = train_cg_;\n            else if (infer_cg_ &amp;&amp; !infer_cg_->nodes(gid).empty()) cg = infer_cg_;\n            if (!cg) continue;\n\n            auto&amp; sl = atlas.slot(v, gi);\n            sl.cg = cg;\n            sl.stream_kind = stream_for(gid);\n\n            if (is_shape_invariant_graph(gid)) {\n                sl.mp = active_memory_plan_;\n                sl.shape_id = kShapeInvariant;   \/\/ {0,0,0,0}\n            } else {\n                sl.mp = mp;\n                sl.shape_id = variant_shape;\n            }\n        }\n    }\n    return atlas;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u6709\u4e24\u4e2a\u5173\u952e\u5224\u65ad\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>is_shape_invariant_graph<\/code><\/strong>\uff1a\u5bf9\u4e8e <code>TRANSFER<\/code>\u3001<code>COMM<\/code>\u3001<code>OPTIMIZER<\/code>\u3001<code>EMA_UPDATE<\/code> \u7b49\u5b50\u56fe\uff0c\u5b83\u4eec\u7684\u62d3\u6251\u4e0d\u4f9d\u8d56\u8f93\u5165\u5f62\u72b6\u3002\u8fd9\u4e9b\u56fe\u5728\u6240\u6709 6 \u4e2a\u53d8\u4f53\u95f4\u5171\u4eab\u540c\u4e00\u4e2a <code>kShapeInvariant<\/code> \u53bb\u91cd\u952e\uff0cPhase B \u53bb\u91cd\u65f6\u5fc5\u7136\u78b0\u649e\uff0c\u6700\u7ec8\u53ea\u6355\u83b7\u4e00\u6b21\u3002<\/li>\n\n\n\n<li><strong><code>is_train_graph \/ is_inference_graph<\/code><\/strong>\uff1a\u8bad\u7ec3\u53d8\u4f53\uff08v0~v3\uff09\u53ea\u586b\u8bad\u7ec3\u56fe\u548c shape \u65e0\u5173\u56fe\uff1b\u9a8c\u8bc1\u53d8\u4f53\uff08v4~v5\uff09\u53ea\u586b\u63a8\u7406\u56fe\u548c shape \u65e0\u5173\u56fe\u3002\u4ea4\u53c9\u69fd\u4f4d\u4fdd\u6301 <code>nullptr<\/code>\uff0c\u8fd0\u884c\u671f\u76f4\u63a5\u8df3\u8fc7\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ShapeId<\/code> \u662f\u4e00\u4e2a\u663e\u5f0f\u7684 <code>(N, H, W, C)<\/code> \u56db\u5143\u7ec4\uff0c\u800c\u4e0d\u662f\u54c8\u5e0c\u503c\u6216\u6307\u9488\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=\"\">struct ShapeId {\n    int32_t n = 0;  \/\/ batch \u7ef4\u5ea6\n    int32_t h = 0;  \/\/ \u9ad8\u5ea6\n    int32_t w = 0;  \/\/ \u5bbd\u5ea6\n    int32_t c = 0;  \/\/ \u901a\u9053\u6570\n};\n\nconstexpr ShapeId kShapeInvariant{0, 0, 0, 0};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u663e\u5f0f\u56db\u5143\u7ec4\u7684\u539f\u56e0\u662f\uff1ahash \u6709\u78b0\u649e\u98ce\u9669\uff0cMemoryPlan \u6307\u9488\u4e0d\u540c\u53d8\u4f53\u4e0d\u540c\uff0c\u800c <code>(N, H, W, C)<\/code> \u662f\u786e\u5b9a\u6027\u7684\u3001\u53ef\u8de8\u53d8\u4f53\u6bd4\u8f83\u7684\u3002\u53ea\u8981\u8f93\u5165 <code>ShapeId<\/code> \u76f8\u540c\uff0cCompiler \u63a8\u5bfc\u51fa\u7684\u6240\u6709\u4e2d\u95f4 <code>DTensor<\/code> \u5f62\u72b6\u90fd\u76f8\u540c\uff0c\u5c31\u53ef\u4ee5\u590d\u7528\u540c\u4e00\u4efd CUDA Graph\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001Phase B \u53bb\u91cd\uff1a\u540c\u4e00\u5f20\u56fe\u7eb8\u4e0d\u6355\u83b7\u4e24\u6b21<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">GraphAtlas \u7684\u4e09\u9636\u6bb5\u8bbe\u8ba1\u5728\u5934\u6587\u4ef6\u6ce8\u91ca\u91cc\u5199\u5f97\u975e\u5e38\u6e05\u695a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Phase A\uff08build\uff09<\/strong>\uff1a\u586b\u5165 <code>cg \/ mp \/ shape_id<\/code>\uff1b<\/li>\n\n\n\n<li><strong>Phase B\uff08pre_capture\uff09<\/strong>\uff1a\u904d\u5386 Slot\uff0c\u6309 <code>(cg, gid, shape_id)<\/code> \u53bb\u91cd\uff0c\u8c03\u7528 <code>CapturedGraph::capture()<\/code> \u586b\u5165 <code>captured_idx<\/code>\uff1b<\/li>\n\n\n\n<li><strong>Phase C\uff08index\uff09<\/strong>\uff1aExecutor \u8fd0\u884c\u65f6 O(1) \u6570\u7ec4\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><code>pre_capture<\/code> \u5728 <code>src\/graph\/captured_graph.cpp<\/code> \u4e2d\u5b9e\u73b0\uff0c\u6838\u5fc3\u53bb\u91cd\u903b\u8f91\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=\"\">PreCaptureResult pre_capture(const GraphAtlas&amp; compile_atlas,\n                             const std::vector&lt;DeviceContext*>&amp; contexts) {\n    PreCaptureResult result;\n    result.atlas = compile_atlas;\n\n    std::unordered_map&lt;CapturedGraph::Key, int32_t, CapturedGraph::KeyHash> seen;\n    std::unordered_map&lt;CapturedGraph::Key, const MemoryPlan*, CapturedGraph::KeyHash> key_to_mp;\n\n    for (size_t vi = 0; vi &lt; GraphAtlas::kMaxVariants; ++vi) {\n        for (uint8_t gi = 0; gi &lt; static_cast&lt;uint8_t>(GraphId::COUNT); ++gi) {\n            auto&amp; slot = result.atlas.slot(vi, gi);\n            if (!slot.cg || !slot.mp) continue;\n\n            CapturedGraph::Key key{slot.cg, static_cast&lt;GraphId>(gi), slot.shape_id};\n            key_to_mp[key] = slot.mp;\n\n            auto it = seen.find(key);\n            if (it != seen.end()) {\n                slot.captured_idx = it->second;   \/\/ \u590d\u7528\u5df2\u6709\u56fe\n                ++result.reused;\n            } else {\n                slot.captured_idx = static_cast&lt;int32_t>(seen.size());\n                seen[key] = slot.captured_idx;\n                ++result.captured;\n            }\n            ++result.total_slots;\n        }\n    }\n\n    \/\/ \u63a5\u4e0b\u6765\uff1acuDNN \u9884\u70ed\u3001\u8bc6\u522b NCCL \u56fe\u3001\u9010 rank \u6355\u83b7\u3001\u534f\u8c03\u591a rank \u6355\u83b7 \u2026\n    \/\/ ...\n    return result;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53bb\u91cd\u4e4b\u540e\uff0c<code>pre_capture<\/code> \u8fd8\u8981\u5b8c\u6210\u4e09\u4ef6\u5bf9\u6b63\u786e\u6027\u4e0e\u6027\u80fd\u90fd\u81f3\u5173\u91cd\u8981\u7684\u4e8b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>cuDNN \u9884\u70ed<\/strong>\uff1a\u5728\u771f\u6b63\u6355\u83b7 CUDA Graph \u4e4b\u524d\uff0c\u6846\u67b6\u4f1a\u9488\u5bf9\u6bcf\u4e2a\u552f\u4e00\u56fe\u5728\u6bcf\u4e2a rank \u4e0a\u628a cuDNN Frontend \u7684 kernel\/plan cache \u586b\u5145\u597d\u3002\u8fd9\u6837\u6355\u83b7\u9636\u6bb5\u5c31\u53ea\u6709\u7eaf <code>execute()<\/code> \u8c03\u7528\uff0c\u907f\u514d plan \u9009\u62e9\u5728\u56fe\u5185\u53d1\u751f\uff0c\u4ece\u800c\u4fdd\u8bc1\u56fe\u7684\u91cd\u653e\u662f\u786e\u5b9a\u4e14\u9ad8\u6548\u7684\u3002<\/li>\n\n\n\n<li><strong>\u8bc6\u522b NCCL \u56fe<\/strong>\uff1a\u5305\u542b <code>DEEP_COMM<\/code>\u3001<code>FIRST_COMM<\/code>\u3001<code>STATS_COMM<\/code> \u7b49 NCCL \u901a\u4fe1\u64cd\u4f5c\u7684\u5b50\u56fe\u9700\u8981\u591a rank \u534f\u8c03\u6355\u83b7\u3002<code>has_nccl_ops()<\/code> \u4f1a\u6807\u8bb0\u8fd9\u4e9b key\uff0c\u968f\u540e <code>capture_nccl_graph_coordinated()<\/code> \u5728\u6240\u6709 rank \u4e0a\u540c\u6b65\u8fdb\u5165\u548c\u9000\u51fa\u6355\u83b7\uff0c\u786e\u4fdd\u901a\u4fe1\u8bed\u4e49\u6b63\u786e\u3002<\/li>\n\n\n\n<li><strong>\u5e76\u884c\u6355\u83b7<\/strong>\uff1a\u975e NCCL \u56fe\u5148\u5728 rank 0 \u4e32\u884c\u6355\u83b7\uff0c\u518d\u5728 rank 1..N-1 \u4e0a\u5e76\u884c\u6355\u83b7\u3002\u4e32\u884c rank 0 \u53ef\u4ee5\u53d1\u73b0\u5e76\u7f13\u5b58\u6240\u6709 cuDNN plan\uff0c\u540e\u7eed rank \u76f4\u63a5\u590d\u7528\uff0c\u65e2\u8282\u7701\u65f6\u95f4\u53c8\u907f\u514d\u591a rank \u540c\u65f6\u89e6\u53d1 cuDNN \u5168\u5c40\u9501\u7ade\u4e89\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u53bb\u91cd\u952e <code>CapturedGraph::Key<\/code> \u7531\u4e09\u4e2a\u5b57\u6bb5\u7ec4\u6210\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=\"\">struct Key {\n    const ComputationGraph* cg = nullptr;   \/\/ \u56fe\u7eb8\u6307\u9488\n    GraphId                 gid = GraphId::TRANSFER_A; \/\/ \u5b50\u56fe\u6807\u8bc6\n    ShapeId                 shape{};        \/\/ \u8f93\u5165\u5f62\u72b6\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u8981 <code>(cg, gid, shape_id)<\/code> \u4e09\u5143\u7ec4\u76f8\u540c\uff0c\u5c31\u53ea\u6355\u83b7\u4e00\u6b21\u3002\u6bd4\u5982 <code>DEEP_FWD_BWD<\/code> \u8fd9\u5f20\u62d3\u6251\u56fe\uff0cv0 \u548c v2 \u7684\u8f93\u5165\u5206\u8fa8\u7387\u4e0d\u540c\uff0c<code>shape_id<\/code> \u4e0d\u540c\uff0c\u6240\u4ee5\u9700\u8981\u5404\u81ea\u6355\u83b7\uff1b\u4f46 v0 \u7684 <code>ZERO_GRAD<\/code> \u548c v2 \u7684 <code>ZERO_GRAD<\/code> \u90fd\u662f <code>kShapeInvariant<\/code>\uff0c\u4e8e\u662f\u590d\u7528\u540c\u4e00\u5f20\u56fe\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u53ef\u4ee5\u5927\u81f4\u4f30\u7b97\u53bb\u91cd\u6548\u679c\u3002<code>GraphAtlas<\/code> \u5171\u6709 <code>6 \u00d7 33 = 198<\/code> \u4e2a\u69fd\u4f4d\uff0c\u4f46\u5f88\u591a\u69fd\u4f4d\u662f\u7a7a\u7684\uff08\u8bad\u7ec3\u53d8\u4f53\u4e0d\u586b\u63a8\u7406\u56fe\uff0c\u9a8c\u8bc1\u53d8\u4f53\u4e0d\u586b\u8bad\u7ec3\u56fe\uff0c\u672a\u542f\u7528\u7684\u529f\u80fd\u5b50\u56fe\u4e5f\u4e3a\u7a7a\uff09\u3002\u5728\u542f\u7528\u5168\u90e8\u529f\u80fd\u7684\u5b8c\u6574\u914d\u7f6e\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7ea6 22 \u5f20 shape \u65e0\u5173\u5b50\u56fe<\/strong>\uff1a<code>TRANSFER<\/code>\u3001<code>COMM<\/code>\u3001<code>OPTIMIZER<\/code>\u3001<code>EMA_UPDATE<\/code>\u3001\u5404\u7c7b cast\u3001metrics \u6e05\u96f6\u7b49\u3002\u5b83\u4eec\u5728\u6240\u6709\u53d8\u4f53\u95f4\u5171\u4eab\u540c\u4e00\u4e2a <code>kShapeInvariant<\/code>\uff0c\u5168\u5c40\u53ea\u6355\u83b7\u4e00\u6b21\u3002<\/li>\n\n\n\n<li><strong>\u8bad\u7ec3\u76f8\u5173\u7684 shape \u654f\u611f\u5b50\u56fe<\/strong>\uff1a\u9996\u5c42\u524d\u5411 A\/B\u3001\u6df1\u5c42\u524d\u53cd\u5411\u3001\u9996\u5c42\u53cd\u5411 A\/B\uff0c\u5171 5 \u5f20\u30024 \u4e2a\u8bad\u7ec3\u53d8\u4f53\u6700\u591a\u4ea7\u751f 4 \u79cd\u4e0d\u540c\u7684 <code>ShapeId<\/code>\uff08\u4e24\u79cd\u5206\u8fa8\u7387 \u00d7 \u4e24\u79cd batch \u5927\u5c0f\uff09\uff1b\u5982\u679c\u8bad\u7ec3\u8d77\u59cb\u5206\u8fa8\u7387\u4e0e\u7ed3\u675f\u5206\u8fa8\u7387\u76f8\u540c\uff0c\u5219\u9000\u5316\u4e3a 2 \u79cd\u3002<\/li>\n\n\n\n<li><strong>\u9a8c\u8bc1\u76f8\u5173\u7684 shape \u654f\u611f\u5b50\u56fe<\/strong>\uff1a\u4e3b\u6a21\u578b\u63a8\u7406 A\/B\u3001EMA \u63a8\u7406 A\/B\uff0c\u5171 4 \u5f20\u30022 \u4e2a\u9a8c\u8bc1\u53d8\u4f53\u4ea7\u751f 2 \u79cd <code>ShapeId<\/code>\uff08\u6807\u51c6 batch \u4e0e\u672b\u5c3e batch\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\u5b9e\u9645\u552f\u4e00\u6355\u83b7\u7684 CUDA Graph \u6570\u91cf\u901a\u5e38\u5728 <strong>40 \u5f20\u5de6\u53f3<\/strong>\uff0c\u8fdc\u5c0f\u4e8e 198 \u4e2a\u69fd\u4f4d\u3002\u66f4\u91cd\u8981\u7684\u662f\uff0c\u90a3 22 \u5f20 shape \u65e0\u5173\u56fe\u662f\u5168\u5c40\u552f\u4e00\u7684\u2014\u2014\u65e0\u8bba\u4f60\u662f\u4ec0\u4e48\u4efb\u52a1\u3001\u4ec0\u4e48\u5206\u8fa8\u7387\u3001\u4ec0\u4e48 batch size\uff0c<code>ZERO_GRAD<\/code>\u3001<code>OPTIMIZER<\/code>\u3001<code>STATS_COMM<\/code> \u8fd9\u4e9b\u5b50\u56fe\u6c38\u8fdc\u53ea\u9700\u8981\u6355\u83b7\u4e00\u6b21\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u8fd0\u884c\u671f\uff1arun_train_epoch_gpu \u5982\u4f55\u6309\u56fe\u7d22\u9aa5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u56fe\u96c6\u7684\u6700\u7ec8\u76ee\u6807\u662f\u8ba9\u8fd0\u884c\u671f\u53d8\u5f97\u5c3d\u53ef\u80fd\u7b80\u5355\u3002\u5728 <code>src\/task\/deep_learning_task.cpp<\/code> \u7684 <code>run_train_epoch_gpu()<\/code> \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u6e05\u695a\u5730\u770b\u5230\u8fd9\u4e00\u70b9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u4e2a epoch \u5f00\u59cb\u524d\uff0c\u5148\u6839\u636e\u5f53\u524d\u5206\u8fa8\u7387\u9009\u62e9\u53d8\u4f53\u57fa\u5740\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=\"\">int current_res = registry.current_resolution_train();\nbool at_begin_res = (current_res == registry.train_sample_resolution_begin());\nsize_t v_base = at_begin_res ? 0 : 2;   \/\/ \u666e\u901a batch \u53d8\u4f53\nsize_t v_last = at_begin_res ? 1 : 3;   \/\/ \u6700\u540e\u4e00\u4e2a\u4e0d\u5b8c\u6574 batch \u53d8\u4f53<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc <code>v_base<\/code> \u662f\u666e\u901a batch \u7528\u7684\u53d8\u4f53\u7d22\u5f15\uff0c<code>v_last<\/code> \u662f\u6700\u540e\u4e00\u4e2a\u4e0d\u5b8c\u6574 batch \u7528\u7684\u53d8\u4f53\u7d22\u5f15\u3002\u4e24\u8005\u552f\u4e00\u533a\u522b\u5c31\u662f\u8f93\u5165 <code>batch_size<\/code> \u4e0d\u540c\uff0c\u56e0\u6b64 <code>MemoryPlan<\/code> \u4e0d\u540c\uff0c\u4f46 <code>ComputationGraph<\/code> \u62d3\u6251\u5171\u4eab\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u7740\u4ee3\u7801\u4f1a<strong>\u9884\u89e3\u6790<\/strong>\u51fa\u6bcf\u4e2a\u5b50\u56fe\u7684 CUDA Graph \u6267\u884c\u53e5\u67c4\u3002\u8fd9\u4e2a\u89e3\u6790\u53d1\u751f\u5728 <code>DeepLearningTask::build_exec_table()<\/code> \u4e2d\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=\"\">auto resolve = [&amp;](GraphId gid, int rank, size_t variant_idx) -> cudaGraphExec_t {\n    int32_t idx = captured_result_.atlas.index(variant_idx, gid);\n    if (idx &lt; 0 || static_cast&lt;size_t>(idx) >= captured_result_.graphs.size())\n        return nullptr;\n    return static_cast&lt;cudaGraphExec_t>(\n        captured_result_.graphs[idx].native_exec(rank));\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>resolve<\/code> \u5c31\u662f Phase C \u7684 O(1) \u7d22\u5f15\uff1a\u7ed9\u5b9a\u53d8\u4f53\u7d22\u5f15\u548c <code>GraphId<\/code>\uff0c<code>GraphAtlas::index()<\/code> \u76f4\u63a5\u8fd4\u56de <code>captured_idx<\/code>\uff0c\u7136\u540e\u4ece <code>captured_result_.graphs<\/code> \u4e2d\u53d6\u51fa\u8be5 rank \u7684 <code>cudaGraphExec_t<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u671f\u7684\u6267\u884c\u8868\u5e76\u4e0d\u76f4\u63a5\u7528 <code>GraphId<\/code> \u7d22\u5f15\uff0c\u800c\u662f\u7528\u4e00\u4e2a\u5185\u90e8\u679a\u4e3e <code>GraphSlot<\/code>\uff08\u5b9a\u4e49\u5728 <code>deep_learning_task.cpp<\/code> \u7684\u533f\u540d\u547d\u540d\u7a7a\u95f4\u4e2d\uff09\uff0c\u5b83\u628a <code>GraphId<\/code> \u6620\u5c04\u5230\u8fd0\u884c\u65f6\u66f4\u5bb9\u6613\u64cd\u4f5c\u7684\u69fd\u4f4d\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=\"\">enum class GraphSlot : uint8_t {\n    XFER_A = 0,\n    XFER_B,\n    FWD_BWD_DEEP_A,\n    FWD_BWD_DEEP_B,\n    FIRST_LAYER_BWD_A,\n    FIRST_LAYER_BWD_B,\n    ZERO_GRAD,\n    DEEP_ALLREDUCE,\n    FIRST_LAYER_ALLREDUCE,\n    WEIGHT_UPDATE,\n    \/\/ ... LARS\u3001EMA\u3001CAST\u3001BN \u7edf\u8ba1\u91cf\u540c\u6b65\u3001\u63a8\u7406\u56fe\u7b49\n    COUNT\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f <code>FWD_BWD_DEEP_A<\/code> \u548c <code>FWD_BWD_DEEP_B<\/code> \u90fd\u89e3\u6790\u81ea\u540c\u4e00\u4e2a <code>GraphId::DEEP_FWD_BWD<\/code>\uff0c\u53ea\u662f\u56e0\u4e3a\u7ed1\u5b9a\u5230 A\/B \u53cc\u7f13\u51b2\u7684\u8f93\u5165\u533a\u800c\u88ab\u5206\u6210\u4e24\u5f20 CUDA Graph\uff1b\u800c <code>ZERO_GRAD<\/code>\u3001<code>DEEP_ALLREDUCE<\/code>\u3001<code>WEIGHT_UPDATE<\/code> \u7b49 shape \u65e0\u5173\u56fe\u5219\u4e0d\u9700\u8981 A\/B \u5404\u4e00\u5f20\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bad\u7ec3\u5faa\u73af\u91cc\u7684\u5178\u578b\u4e00\u4e2a batch \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=\"\">for (int batch = 0; batch &lt; batches - 1; ++batch) {\n    bool from_a = (batch % 2 == 0);\n    int next_buf = from_a ? 1 : 0;\n    auto g_fwd   = from_a ? n_fwd_a : n_fwd_b;\n    auto g_deep  = from_a ? n_deep_a : n_deep_b;\n    auto g_xfer_n = from_a ? n_xfer_b : n_xfer_a;\n    auto g_first = from_a ? n_bwd_a : n_bwd_b;\n\n    if (n_zg) cudaGraphLaunch(n_zg, s_up);          \/\/ \u6e05\u96f6\u68af\u5ea6\u548c loss\n    if (g_fwd) cudaGraphLaunch(g_fwd, s_c1);        \/\/ \u9996\u5c42\u524d\u5411\n\n    sync_tr();\n    ts->wait_buffer_readable(next_buf);\n    if (g_xfer_n) cudaGraphLaunch(g_xfer_n, s_trans); \/\/ \u4e0b\u4e00\u4e2a batch \u7684 H2D \u4f20\u8f93\n\n    sync_comp(); sync_up();\n    if (g_deep) cudaGraphLaunch(g_deep, s_c1);      \/\/ \u6df1\u5c42\u524d\u5411 + \u53cd\u5411\n    sync_comp();\n\n    if (!frozen &amp;&amp; g_first) cudaGraphLaunch(g_first, s_c1); \/\/ \u9996\u5c42\u53cd\u5411\n    if (n_dar) cudaGraphLaunch(n_dar, s_up);        \/\/ \u6df1\u5c42\u68af\u5ea6 AllReduce\n\n    sync_up(); sync_comp();\n    if (n_wu) cudaGraphLaunch(n_wu, s_up);          \/\/ \u4f18\u5316\u5668\u66f4\u65b0\n    \/\/ ... BN \u7edf\u8ba1\u91cf\u540c\u6b65\u3001EMA \u66f4\u65b0\u3001\u5b66\u4e60\u7387\u540c\u6b65\u7b49\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u4e00\u4e2a batch \u8d70 <code>v_last<\/code> \u53d8\u4f53\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=\"\">const auto&amp; g_l = gpu_exec_.variant_graphs[v_last][rank];\nauto l_deep_a = g_l[S(GraphSlot::FWD_BWD_DEEP_A)];\nauto l_fwd_a  = g_l[S(GraphSlot::FIRST_LAYER_FWD_A)];\nauto l_accum_tl = g_l[S(GraphSlot::ACCUM_METRICS_TRAIN_LAST)];\n\/\/ ...<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b83\u7684\u62d3\u6251\u548c\u666e\u901a batch \u5b8c\u5168\u4e00\u6837\uff0c\u4f46\u56e0\u4e3a <code>batch_size<\/code> \u4e0d\u540c\uff0cshape \u76f8\u5173\u56fe\u9700\u8981\u5355\u72ec\u6355\u83b7\u3002\u8fd9\u5c31\u662f GraphAtlas \u652f\u6301<strong>\u6700\u540e\u4e00\u4e2a\u4e0d\u5b8c\u6574 batch<\/strong> \u7684\u5173\u952e\u673a\u5236\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u8865\u5145\u7684\u662f\uff0c\u8fd9\u4e9b\u6267\u884c\u4ee3\u7801\u8fd0\u884c\u5728\u6bcf\u5f20 GPU \u5bf9\u5e94\u7684\u4e00\u4e2a\u72ec\u7acb\u7ebf\u7a0b\u4e2d\u3002<code>run_train_epoch_gpu()<\/code> \u5728 epoch \u5f00\u59cb\u65f6\u4f1a\u4e3a\u6bcf\u4e2a rank \u521b\u5efa\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u62e5\u6709\u72ec\u7acb\u7684 <code>DeviceContext<\/code>\u3001\u6d41\u53e5\u67c4\u548c\u89e3\u6790\u540e\u7684\u56fe\u6267\u884c\u8868\u3002\u7ebf\u7a0b\u4e4b\u95f4\u901a\u8fc7 CUDA \u4e8b\u4ef6\u4e0e <code>cudaStreamSynchronize<\/code> \u540c\u6b65\uff0c\u800c\u4e0d\u662f\u901a\u8fc7 host \u7aef\u9501\u3002\u5982\u679c\u67d0\u4e2a rank \u5728\u6355\u83b7\u6216\u6267\u884c\u8fc7\u7a0b\u4e2d\u629b\u51fa\u5f02\u5e38\uff0c<code>std::exception_ptr<\/code> \u4f1a\u628a\u5f02\u5e38\u4f20\u56de\u4e3b\u7ebf\u7a0b\u518d\u7edf\u4e00 <code>rethrow<\/code>\uff0c\u4fdd\u8bc1\u591a\u5361\u8bad\u7ec3\u4e0d\u4f1a\u56e0\u4e3a\u5355\u5361\u5931\u8d25\u800c\u6084\u65e0\u58f0\u606f\u5730\u7ee7\u7eed\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u540c\u53d8\u4f53\u4e4b\u95f4\u7684\u5207\u6362\u4e4b\u6240\u4ee5\u5b89\u5168\uff0c\u8fd8\u5f97\u76ca\u4e8e Compiler \u5728 Phase 2 \u505a\u7684\u4e00\u4ef6\u91cd\u8981\u4e8b\u60c5\uff1a<strong><code>compute_max_slot_bytes<\/code><\/strong>\u3002\u5b83\u4f1a\u5bf9\u6bcf\u4e2a <code>(layer, tensor)<\/code> \u4f4d\u7f6e\u8de8\u6240\u6709\u53d8\u4f53\u53d6\u6700\u5927 slot \u5b57\u8282\u6570\uff0c\u7136\u540e\u7528\u8fd9\u4e2a\u6700\u5927\u503c\u53bb\u6784\u9020 6 \u4e2a MemoryPlan\u3002\u7528\u4ee3\u7801\u6ce8\u91ca\u7684\u8bdd\u6765\u8bf4\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=\"\">\/\/ Phase 2: \u9010 (layer, tensor) \u8de8\u53d8\u4f53\u53d6 max slot_bytes\n\/\/ Phase 3: \u7528 max_slot_bytes \u6784\u9020 6 \u4e2a MemoryPlan\uff0c\n\/\/          \u6240\u6709\u53d8\u4f53\u540c\u4e00\u4f4d\u7f6e\u7684 DTensor \u5177\u6709\u76f8\u540c offset\u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u6b64\uff0c\u540c\u4e00\u4f4d\u7f6e\u7684 <code>DTensor<\/code> \u5728\u4e0d\u540c\u53d8\u4f53\u4e0b\u5177\u6709\u76f8\u540c\u7684 offset\u2014\u2014\u6743\u91cd\u3001\u68af\u5ea6\u3001\u52a8\u91cf\u8fd9\u4e9b\u975e batch \u76f8\u5173\u5f20\u91cf\u7684\u5730\u5740\u4e0d\u4f1a\u56e0\u4e3a\u53d8\u4f53\u5207\u6362\u800c\u6f02\u79fb\u3002\u5e38\u89c4 batch \u66f4\u65b0\u5b8c\u7684\u6743\u91cd\uff0c\u672b\u5c3e batch \u76f4\u63a5\u7ee7\u7eed\u4f7f\u7528\u540c\u4e00\u5757\u663e\u5b58\uff0c\u65e0\u9700\u4efb\u4f55\u62f7\u8d1d\u6216\u91cd\u6620\u5c04\u3002\u8fd9\u4e5f\u4e3a CUDA Graph \u5168\u6355\u83b7\u63d0\u4f9b\u4e86\u5730\u5740\u7a33\u5b9a\u6027\u4fdd\u8bc1\uff1a\u56fe\u5728\u6355\u83b7\u65f6\u770b\u5230\u7684\u6307\u9488\uff0c\u5728\u91cd\u653e\u65f6\u4ecd\u7136\u6307\u5411\u540c\u4e00\u4e2a\u504f\u79fb\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u4e0e\u4e3b\u6d41\u6846\u67b6\u7684\u5bf9\u6bd4<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PyTorch \u7684 <code>torch.compile<\/code> \u4e5f\u8bd5\u56fe\u505a\u9759\u6001\u4f18\u5316\u548c CUDA Graph\uff0c\u4f46\u5b83\u7684\u51fa\u53d1\u70b9\u662f\u5728\u52a8\u6001\u56fe\u4e4b\u4e0a\u201c\u4e8b\u540e\u6355\u83b7\u201d\u3002\u8fd9\u5e26\u6765\u51e0\u4e2a\u7ed3\u6784\u6027\u96be\u9898\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Graph break<\/strong>\uff1a\u9047\u5230\u4e0d\u652f\u6301\u7684\u64cd\u4f5c\u65f6 Dynamo \u4f1a\u4e2d\u65ad\u56fe\uff0c\u4e2d\u95f4\u56de\u9000 eager\uff1b<\/li>\n\n\n\n<li><strong>\u52a8\u6001\u5f62\u72b6<\/strong>\uff1a\u8f93\u5165 shape \u53d8\u5316\u53ef\u80fd\u89e6\u53d1\u91cd\u65b0\u7f16\u8bd1\uff1b<\/li>\n\n\n\n<li><strong>\u5730\u5740\u7a33\u5b9a\u6027<\/strong>\uff1aCUDA Graph \u8981\u6c42\u5730\u5740\u4e0d\u53d8\uff0cPyTorch \u7684\u7f13\u5b58\u5206\u914d\u5668\u9700\u8981 CUDA Graph Trees \u7b49\u989d\u5916\u673a\u5236\uff1b<\/li>\n\n\n\n<li><strong>\u6b63\u786e\u6027\u98ce\u9669<\/strong>\uff1a\u793e\u533a\u957f\u671f\u62a5\u544a torch.compile \u4e0e eager \u4e0d\u4e00\u81f4\u7684\u6848\u4f8b\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Tech-Renaissance \u6ca1\u6709\u8fd9\u4e9b\u5386\u53f2\u5305\u88b1\u3002\u6211\u4eec\u4ece\u6a21\u578b\u5b9a\u4e49\u9636\u6bb5\u5c31\u662f\u9759\u6001\u7684\uff0c\u6240\u6709\u5f62\u72b6\u3001\u5185\u5b58\u3001\u62d3\u6251\u3001\u8c03\u5ea6\u5173\u7cfb\u5728\u7f16\u8bd1\u671f\u786e\u5b9a\u3002<code>ComputationGraph<\/code> \u7684\u96f6\u5f62\u72b6\u8bbe\u8ba1\u8ba9\u201c\u62d3\u6251\u201d\u6210\u4e3a\u53ef\u590d\u7528\u7684\u57fa\u7840\u8bbe\u65bd\uff0c<code>GraphAtlas<\/code> \u7684\u53bb\u91cd\u7d22\u5f15\u8ba9\u591a\u79cd\u53d8\u4f53\u5171\u4eab\u540c\u4e00\u4efd\u6355\u83b7\u7ed3\u679c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e0d\u662f\u8bf4 Tech-Renaissance \u6bd4 PyTorch \u201c\u66f4\u5148\u8fdb\u201d\u2014\u2014\u5b83\u53ea\u662f\u5728<strong>\u8ffd\u6c42\u6781\u9650\u8bad\u7ec3\u541e\u5410<\/strong>\u8fd9\u6761\u8def\u4e0a\u505a\u4e86\u4e0d\u540c\u7684\u53d6\u820d\u3002\u5982\u679c\u4f60\u7684\u573a\u666f\u9700\u8981\u52a8\u6001\u6a21\u578b\u7ed3\u6784\u3001\u6570\u636e\u4f9d\u8d56\u63a7\u5236\u6d41\u3001Python \u8c03\u8bd5\u4f53\u9a8c\uff0cPyTorch Eager \u4ecd\u7136\u662f\u66f4\u81ea\u7136\u7684\u9009\u62e9\u3002\u4f46\u5982\u679c\u4f60\u8981\u7684\u662f\u7a33\u5b9a\u3001\u786e\u5b9a\u3001\u53ef\u5168\u56fe\u6355\u83b7\u7684\u9759\u6001\u8bad\u7ec3\u7ba1\u7ebf\uff0c\u90a3\u4e48\u201c\u4e00\u4efd\u56fe\u7eb8\uff0c\u591a\u5904\u590d\u7528\u201d\u5c31\u662f\u4e00\u6761\u66f4\u5e72\u51c0\u7684\u8def\u5f84\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u5c0f\u7ed3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ComputationGraph<\/code> \u548c <code>GraphAtlas<\/code> \u5171\u540c\u89e3\u51b3\u4e86\u9759\u6001\u56fe\u6846\u67b6\u4e2d\u7684\u4e00\u4e2a\u6838\u5fc3\u95ee\u9898\uff1a<strong>\u5982\u4f55\u5728\u591a\u79cd\u8fd0\u884c\u573a\u666f\u4e0b\u590d\u7528\u540c\u4e00\u4efd\u7b97\u5b50\u62d3\u6251<\/strong>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ComputationGraph<\/code> \u53ea\u4fdd\u5b58\u96f6\u5f62\u72b6\u4fe1\u606f\u7684\u7b97\u5b50\u62d3\u6251\uff0c\u4e0d\u6301\u6709\u4efb\u4f55\u5f20\u91cf\u6216\u5185\u5b58\uff1b<\/li>\n\n\n\n<li><code>GraphAtlas<\/code> \u628a\u8fd9\u4efd\u62d3\u6251\u6620\u5c04\u5230 6 \u4e2a\u53d8\u4f53\u300133 \u4e2a\u5b50\u56fe\uff0c\u5e76\u6309 <code>(cg, gid, shape_id)<\/code> \u53bb\u91cd\uff1b<\/li>\n\n\n\n<li>22 \u5f20 shape \u65e0\u5173\u56fe\uff08\u4f20\u8f93\u3001\u901a\u4fe1\u3001\u4f18\u5316\u5668\u7b49\uff09\u5728\u6240\u6709\u53d8\u4f53\u95f4\u5168\u5c40\u590d\u7528\uff1b<\/li>\n\n\n\n<li>\u8bad\u7ec3\u4e0e\u9a8c\u8bc1\u7684 shape \u76f8\u5173\u56fe\u6309 <code>ShapeId<\/code> \u533a\u5206\uff0c\u652f\u6301\u666e\u901a batch\u3001\u6700\u540e\u4e00\u4e2a batch\u3001\u4e0d\u540c\u5206\u8fa8\u7387\u3001\u8bad\u7ec3\/\u63a8\u7406\u7b49\u591a\u79cd\u573a\u666f\uff1b<\/li>\n\n\n\n<li>\u8fd0\u884c\u671f\u901a\u8fc7 <code>GraphAtlas::index()<\/code> \u505a O(1) \u7d22\u5f15\uff0c\u76f4\u63a5\u62ff\u5230 <code>cudaGraphExec_t<\/code> \u5e76 launch\uff1b<\/li>\n\n\n\n<li>\u8de8\u53d8\u4f53\u7684 <code>DTensor<\/code> offset \u4e00\u81f4\u6027\uff0c\u8ba9\u5e38\u89c4 batch \u4e0e\u672b\u5c3e batch\u3001\u8bad\u7ec3\u4e0e\u9a8c\u8bc1\u4e4b\u95f4\u7684\u5207\u6362\u65e0\u9700\u62f7\u8d1d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u5957\u673a\u5236\u662f\u540e\u7eed CUDA Graph \u5168\u6355\u83b7\u3001\u591a\u6d41\u5e76\u53d1\u3001MemoryPlan \u9759\u6001\u5206\u533a\u7b49\u80fd\u529b\u7684\u5171\u540c\u5e95\u5ea7\u3002\u5b83\u8ba9\u6211\u4eec\u53ef\u4ee5\u628a\u7cbe\u529b\u96c6\u4e2d\u5728\u62d3\u6251\u6b63\u786e\u6027\u4e0a\uff0c\u800c\u4e0d\u662f\u88ab\u8fd0\u884c\u65f6\u5f62\u72b6\u53d8\u5316\u7275\u7740\u9f3b\u5b50\u8d70\u3002\u4e0b\u4e00\u7bc7\u6587\u7ae0\uff0c\u6211\u4eec\u5c06\u8fdb\u5165\u6574\u4e2a\u6846\u67b6\u6700\u6838\u5fc3\u7684\u8bbe\u8ba1\u4e4b\u4e00\u2014\u2014<code>MemoryPlan<\/code> \u4e0e\u663e\u5b58\u5206\u533a\uff0c\u770b\u770b Tech-Renaissance \u662f\u5982\u4f55\u628a GPU \u663e\u5b58\u6309\u8bed\u4e49\u9759\u6001\u5e03\u5c40\uff0c\u4ece\u800c\u5f7b\u5e95\u6d88\u9664\u8fd0\u884c\u671f\u52a8\u6001\u5206\u914d\u7684\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\u56db \u5728\u524d\u4e00\u7bc7\u6587\u7ae0\u91cc\uff0c\u6211\u4eec\u6cbf\u7740 A [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":697,"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-505","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\/505","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=505"}],"version-history":[{"count":3,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/505\/revisions"}],"predecessor-version":[{"id":722,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/posts\/505\/revisions\/722"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/media\/697"}],"wp:attachment":[{"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech-renaissance.cn\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}