{"id":336819,"date":"2023-08-12T07:05:59","date_gmt":"2023-08-11T23:05:59","guid":{"rendered":"https:\/\/www.idc.net\/help\/336819\/"},"modified":"2023-08-12T07:05:59","modified_gmt":"2023-08-11T23:05:59","slug":"rayrtc%ef%bc%9a%e5%a4%a7%e8%a7%84%e6%a8%a1%e5%88%86%e5%b8%83%e5%bc%8f%e8%ae%a1%e7%ae%97%e5%ad%a6%e4%b9%a0%e5%bc%95%e6%93%8e-ray-%e5%9c%a8%e5%ad%97%e8%8a%82%e8%b7%b3%e5%8a%a8-nlp-%e5%9c%ba%e6%99%af","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/336819\/","title":{"rendered":"RayRTC\uff1a\u5927\u89c4\u6a21\u5206\u5e03\u5f0f\u8ba1\u7b97\u5b66\u4e60\u5f15\u64ce Ray \u5728\u5b57\u8282\u8df3\u52a8 NLP \u573a\u666f\u4e0b\u7684\u5b9e\u8df5"},"content":{"rendered":"<p>RayRTC \u662f\u5b57\u8282\u57fa\u7840\u67b6\u6784\u7ec4\u4e0e\u5b57\u8282 AML \u7ec4\u5171\u540c\u5408\u4f5c\uff0c\u5728\u5185\u90e8 RTC\uff08Realtime Text Classification\uff09\u6587\u672c\u8bad\u7ec3\u5e73\u53f0\u4e0a\u57fa\u4e8e Ray \u8fdb\u884c\u7684\u4e0b\u4e00\u4ee3 Serverless ML \u7684\u63a2\u7d22\u3002RTC \u6587\u672c\u5206\u7c7b\u5e73\u53f0\u662f\u4e00\u4e2a\u4e00\u7ad9\u5f0f\u7684 NLP \u670d\u52a1\u5e73\u53f0\uff0c\u5305\u62ec\u4e86\u6570\u636e\u9884\u5904\u7406\uff0c\u6807\u6ce8\uff0c\u6a21\u578b\u8bad\u7ec3\uff0c\u6253\u5206\uff0c\u8bc4\u4f30\uff0cAutoML \u4ee5\u53ca\u6a21\u578b\u63a8\u7406\u7b49\u673a\u5668\u5b66\u4e60\u5168\u6d41\u7a0b\u3002\u76ee\u524d\u5b57\u8282\u5185\u5404\u5927\u4ea7\u54c1\uff0c\u5305\u62ec\u6296\u97f3\uff0cTikTok\uff0c\u5934\u6761\uff0c\u897f\u74dc\uff0c\u756a\u8304\u7b49\u90fd\u6709\u4f7f\u7528\u8be5\u5e73\u53f0\u63d0\u4f9b\u7684\u76f8\u5173\u81ea\u7136\u8bed\u8a00\u80fd\u529b\u3002RayRTC \u901a\u8fc7\u7b97\u6cd5\u4e0e\u7cfb\u7edf\u7684\u534f\u540c\u8bbe\u8ba1\u53ca Serverless \u7b49\u6280\u672f\u4e3a RTC \u63d0\u4f9b\u4e86\u6027\u80fd\u548c\u8d44\u6e90\u5229\u7528\u7387\u7684\u6781\u81f4\u4f18\u5316\uff0c\u5e76\u7531\u6b64\u62bd\u8c61\u51fa\u4e00\u5957\u901a\u7528\u7684 Serverless ML \u6846\u67b6\uff0c\u76ee\u524d\u5df2\u5728\u5b57\u8282\u5185\u90e8\u673a\u5668\u5b66\u4e60\u5e73\u53f0\u4e0a\u90e8\u7f72\u4e0a\u7ebf\u3002<\/p>\n<p>RayRTC \u7684\u6838\u5fc3\u8ba1\u7b97\u5f15\u64ce\u662f Ray\uff0c\u6700\u65e9\u662f UC Berkeley \u7684\u4e00\u4e2a\u9488\u5bf9\u5f3a\u5316\u5b66\u4e60\u6240\u8bbe\u8ba1\u7684\u5927\u89c4\u6a21\u5206\u5e03\u5f0f\u8ba1\u7b97\u6846\u67b6\u3002Ray \u7684\u4f5c\u8005 Robert Nishihara \u548c Philipp Moritz \u5728\u6b64\u57fa\u7840\u4e0a\u6210\u7acb\u4e86 Anyscale \u8fd9\u5bb6\u516c\u53f8\u3002\u5f00\u6e90\u9879\u76ee\u5343\u5343\u4e07\uff0c\u80fd\u6210\u529f\u5546\u4e1a\u5316\u5e76\u5728\u7845\u8c37\u4e43\u81f3\u6574\u4e2a IT \u5c4a\u4ea7\u751f\u98a0\u8986\u6027\u5f71\u54cd\u7684\u51e4\u6bdb\u9e9f\u89d2\u3002Anyscale \u7684\u521b\u59cb\u4eba\u4e2d\u5305\u62ec Ion Stoica\uff0c\u8fd9\u4f4d\u7f57\u9a6c\u5c3c\u4e9a\u7c4d\u6559\u6388\u4e0a\u4e00\u5bb6\u516c\u53f8\u662f\u8ddf\u4ed6\u7684\u5b66\u751f Matei Zaharia \u4ee5 Spark \u6280\u672f\u4e3a\u57fa\u7840\u6210\u7acb\u7684 Databricks \u3002Spark \u548c Ray \u5206\u522b\u8bde\u751f\u4e8e\u5927\u6570\u636e\u548c\u673a\u5668\u5b66\u4e60\u65f6\u4ee3\uff0c\u524d\u8005\u5df2\u7ecf\u5728\u5de5\u4e1a\u754c\u5f97\u5230\u5e7f\u6cdb\u5e94\u7528\uff0c\u540e\u8005\u4e5f\u9010\u6e10\u5f15\u8d77\u8d8a\u6765\u8d8a\u591a\u7684\u516c\u53f8\u5728\u4e0d\u540c\u4e1a\u52a1\u573a\u666f\u8fdb\u884c\u63a2\u7d22\u3002\u5b57\u8282\u7f8e\u7814\u8ba1\u7b97\u56e2\u961f\u81ea 2020 \u5e74\u672b\u5f00\u59cb\u63a5\u89e6 Ray\uff0c2021 \u5e74\u5f00\u59cb\u5728\u4e0d\u540c\u573a\u666f\u5c0f\u8303\u56f4\u8bd5\u9a8c\u3002RTC \u6587\u672c\u5206\u7c7b\u5e73\u53f0\u662f\u7b2c\u4e00\u4e2a\u5927\u89c4\u6a21\u4e0a\u7ebf\u7684 Ray \u5e94\u7528\u573a\u666f\uff0c\u5728 RayRTC \u7684\u8bbe\u8ba1\u8fc7\u7a0b\u4e2d\uff0c\u6709\u4e0d\u5c11\u7b2c\u4e00\u624b\u7684\u7ecf\u9a8c\u503c\u5f97\u5206\u4eab\u3002\u672c\u6587\u4ece RayRTC \u6240\u9047\u5230\u7684\u5b9e\u9645\u95ee\u9898\u51fa\u53d1\uff0c\u5bf9 Ray \u5728\u5b57\u8282\u7684\u5b9e\u8df5\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n<p>\u7b2c\u4e00\u6b21\u63a5\u89e6 Ray \u7684\u8bfb\u8005\u53ef\u80fd\u4f1a\u95ee\uff0c\u9664\u4e86\u660e\u661f\u521b\u59cb\u4eba\u56e2\u961f\uff0c\u6df1\u5ea6\u8d34\u8fd1\u5f53\u524d ML \u9700\u6c42\u7684\u4ea7\u5b66\u7814\u652f\u6301\uff0cRay \u8fd9\u5957\u6846\u67b6\u5230\u5e95\u6709\u54ea\u4e9b\u5438\u5f15\u4eba\u7684\u5730\u65b9\uff1f<\/p>\n<p>\u9996\u5148\u662f\u4ee5 Ray \u4e3a\u5e95\u5ea7\u53ef\u4ee5\u975e\u5e38\u8f7b\u677e\u6784\u5efa\u5b8c\u6574\u673a\u5668\u5b66\u4e60\u5b8c\u6574\u751f\u6001\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s4.\/oss\/202206\/02\/f198690904788ff9e7555195583a7012118fba.png\" style=\"width: 729px;height: 359px\" class=\"aligncenter\"><\/p>\n<p>\u673a\u5668\u5b66\u4e60\u7684\u7814\u53d1\u4eba\u5458\u5f80\u5f80\u4e0d\u4ec5\u9700\u8981\u5173\u6ce8\u7b97\u6cd5\u672c\u8eab\uff0c\u5728\u5b9e\u9645\u7684\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u5404\u4e2a\u73af\u8282\u6240\u6d89\u53ca\u7684\u5de5\u7a0b\u91cf\u548c\u8fd0\u7ef4\u91cf\u4e5f\u4e0d\u5bb9\u5c0f\u89d1\u3002\u4e0d\u5c11\u7814\u7a76\u8868\u660e\uff0c\u5de5\u7a0b\u5e08\u4eec\u6709 80-90%\u7684\u65f6\u95f4\u548c\u7cbe\u529b\u6295\u5165\u5728\u4e86\u7b97\u6cd5\u4e4b\u5916\u7684\u6570\u636e\u5904\u7406\uff0c\u5168\u6d41\u7a0b\u6253\u901a\u7b49\u3002Ray \u793e\u533a\u5728\u8fd1\u51e0\u5e74\u7684\u6f14\u8fdb\u4e2d\uff0c\u4e0d\u65ad\u5438\u6536\u4e1a\u754c\u9886\u5148\u7684\u7406\u5ff5\uff0c\u79ef\u6781\u5730\u4e0e\u5176\u4ed6\u5f00\u6e90\u793e\u533a\u548c\u5404\u5927\u5382\u5546\u8fdb\u884c\u5408\u4f5c\u4ea4\u6d41\u3002\u4ee5 Ray \u4e3a\u8ba1\u7b97\u5f15\u64ce\u7684\u4e0a\u5c42\u751f\u6001\u7684\u4e30\u5bcc\u5ea6\u662f\u522b\u7684\u5f00\u6e90\u751f\u6001\u4e2d\u4e0d\u5e38\u89c1\u7684\u3002\u6bd4\u5982\u5927\u6570\u636e\u5904\u7406\u65b9\u9762\uff0c\u6709 Intel \u8bbe\u8ba1\u7684 RayDP\uff0c\u5c06 Spark \u65e0\u7f1d\u96c6\u6210\u5230 Ray \u4e2d\uff0c\u901a\u8fc7 Ray \u7684 Actor \u62c9\u8d77 Spark \u7684 executor\uff0c\u5229\u7528 Ray \u7684\u5206\u5e03\u5f0f\u8c03\u5ea6\u5b9e\u73b0\u8d44\u6e90\u7ec6\u7c92\u5ea6\u7684\u8c03\u63a7\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u5728\u4e8e\u4ee5 Spark \u4e3a\u5927\u6570\u636e\u5f15\u64ce\u7684\u673a\u5668\u5b66\u4e60\u5e94\u7528\u4e2d\uff0c\u901a\u8fc7 Ray \u53ef\u4ee5\u5c06 Spark \u4ea7\u751f\u7684 dataframe \u4ee5 ML Dataset \u7684\u5f62\u5f0f\u76f4\u63a5\u4ece\u5185\u5b58\u4f20\u7ed9\u4e0b\u6e38\u7684\u673a\u5668\u5b66\u4e60\u6846\u67b6\uff0c\u6bd4\u5982 PyTorch\u3002\u800c Ray \u7684\u751f\u6001\u91cc\u7684\u5176\u4ed6\u7ec4\u4ef6\uff0c\u6bd4\u5982\u8d85\u53c2\u8bad\u7ec3\uff08Ray Tune\uff09\u548c\u63a8\u7406\u670d\u52a1\uff08Ray Serve\uff09\uff0c\u5219\u8fdb\u4e00\u6b65\u8865\u8db3\u4e86\u8bad\u7ec3\u9636\u6bb5\u540e\u7eed\u7684\u4e00\u7cfb\u5217\u5de5\u7a0b\u9700\u6c42\u3002\u7814\u53d1\u4eba\u5458\u53ef\u4ee5\u629b\u5f00\u7e41\u7410\u7684\u4e0a\u7ebf\u90e8\u7f72\u6d41\u7a0b\uff0c\u5b9e\u73b0\u4e00\u952e\u5206\u5e03\u5f0f\u4ee5\u53ca\u4e00\u952e\u90e8\u7f72\u3002<\/p>\n<p>Ray \u7684\u53e6\u4e00\u4e2a\u663e\u8457\u4f18\u52bf\u662f\u5176\u7b80\u5355\u901a\u7528\u7684 API&nbsp;\uff0c\u53ea\u9700\u5728\u4e00\u6bb5\u51fd\u6570\u4e0a\u52a0\u5165ray.remote&nbsp;\u7684\u88c5\u9970\u5668\uff0c\u4fbf\u53ef\u5c06\u4e00\u4e2a\u5355\u673a\u7a0b\u5e8f\u53d8\u6210\u5206\u5e03\u5f0f\u6267\u884c\u5355\u5143\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>#declare a Ray task<br>@ray.remote<br>def fun(a):<br>    return a + 1<br><br>#submit and execute a Ray task<br>fun.remote()<br><br>#declare a Ray actor<br>@ray.remote<br>class Actor():<br>    def fun(slef, a):<br>        return a+1<br>actor = Actor.remote()<br>#execute an actor method<br>actor.fun.remote()<\/pre>\n<p>Ray \u4e2d\u6700\u57fa\u7840\u7684\u6982\u5ff5\u5305\u62ec Task \u548c Actor\uff0c\u5206\u522b\u5bf9\u5e94\u51fd\u6570\u548c\u7c7b\u3002\u51fd\u6570\u4e00\u822c\u662f\u65e0\u72b6\u6001\u7684\uff0c\u5728 Ray \u91cc\u88ab\u5c01\u88c5\u6210 Task\uff0c\u4ece\u800c\u88ab Ray \u7684\u5206\u5e03\u5f0f\u7cfb\u7edf\u8fdb\u884c\u8c03\u5ea6\uff1b\u7c7b\u4e00\u822c\u662f\u6709\u72b6\u6001\u7684\uff0c\u5728 Ray \u91cc\u88ab\u6620\u5c04\u6210\u4e00\u4e2a Actor\u3002Actor \u7684\u8868\u8fbe\u6027\u66f4\u5f3a\uff0c\u80fd\u8986\u76d6\u5927\u591a\u6570\u7684\u5e94\u7528\u7a0b\u5e8f\u5b50\u6a21\u5757\u3002\u57fa\u4e8e Actor \u548c Task\uff0cRay \u5bf9\u7528\u6237\u66b4\u9732\u4e86\u8d44\u6e90\u7684\u6982\u5ff5\uff0c\u5373\u6bcf\u4e2a actor \u6216 task \u90fd\u53ef\u4ee5\u6307\u5b9a\u8fd0\u884c\u6240\u9700\u8981\u7684\u8d44\u6e90\uff0c\u8fd9\u5bf9\u5f02\u6784\u7684\u652f\u6301\u4ece\u5f00\u53d1\u4eba\u5458\u7684\u89d2\u5ea6\u53d8\u5f97\u975e\u5e38\u4fbf\u5229\u3002\u6bd4\u5982\uff1a<\/p>\n<pre>@ray.remote(num_cpus=1, num_gpus=0.2):<br>def infer(data):<br>    return model(data)<\/pre>\n<p>\u5f53 task \u5728\u88ab\u63d0\u4ea4\u6267\u884c\u7684\u65f6\u5019\uff0cRay \u7684\u8c03\u5ea6\u5668\u4f1a\u53bb\u627e\u5230\u4e00\u4e2a\u6ee1\u8db3\u6307\u5b9a\u8d44\u6e90\u9700\u6c42\u7684\u8282\u70b9\u3002\u5728\u6b64\u540c\u65f6 Ray \u4f1a\u8003\u8651\u6570\u636e\u7684 locality\u3002\u6bd4\u5982\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\u7684\u201cdata\u201d\uff0c\u5b9e\u9645\u8fd0\u884c\u4e2d\u53ef\u80fd\u4f1a\u5206\u5e03\u5728\u4efb\u610f\u4e00\u4e2a\u8fdc\u7aef\u7684\u8282\u70b9\u7684\u5185\u5b58\u91cc\uff0c\u5982\u679c task \u4e0d\u5728\u6570\u636e\u6240\u5728\u7684\u8282\u70b9\u4e0a\u6267\u884c\uff0c\u8de8\u8282\u70b9\u7684\u6570\u636e\u4f20\u8f93\u5c31\u65e0\u6cd5\u907f\u514d\u3002\u800c Ray \u53ef\u4ee5\u8ba9\u8fd9\u4e00\u7c7b\u7684\u4f18\u5316\u53d8\u5f97\u900f\u660e\u3002\u6846\u67b6\u5f00\u53d1\u4eba\u5458\u4e5f\u53ef\u4ee5\u5229\u7528 Ray \u7684 API \u96c6\u6210\u66f4\u4e30\u5bcc\u8c03\u5ea6\u7b56\u7565\uff0c\u6700\u7ec8\u63d0\u4f9b\u7ed9\u7528\u6237\u7684\u662f\u975e\u5e38\u7b80\u5355\u7684 API\u3002Ray \u5bf9 Actor \u548c Task \u8fd8\u6709\u5f88\u591a\u9ad8\u7ea7\u7684\u7ec6\u7c92\u5ea6\u63a7\u5236\u7279\u6027\uff0c\u6bd4\u5982\u652f\u6301 gang-scheduling \u7684 placement group \u7b49\uff0c\u5728\u6b64\u4e0d\u4e00\u4e00\u8d58\u8ff0\u3002<\/p>\n<p><strong>Ray \u53e6\u5916\u7684\u4f18\u52bf\u5728\u4e8e\uff1a<\/strong><\/p>\n<p><strong>\u9ad8\u6548\u7684\u6570\u636e\u4f20\u9012\u548c\u5b58\u50a8\uff1a<\/strong>Ray \u901a\u8fc7\u5171\u4eab\u5185\u5b58\u5b9e\u73b0\u4e86\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684 plasma \u5206\u5e03\u5f0f object store\u3002\u6570\u636e\u901a\u8fc7 Apache Arrow \u683c\u5f0f\u5b58\u50a8\u3002<\/p>\n<p><strong>\u5206\u5e03\u5f0f\u8c03\u5ea6\uff1a<\/strong>Ray \u7684\u8c03\u5ea6\u662f decentralized\uff0c\u6bcf\u4e2a\u8282\u70b9\u4e0a\u7684 raylet \u90fd\u53ef\u4ee5\u8fdb\u884c\u8c03\u5ea6\uff1braylet \u901a\u8fc7\u5411 gcs \u53d1\u9001 heart beat \u83b7\u53d6\u5168\u5c40\u4fe1\u606f\uff0c\u5728\u672c\u5730\u4f18\u5148\u8c03\u5ea6\u4e0d\u80fd\u6ee1\u8db3\u7684\u60c5\u51b5\u4e0b\uff0c\u5feb\u901f\u8ba9\u4f4d\u7ed9\u5468\u8fb9 raylet \u8fdb\u884c\u8c03\u5ea6\u3002<\/p>\n<p><strong>\u591a\u8bed\u8a00\u7684\u652f\u6301\uff1a<\/strong>\u76ee\u524d\u5df2\u7ecf\u652f\u6301\u7684\u8bed\u8a00\u5305\u62ec\uff1aPython, Java, C++\u3002\u540e\u7eed go \u7684\u652f\u6301\u4ee5\u53ca\u66f4\u901a\u7528\u7684\u591a\u8bed\u8a00\u67b6\u6784\u8bbe\u8ba1\u4e5f\u5728\u8fdb\u884c\u4e2d\u3002<\/p>\n<p style=\"text-align: justify\">\u4e0b\u56fe\u662f RayRTC \u7684\u4e00\u4e2a\u65e9\u671f\u8bbe\u8ba1\u89c4\u5212\u56fe\u548c\u9636\u6bb5\u4e00\u6838\u5fc3\u90e8\u5206\uff08DP+Training\uff09\u7684 Actor \u5c01\u88c5\u6d41\u7a0b\u56fe\u3002\u672c\u6587\u7740\u91cd\u8bb2\u89e3\u9636\u6bb5\u4e00\uff0c\u4e8c\u7684\u8bbe\u8ba1\u548c\u5b9e\u73b0\u3002\u5176\u4e2d\u5728\u9636\u6bb5\u4e00\u4e2d\u6240\u7528\u5230\u7684\u6838\u5fc3\u7ec4\u4ef6\u5305\u62ec Ray Actor Pool \u548c RaySGD \u7b49\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s2.\/oss\/202206\/02\/c7e42e6194cdfa45a9b2516fc99cdfed5d51bf.png\" style=\"width: 729px;height: 506px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u201cDP+Training\u201d Actor \u5316\u6d41\u7a0b\u56fe\uff1a<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s6.\/oss\/202206\/02\/a42a525645fb5c63cf40051d78eab783288089.png\" style=\"width: 729px;height: 122px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u5176\u4e2d\u4e3b\u8981\u5305\u62ec DataProcessing \u548c Training \u4e24\u4e2a Stage\u3002\u6bcf\u4e00\u90e8\u5206\u7684\u6838\u5fc3\u8ba1\u7b97\u903b\u8f91\u90fd\u7528 Ray \u7684 API \u5c01\u88c5\u6210\u4e3a Actor \u6216 Task\u3002Actor \u63d0\u4ea4\u8fd0\u884c\u540e\u901a\u8fc7 Ray \u7684\u8c03\u5ea6\u88ab\u653e\u7f6e\u5230\u5408\u9002\u7684\u8282\u70b9\u4e0a\u6267\u884c\u3002Ray \u7684\u96c6\u7fa4\u8d44\u6e90\u53ef\u4ee5\u901a\u8fc7\u6539\u9020\u540e\u7684 Autoscaler \u5728\u5b57\u8282\u5185\u7684 Yarn\/K8S \u96c6\u7fa4\u4e0a\u5b9e\u73b0\u52a8\u6001\u6269\u7f29\u5bb9\u3002<\/p>\n<p style=\"text-align: justify\">DP \u5b9e\u73b0\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u5229\u7528 Ray \u7684 ActorPool \u89e3\u51b3\u4e86\u4e00\u4e2a\u56e0\u4e3a\u521b\u5efa Actor \u6570\u76ee\u8fc7\u591a\u800c\u5bfc\u81f4\u7684 OOM \u95ee\u9898\u3002Actorpool \u672c\u8eab\u76f8\u5f53\u4e8e\u4e00\u4e2a\u7ebf\u7a0b\u6c60\uff0c\u4f46 Ray \u7684 Actorpool \u53ef\u4ee5\u88ab\u5f00\u53d1\u8005\u62d3\u5c55\u4e3a\u66f4\u9ad8\u9636\u7684\u5f39\u6027\u7ebf\u7a0b\u6c60\u3002\u5728 RayRTC \u4e2d\uff0c\u7ed9\u5b9a\u4e00\u7ec4\u6570\u636e\uff0c\u6211\u4eec\u9700\u8981\u89e3\u51b3\u7684\u6838\u5fc3\u95ee\u9898\u4e4b\u4e00\u662f\u4f7f\u7528\u591a\u5c11 Ray \u7684 actor \u662f\u6bd4\u8f83\u9ad8\u6548\u7684\u3002\u8fd9\u91cc\u7684\u9ad8\u6548\u6307\uff1a\u8d44\u6e90\u4f7f\u7528\u9ad8\u6548\uff0c\u6027\u80fd\u8f83\u4f18\u4e14\u7a33\u5b9a\u6027\u8f83\u597d\uff08\u4e0d\u80fd oom\uff09\u7b49\u3002\u6700\u7b80\u5355\u7684\u8bbe\u8ba1\u65b9\u5f0f\u662f 1 \u5bf9 1\uff0c\u5373\u5bf9\u4e8e\u6bcf\u4e00\u4e2a HDFS \u8def\u5f84, \u90fd\u6307\u5b9a\u4e00\u4e2a\u5355\u72ec\u7684 DP Actor \u6765\u8fdb\u884c\u5904\u7406\u3002\u4f46\u5f53\u6570\u636e\u91cf\u7ebf\u6027\u589e\u957f\u65f6\uff0c\u7531\u4e8e\u7f3a\u5c11\u5185\u5b58\u7ba1\u63a7\u800c\u5f88\u5bb9\u6613\u51fa\u73b0 OOM\u3002\u6700\u6781\u7aef\u7684\u65b9\u5f0f\u662f n \u5bf9 1\uff0c\u5373\u7528\u4e00\u4e2a actor\uff0c\u987a\u5e8f\u5904\u7406\u6240\u6709\u6570\u636e\uff0c\u8fd9\u6837\u505a\u663e\u7136\u65e0\u6cd5\u53d1\u6325 Ray \u7684\u5206\u5e03\u5f0f\u80fd\u529b\u3002\u6bd4\u8f83\u7406\u60f3\u7684\u65b9\u5f0f\u662f n \u5bf9 m\uff0c\u5373 m \u4e2a actor \u5904\u7406 n \u7ec4\u6570\u636e\u3002\u4f5c\u4e3a\u5bf9\u6bd4\uff0c1 \u5bf9 1 \u7684\u60c5\u51b5\u5982\u4e0b\uff1a<\/p>\n<pre>ray_preprocessor_ret_refs = []<br>for hdfs_file_path in hdfs_file_path_list:<br>    my_dp = ray.remote(DP).remote(hdfs_file_path)<br>    ray_preprocessor_ret_refs.append(my_dp.__call__.remote())<\/pre>\n<p>n \u5bf9 m \u7684\u60c5\u51b5\uff1a<\/p>\n<pre>num_cpus = 10<br>actors = [ray.remote(DP).remote() for _ in range(num_cpus)]<br>actor_pool = ray.util.ActorPool(actors)<br>for hdfs_file_path in hdfs_file_path_list:<br>    actor_pool.submit(lambda actor, info: actor.__call__.remote(**info),<br>                                  hdfs_file_path)<\/pre>\n<p>\u5728\u751f\u4ea7\u5b9e\u8df5\u4e2d\uff0c\u901a\u8fc7\u5bf9 m \u53d6\u4e00\u4e2a\u5b9a\u503c\uff0c\u6bd4\u5982 m=10\uff0c\u53ef\u4ee5\u6709\u6548\u63a7\u5236\u5185\u5b58\u4f7f\u7528\u5e76\u5b9e\u73b0 I\/O \u5e76\u884c\u3002\u5982\u524d\u6240\u8ff0\uff0c\u7ed9\u5b9a\u4e00\u4e2a\u52a8\u6001\u7684 workload\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u5bf9 m \u7684\u8fdb\u884c\u5f39\u6027\u652f\u6301\uff0c\u7c7b\u4f3c\u4e8e K8S \u7684 HPA \u6216 Spark \u7684 dynamic allocation\u3002\u4e0d\u540c\u7684\u662f\uff0c\u5728 Ray \u91cc\uff0c\u5f00\u53d1\u8005\u901a\u8fc7\u53ef\u7f16\u7a0b\u7684\u65b9\u5f0f\u5b9e\u73b0\u5b9a\u5236\u5316\u7684 dynamic allocation\uff0c\u6bd4\u8f83\u7b80\u5355\u7684\u5b9e\u73b0\u4efb\u610f\u7c92\u5ea6\u7684\u81ea\u52a8\u6269\u7f29\u3002\u8fd9\u4e00\u90e8\u5206\u7684\u4ee3\u7801\u53ef\u4ee5\u53c2\u8003\u6700\u65b0\u7248\u672c\u7684 Ray dataset \u4e2d\u7684\u7c7b\u4f3c\u5b9e\u73b0\uff08https:\/\/github.com\/ray-project\/ray\/blob\/master\/python\/ray\/data\/impl\/compute.py\uff09\u3002<\/p>\n<p style=\"text-align: justify\">Training \u90e8\u5206\u7684\u903b\u8f91\u7531\u4e8e\u5386\u53f2\u539f\u56e0\uff0c\u5728\u5b57\u8282\u7684\u5185\u90e8\u573a\u666f\u6709\u6bd4\u8f83\u590d\u6742\u7684\u6df1\u5ea6\u5b9a\u5236\u3002\u5bf9\u6b64\uff0c\u6211\u4eec\u91c7\u7528\u4e86 Ray \u793e\u533a\u7b2c\u4e00\u7248\u7684 Ray SGD\uff08\u6700\u65b0\u7684\u7248\u672c\u4e2d\uff0c\u8fd9\u4e00\u6a21\u5757\u4e3a Ray Train\uff09\u5bf9\u5df2\u6709\u8bad\u7ec3\u6a21\u5757\u8fdb\u884c\u5c01\u88c5\u3002RaySGD \u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5206\u5e03\u5f0f\u8bad\u7ec3\u6846\u67b6\uff0c\u652f\u6301 PyTorch \u548c TensorFlow\u3002\u5e95\u5c42\u76f4\u63a5\u96c6\u6210\u4e86 PyTorch \u7684 DDP \u548c Tensorflow \u7684 MirroredStrategy \u6765\u8fdb\u884c\u6570\u636e\u5e76\u884c\u3002RaySGD \u901a\u8fc7\u628a\u8bad\u7ec3 worker \u7528 actor \u8fdb\u884c\u5c01\u88c5\uff0c\u4e0d\u4ec5\u5b9e\u73b0\u4e86\u66f4\u7075\u6d3b\u7684\u5206\u5e03\u5f0f\u7edf\u4e00\u8c03\u5ea6\uff0c\u800c\u4e14\u4e0e\u6574\u4e2a Ray \u751f\u6001\u6253\u901a\u3002\u6bd4\u5982\u53ef\u4ee5\u4e0e Ray Tune\uff08\u8d85\u53c2\uff09\u548c Ray Serve(\u63a8\u7406)\u76f4\u63a5\u5728 actor \u8fd9\u4e00\u7c92\u5ea6\u4e0a\u8fdb\u884c\u901a\u4fe1\u548c\u6570\u636e\u4f20\u8f93\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s8.\/oss\/202206\/02\/896a833667b4bb964693413298ffce7d1bfad0.png\" style=\"width: 729px;height: 496px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u6570\u636e\u5e76\u884c\u7684\u5206\u5e03\u5f0f\u8bad\u7ec3\u76f8\u6bd4\u6a21\u578b\u5e76\u884c\u548c\u6df7\u5408\u5e76\u884c\u7684\u6a21\u5f0f\u90fd\u8981\u76f8\u5bf9\u7b80\u5355\u3002\u4f46\u628a\u4e00\u4e2a\u590d\u6742\u7684\u5355\u673a\u7248 NLP \u8bad\u7ec3\u6846\u67b6\u901a\u8fc7 Ray \u5c01\u88c5\u4e3a\u5206\u5e03\u5f0f\u6846\u67b6\uff0c\u5e76\u505a\u5230\u5bf9\u539f\u4ee3\u7801\u4fb5\u5165\u6027\u6700\u5c0f\uff0c\u9700\u8981\u5904\u7406\u597d\u4ee5\u4e0b\u51e0\u4e2a\u95ee\u9898\uff1a<\/p>\n<ol>\n<li>\u5355\u8282\u70b9\u7684\u8bad\u7ec3\u903b\u8f91\uff0c\u5982\u4f55\u8bbe\u7f6e\u6a21\u578b\uff0c\u5982\u4f55\u5728 CPU \u548c GPU \u4e4b\u95f4\u4f20\u9012\u6570\u636e<\/li>\n<li>\u5982\u4f55\u8bbe\u7f6e dataloader \u4ee5\u53ca sampler\uff0c\u5b9e\u73b0\u5206\u5e03\u5f0f\u6570\u636e\u8bfb\u53d6<\/li>\n<li>\u5982\u4f55\u63a7\u5236\u4e00\u4e2a epoch \u91cc\u7684 batch \u5faa\u73af<\/li>\n<li>\u5206\u5e03\u5f0f\u8bad\u7ec3\u903b\u8f91\uff0c\u5982\u4f55\u8bbe\u7f6e worker \u6570\u91cf<\/li>\n<li>\u5982\u4f55\u4f7f\u7528 Ray \u62c9\u8d77 worker\uff0c\u5e76\u80fd\u5728 worker \u95f4\u901a\u4fe1<\/li>\n<\/ol>\n<p style=\"text-align: justify\">\u5bf9\u4e8e\u524d 3 \u4e2a\u95ee\u9898\uff0cRayRTC \u5b9e\u73b0\u4e86 RayRTCTrainoperator\uff0c\u7ee7\u627f\u81ea ray.util.sgd.torch \u4e2d\u7684 TrainingOperator\uff0c\u628a\u5355\u8282\u70b9\u4e0a\u7684\u8bad\u7ec3\u903b\u8f91\u5168\u90e8\u62bd\u8c61\u5230\u4e00\u4e2a\u7c7b\u3002<\/p>\n<pre>class RayRTCTrainOperator(TrainingOperator):<br>    def setup(self, config):<br>        # Setup data<br>        self.train_loader = DataLoader(self.train_data,...)<br>        self.valid_loader = DataLoader(self.valid_data,...)<br>        # Register data loader<br>        self.register_data(<br>            train_loader=self.train_loader,<br>            validation_loader=self.valid_loader)<br>        ...<br>        # Register model, optimizer<br>        self.model, self.optimizer = \\<br>            self.register(models=model, optimizers=optimizer,...)<\/pre>\n<p style=\"text-align: justify\">\u5728 RayRTCTrainOperator \u8fd9\u4e2a\u7c7b\u4e2d\uff0c\u9996\u5148\u8bbe\u7f6e\u597d\u8bad\u7ec3\u6240\u9700\u8981\u7684\u6a21\u578b\u548c\u6570\u636e\uff0c\u5e76\u5c06 optimizer\uff0cscheduler \u7b49\u53c2\u6570\u4f20\u5165\u3002\u8fd9\u4e9b\u6570\u636e\u4f1a\u968f\u7740 RayRTCTrainOperator \u8fd9\u4e2a\u7c7b\u88ab Ray \u5c01\u88c5\u4e3a actor\uff0c\u4ece\u800c\u5206\u5e03\u5230\u4e0d\u540c\u7684\u8282\u70b9\u4e0a\uff0c\u4ece\u800c\u4f7f\u5f97\u6bcf\u4e2a\u8282\u70b9\u4e0a\u90fd\u6709\u4e00\u4efd\u5b8c\u5168\u4e00\u6837\u7684\u6a21\u578b\u7684\u62f7\u8d1d\u548c\u53c2\u6570\u7684\u521d\u59cb\u72b6\u6001\u3002<\/p>\n<p><strong>\u6570\u636e\u683c\u5f0f\u7684\u4e0d\u540c\uff1a<\/strong><\/p>\n<p style=\"text-align: justify\">\u9664\u4e86\u6a21\u578b\u548c\u6570\u636e\u7684 setup\uff0c\u5177\u4f53\u7684\u8bad\u7ec3\u903b\u8f91\u9700\u8981\u6839\u636e RTC \u7684\u573a\u666f\u8fdb\u884c\u5b9a\u5236\u3002\u6bd4\u5982\uff0c\u6bcf\u4e00\u4e2a epoch \u7684\u8bad\u7ec3\uff0c\u4ee5\u53ca\u4e00\u4e2a epoch \u4e2d\u6bcf\u4e00\u4e2a batch \u7684\u8bad\u7ec3\u3002\u7531\u4e8e RaySGD \u5bf9\u4e8e input \u6709\u4e00\u5b9a\u7684\u683c\u5f0f\u5047\u8bbe\uff0c\u5bfc\u81f4\u5728 RayRTCTrainOperator \u4e2d\uff0c\u9700\u8981\u91cd\u5b9a\u4e49 train_epoch \u548c train_batch \u8fd9\u4e24\u4e2a\u51fd\u6570\u4ee5\u4fbf\u6b63\u786e\u5904\u7406\u6570\u636e\u548c metrics\u3002\u4e3e\u4f8b\u800c\u8a00\uff0c\u5728 RaySGD \u4e2d\uff0cbatch input \u9700\u8981\u7b26\u5408\u4ee5\u4e0b\u683c\u5f0f\uff1a<\/p>\n<pre>*features, target = batch<\/pre>\n<p>(https:\/\/github.com\/ray-project\/ray\/blob\/ray-1.3.0\/python\/ray\/util\/sgd\/torch\/training_operator.py#L536)<\/p>\n<p style=\"text-align: justify\">\u800c\u5b9e\u9645\u7684\u573a\u666f\u4e2d\uff0c\u7528\u6237\u5f80\u5f80\u5bf9\u6570\u636e\u683c\u5f0f\u6709\u81ea\u5df1\u7684\u5b9a\u4e49\u3002\u6bd4\u5982 RTC \u4e2d\uff0cbatch \u88ab\u5b9a\u4e49\u4e3a Dict:<\/p>\n<pre>TensorDict = Dict[str, Union[torch.Tensor, Dict[str, torch.Tensor]]]<\/pre>\n<p style=\"text-align: justify\">\u4f7f\u7528 RaySGD \u4e2d\u9ed8\u8ba4\u7684 train_batch \u51fd\u6570\uff0c\u4f1a\u5728\u6570\u636e unpack \u65f6\u5019\u53d1\u751f\u9519\u8bef\u3002\u5728 RayRTC \u4e2d\uff0c\u91cd\u5199\u7684 train_batch \u628a\u5904\u7406\u540e batch \u4ee5\u6b63\u786e\u7684\u683c\u5f0f\u4f20\u7ed9 forward \u51fd\u6570\u3002<\/p>\n<p><strong>\u8bad\u7ec3\u6307\u6807\u7684\u81ea\u5b9a\u4e49\u95ee\u9898\uff1a<\/strong><\/p>\n<p style=\"text-align: justify\">\u5728 train_epoch \u4e2d\uff0c\u540c\u6837\u6709\u9700\u8981\u7279\u6b8a\u5904\u7406\u7684\u5730\u65b9\u3002RaySGD \u9ed8\u8ba4\u652f\u6301\u7684 metrics \u53ea\u5305\u62ec loss \u7b49\u3002RTC \u4e2d\uff0c\u7528\u6237\u4e3b\u8981\u5173\u5fc3\u7684\u6307\u6807\u5305\u62ec accuracy, precision, recall \u4ee5\u53ca f1 measure \u7b49\u3002\u8fd9\u4e9b\u6307\u6807\u5982\u4f55\u5728 RaySGD \u4e2d\u52a0\u5165\u662f RayRTC \u5b9e\u73b0\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u4e00\u4e2a\u4e0d\u5c0f\u7684\u6311\u6218\u3002\u4e00\u65b9\u9762\u7531\u4e8e RTC \u672c\u8eab\u5df2\u7ecf\u5b9e\u73b0\u4e86\u4e30\u5bcc\u7684 metrics \u8ba1\u7b97\u6a21\u5757\uff0c\u4e00\u65b9\u9762 RaySGD \u5bf9\u8bad\u7ec3\u8fc7\u7a0b\u4e2d metrics \u7684\u5904\u7406\u6709\u56fa\u5b9a\u7684\u5047\u8bbe\u548c\u4e14\u5c01\u88c5\u5728\u6bd4\u8f83\u5e95\u5c42\u3002RayRTC \u6700\u7ec8\u91c7\u53d6\u7684\u65b9\u6cd5\u662f\u628a RTC \u4e2d\u7684 metrics \u8ba1\u7b97\u6a21\u5757\u590d\u7528\u5230 RaySGD \u7684 train_epoch \u4e2d\u3002\u53e6\u5916\u9047\u5230\u7684\u4e00\u4e2a\u95ee\u9898\u662f RTC \u7684 metrics \u8ba1\u7b97\u9700\u8981\u628a model \u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\uff0c\u800c RaySGD \u4e2d\u7684 model \u5df2\u7ecf\u88ab DDP \u5c01\u88c5\uff0c\u76f4\u63a5\u4f20\u5165\u4f1a\u5bfc\u81f4\u51fa\u9519\u3002\u6700\u540e\uff0ctrain_epoch \u9700\u8981\u52a0\u5165\u5982\u4e0b\u6539\u52a8\uff1a<\/p>\n<pre>if hasattr(model, 'module'):<br>  metrics = rtc.get_metrics(model.module, ... reset=True)<br>else:<br>  metrics = rtc.get_metrics(model, ... reset=True)<\/pre>\n<p style=\"text-align: justify\">\u6539\u52a8\u4e4b\u540e\u540c\u65f6\u517c\u5bb9\u4e86\u5206\u5e03\u5f0f\u548c\u5355\u673a\uff08\u6ca1\u6709\u88ab DDP \u5c01\u88c5\uff09\u7684\u60c5\u51b5\u3002<\/p>\n<p style=\"text-align: justify\">RayRTCTrainOperator \u53ef\u4ee5\u7406\u89e3\u4e3a\u5355\u673a\u7684\u8bad\u7ec3\u6a21\u5757\uff0c\u5230\u4e86\u5206\u5e03\u5f0f\u73af\u5883\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7 TorchTrainer \u8fd9\u4e2a\u7c7b\u3002\u5982\u4e0b\u6240\u793a:<\/p>\n<pre>trainer = TorchTrainer(<br>    training_operator_cls=RayRTCTrainOperator,<br>    num_workers=self.num_workers,<br>    use_fp16=self.use_fp16,<br>    use_gpu=self.use_gpu,<br>    ...<br>    num_cpus_per_worker=self.cpu_worker<br>)<\/pre>\n<p style=\"text-align: justify\">Trainer \u7684\u4e3b\u8981\u529f\u80fd\u662f\u8bbe\u7f6e training worker \u7684\u6570\u91cf\uff0c\u6df7\u5408\u7cbe\u5ea6\uff0c\u4ee5\u53ca worker \u7684 cpu \u548c gpu\u3002\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7 trainer \u53ef\u4ee5\u975e\u5e38\u7b80\u5355\u5730\u63a7\u5236\u6574\u4e2a\u5206\u5e03\u5f0f\u8bad\u7ec3\u7684\u903b\u8f91\uff1a<\/p>\n<pre>for epoch in epochs:<br>    metrics['train'] = trainer.train()<br>    metrics['validate'] = trainer.validate()<br>return metrics<\/pre>\n<p>Trainer \u7684\u5e95\u5c42\u903b\u8f91\u4e2d\u5305\u62ec\u4e86\u62c9\u8d77 worker group\uff08https:\/\/github.com\/ray-project\/ray\/blob\/8ce01ea2cc7eddd40c2415904fa94198c0fe1e44\/python\/ray\/util\/sgd\/torch\/worker_group.py#L195\uff09\uff0c\u6bcf\u4e00\u4e2aworker\u7528actor\u8868\u8fbe\uff0c\u4ece\u800c\u5f62\u6210\u4e00\u4e2aactor group\u3002RaySGD \u4e5f\u4f1a\u5904\u7406 communication group \u7684 setup\uff0c\u4ee5\u53ca actor \u7684\u5931\u8d25\u91cd\u542f\u3002\u7ecf\u8fc7\u8fd9\u4e9b\u5c01\u88c5\uff0c\u7528\u6237\u53ea\u9700\u8981\u5173\u6ce8\u8ddf\u8bad\u7ec3\u6700\u76f4\u63a5\u76f8\u5173\u7684\u903b\u8f91\uff0c\u800c\u4e0d\u9700\u8981\u82b1\u8fc7\u591a\u65f6\u95f4\u5728\u5e95\u5c42\u901a\u8baf\uff0c\u8c03\u5ea6\u7b49\u5206\u5e03\u5f0f\u903b\u8f91\uff0c\u6781\u5927\u63d0\u9ad8\u4e86\u7f16\u7a0b\u6548\u7387\u3002<\/p>\n<p><strong>Checkpoint \u7684\u95ee\u9898:<\/strong><\/p>\n<p style=\"text-align: justify\">\u5728\u6539\u9020\u57fa\u672c\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u7528\u6296\u97f3\u7684\u6570\u636e\u8fdb\u884c\u6d4b\u8bd5\uff0c\u53d1\u73b0\u6a21\u578b\u5728\u591a\u5361\u65f6\uff0c\u6ca1\u6709\u4efb\u4f55\u8c03\u53c2\u7684\u60c5\u51b5\u4e0b\uff0c\u6027\u80fd\u5df2\u7ecf\u53ef\u4ee5\u4e0e\u5355\u673a\u6301\u5e73\uff0c\u7b26\u5408\u4e0a\u7ebf\u8981\u6c42\u3002\u4f46\u7b2c\u4e00\u6b21\u4e0a\u7ebf\u6d4b\u8bd5\u540e\uff0c\u53d1\u73b0 RayRTC \u8bad\u7ec3\u51fa\u6765\u7684\u6a21\u578b\u8fde\u57fa\u7ebf\u6a21\u578b\u90fd\u6253\u4e0d\u8fc7\uff0c\u51c6\u786e\u7387\u751a\u81f3\u4f4e\u5230 30%\u3002\u5728\u628a\u6240\u6709\u63a7\u5236\u53d8\u91cf\u56fa\u5b9a\u4ecd\u7136\u6ca1\u6709\u6ca1\u6709\u627e\u5230\u539f\u56e0\u540e\uff0c\u7b2c\u4e00\u53cd\u5e94\u662f RayRTC \u8bad\u7ec3\u51fa\u6765\u7684\u6a21\u578b\u53ef\u80fd\u5e76\u6ca1\u6709\u771f\u6b63\u4fdd\u5b58\u4e0b\u6765\uff0c\u4ee5\u81f4\u7ebf\u4e0a\u6253\u5206\u7528\u5230\u7684\u5b9e\u9645\u662f pre-trained \u7684 bert \u6a21\u578b\u3002\u4e8b\u5b9e\u8bc1\u660e\u786e\u5b9e\u5982\u6b64\uff0c\u800c\u5bfc\u81f4\u8fd9\u4e2a\u539f\u56e0\u662f\u56e0\u4e3a RaySGD \u4e2d\u7684 training worker \u662f\u5728\u8fdc\u7aef\u8fd0\u884c\uff0cdriver \u7aef\u6240\u521d\u59cb\u7684\u6570\u636e\u7ed3\u6784\u968f\u7740\u8bad\u7ec3\u8fdb\u884c\u4f1a\u4e0e\u4e4b\u9010\u6e10\u4e0d\u540c\u6b65\u3002checkpointing \u4e4b\u524d\u9700\u8981\u53d6\u5f97\u66f4\u65b0\u540e\u7684\u6a21\u578b\u53c2\u6570\uff0c\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>for epoch in epochs:<br>    metrics['train'] = trainer.train()<br>    metrics['validate'] = trainer.validate()<br>    self.model = trainer.get_model()<br>    self.save_checkpoint()<br>return metrics<\/pre>\n<p style=\"text-align: justify\">\u4e0e\u4e4b\u524d\u6bd4\u8f83\uff0c\u589e\u52a0\u4e86\u7b2c 4 \u884c\uff0c\u901a\u8fc7 trainer \u83b7\u5f97\u66f4\u65b0\u540e\u7684 model\uff0c\u5e76\u901a\u8fc7 checkpoint \u5c06\u6a21\u578b\u6301\u4e45\u5316\u3002<\/p>\n<p><strong>\u6539\u9020\u4fb5\u5165\u6027\u95ee\u9898\uff1a<\/strong><\/p>\n<p style=\"text-align: justify\">Anyscale \u5728\u4e00\u7bc7\u535a\u5ba2[https:\/\/www.anyscale.com\/blog\/ray-distributed-library-patterns]\u4e2d\u603b\u7ed3\u4e86\u4f7f\u7528 Ray \u7684\u51e0\u79cd pattern\u3002\u5176\u4e2d\u5927\u81f4\u53ef\u4ee5\u5206\u4e3a\u4e09\u7c7b\uff0cRayRTC \u5c5e\u4e8e\u7b2c\u4e09\u7c7b\u3002<\/p>\n<ul>\n<li>\u7528 Ray \u505a\u8c03\u5ea6\uff0c\u6bd4\u5982 RayDP<\/li>\n<li>\u7528 Ray \u505a\u8c03\u5ea6\u548c\u901a\u4fe1\uff0c\u6bd4\u5982\u8682\u8681\u7684\u5728\u7ebf\u8d44\u6e90\u5206\u914d<\/li>\n<li>\u7528 Ray \u505a\u8c03\u5ea6\uff0c\u901a\u4fe1\uff0c\u6570\u636e\u5185\u5b58\u5b58\u50a8<\/li>\n<\/ul>\n<p style=\"text-align: justify\">\u4ece\u7b2c\u4e00\u7c7b\u5230\u7b2c\u4e09\u7c7b\uff0c\u7528 Ray \u7684\u5c42\u6b21\u52a0\u6df1\uff0c\u4f46\u5e76\u4e0d\u610f\u5473\u7740\u6539\u9020\u6210\u672c\u7ebf\u6027\u589e\u52a0\u3002\u5177\u4f53\u7684\u5e94\u7528\u9700\u8981\u5177\u4f53\u5206\u6790\u3002\u5355\u7eaf\u4ece\u4ee3\u7801\u6539\u52a8\u91cf\u4e0a\u5206\u6790\uff0cRayRTC \u7b2c\u4e00\u9636\u6bb5\u6539\u4e86\u5927\u6982 2000 \u884c\u4ee3\u7801\uff0c\u5360\u539f\u5e94\u7528\u603b\u4ee3\u7801\u91cf\u7684 1%\u4e0d\u5230\u3002<\/p>\n<p style=\"text-align: justify\">\u540c\u65f6\uff0cRayRTC \u628a\u8bad\u7ec3\u6a21\u5757\u5355\u72ec\u62bd\u8c61\u51fa\u6765\uff0c\u4e0e\u539f\u6709\u4ee3\u7801\u4fdd\u6301\u677e\u8026\u5408\u5173\u7cfb\u3002\u7528\u6237\u4f7f\u7528\u7684\u65f6\u5019\uff0c\u53ea\u9700\u8981\u8f7d\u5165\u76f8\u5173 RayRTC \u7684\u6a21\u5757\uff0c\u5373\u53ef\u542f\u52a8 Ray \u8fdb\u884c\u5206\u5e03\u5f0f\u8bad\u7ec3\u3002<\/p>\n<p><strong>\u5b9e\u9a8c\u6548\u679c\uff1a<\/strong><\/p>\n<p style=\"text-align: justify\">RayRTC \u7b2c\u4e00\u9636\u6bb5\u5728 1 \u5230 8 \u5361\uff08NVIDIA V100\uff09\u4e0a\u8fdb\u884c scaling \u6d4b\u8bd5\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s5.\/oss\/202206\/02\/4476679213d1754411e4411299b1961c2b0f6d.png\" style=\"width: 432px;height: 288px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u8bad\u7ec3\u901f\u5ea6\u4e0a\uff0cRayRTC \u7684\u6027\u80fd\u968f\u5361\u6570\u5448\u73b0\u7ebf\u6027\u589e\u52a0\u3002\u8bad\u7ec3\u51c6\u786e\u5ea6\u4e0a\uff0cRayRTC \u6ca1\u6709\u56e0\u4e3a global batch size \u7684\u589e\u52a0\u800c\u663e\u8457\u964d\u4f4e\u30028 \u5361\u8bad\u7ec3\u4e2d\uff0c\u5355\u4e2a epoch \u65f6\u95f4\u964d\u5230\u4e86 6 \u5206\u949f\u4ee5\u5185\u3002\u4ee5\u5f80\u7814\u53d1\u4eba\u5458\u5f80\u5f80\u9700\u8981\u7b49\u5f85\u51e0\u4e2a\u5c0f\u65f6\u624d\u80fd\u62ff\u5230\u8bad\u7ec3\u7ed3\u679c\uff0c\u5bfc\u81f4\u5927\u5bb6\u90fd\u4e60\u60ef\u5728\u4e0b\u73ed\u524d\u5927\u91cf\u63d0\u4ea4\u4f5c\u4e1a\uff0c\u7b2c\u4e8c\u5929\u518d\u6765\u67e5\u770b\u6548\u679c\u3002\u6574\u4f53\u96c6\u7fa4 quota \u8d44\u6e90\u5229\u7528\u7387\u5728\u767d\u5929\u4e0d\u9ad8\uff0c\u5728\u665a\u4e0a\u6392\u961f\u9ad8\u5cf0\u3002\u7ecf\u8fc7 RayRTC \u63d0\u901f\u540e\uff0c\u7814\u53d1\u4eba\u5458\u4f1a\u8d8a\u6765\u8d8a\u591a\u7684\u8fdb\u884c\u63a5\u8fd1\u4ea4\u4e92\u5f0f\u7684\u5f00\u53d1\u8fed\u4ee3\u3002<\/p>\n<h4>RayRTC pipeline<\/h4>\n<p style=\"text-align: justify\">RayRTC \u5728\u5b57\u8282\u5185\u90e8\u8fd0\u884c\u5728 Arnold \u673a\u5668\u5b66\u4e60\u5e73\u53f0\u3002\u7528\u6237\u5728\u63d0\u4ea4\u4e00\u4e2a RayRTC \u4efb\u52a1\u65f6\uff0c\u5bf9\u5e94\u5728 Arnold \u5e73\u53f0\u4e0a\u62c9\u8d77\u4e00\u4e2a Trial\u3002\u4e00\u4e2a Trial \u91cc\uff0c\u7528\u6237\u914d\u7f6e\u4e00\u4e2a\u6216\u591a\u4e2a container \u4ee5\u53ca\u6bcf\u4e2a container \u6240\u9700\u7684 CPU\/GPU\/Mem \u8d44\u6e90\u3002\u5728\u4e00\u4e2a RayRTC \u4efb\u52a1\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u4e2d\uff0c\u5bf9\u5e94 Trial \u7684\u8d44\u6e90\u662f\u4e00\u76f4\u5360\u7528\u7684\u3002\u4e0b\u56fe\u5c55\u793a\u4e86\u67d0 RTC \u4efb\u52a1\u8fd0\u884c\u671f\u95f4\u7684 GPU \u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s7.\/oss\/202206\/02\/911629c82557b1ae252757e16ecbdd1513839b.png\" style=\"width: 729px;height: 138px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u5982\u56fe\u6240\u793a\uff0c\u5728 Data Processing(DP)\u9636\u6bb5\uff0cGPU \u8d44\u6e90\u5b8c\u5168\u5904\u4e8e idle \u72b6\u6001\u3002\u9020\u6210\u8fd9\u4e2a\u73b0\u8c61\u7684\u4e3b\u8981\u539f\u56e0\u662f\u5f53\u524d\u7684 RayRTC \u9636\u6bb5\u4e00\u65b9\u6848\u867d\u7136\u5728 DP \u548c Training \u9636\u6bb5\u90fd\u5145\u5206\u5229\u7528 Ray \u7684\u5e76\u884c\u80fd\u529b\u8fdb\u884c\u52a0\u901f\uff0c\u4f46\u662f\u8fd9\u4e24\u4e2a stage \u4e4b\u95f4\u672c\u8d28\u8fd8\u662f\u4e32\u884c\u6267\u884c\uff1aTraining \u9636\u6bb5\u5fc5\u987b\u7b49\u5230 DP \u7ed3\u675f\u4e86\u624d\u5f00\u59cb\u3002\u5bf9\u4e8e DP \u65f6\u95f4\u957f\u7684 RayRTC \u4efb\u52a1\uff0c\u8fd9\u5c06\u5e26\u6765\u5f88\u5927\u7684 GPU \u8d44\u6e90\u6d6a\u8d39\u3002\u4e3a\u4e86\u63d0\u9ad8 GPU \u8d44\u6e90\u4f7f\u7528\u7387\uff0c\u6211\u4eec\u7ed3\u5408 Ray Datasets \u63d0\u4f9b\u7684 pipeline \u529f\u80fd\uff0c \u63d0\u51fa\u5e76\u5b9e\u73b0\u4e86 RayRTC \u7684\u6d41\u6c34\u5e76\u884c\u65b9\u6848 RayRTC pipeline\u3002<\/p>\n<p style=\"text-align: justify\">Ray Datasets \u662f\u5728 Ray1.6+\u7248\u672c\u5f15\u5165\u7684\u5728 Ray \u7684 libraries \u548c\u5e94\u7528\u4e4b\u95f4\u52a0\u8f7d\u548c\u4ea4\u6362\u6570\u636e\u6807\u51c6\u5316\u65b9\u6cd5\uff0c\u5176\u672c\u8eab\u63d0\u4f9b\u4e86\u4e00\u5b9a\u7684\u57fa\u672c\u5206\u5e03\u5f0f\u6570\u636e\u5904\u7406\u80fd\u529b\uff0c\u5982 map, filter, repartition \u7b49\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u6570\u636e\u7ecf\u8fc7 ETL \u540e\uff0c\u8fdb\u5165 ML Training \u7cfb\u7edf\u524d\uff0c\u53ef\u4ee5\u5148\u901a\u8fc7 Ray Datasets \u7684 API \u8fdb\u884c last mile \u7684\u9884\u5904\u7406\u3002\u6362\u8a00\u4e4b\uff0cRayRTC \u4e2d\u7684 DP \u90e8\u5206\uff0c\u5b8c\u5168\u53ef\u4ee5\u7528 Ray Datasets APIs \u8fd9\u79cd Ray \u6807\u51c6\u5316\u7684\u65b9\u5f0f\u91cd\u6784\uff0c\u5e76\u4e0e\u540e\u9762\u7684 RaySGD\uff08\u73b0 Ray Train\uff09\u6253\u901a\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s3.\/oss\/202206\/02\/46d77c470cd87005e2b201eb8938861984c4f1.png\" style=\"width: 729px;height: 234px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u9664\u4e86\u63d0\u4f9b last mile \u9884\u5904\u7406\u6807\u51c6\u5316 APIs, Ray Dataset s \u8fd8\u63d0\u4f9b\u4e86\u4e00\u7ec4\u975e\u5e38\u91cd\u8981\u7684 pipeline \u63a5\u53e3\uff0c\u4f7f\u5f97 DP \u90e8\u5206\u548c Training \u90e8\u5206\u7684\u6d41\u6c34\u5e76\u884c\u6267\u884c\u6210\u4e3a\u53ef\u80fd\u3002\u6240\u8c13\u6d41\u6c34\u5e76\u884c\u6267\u884c\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff0cTraining \u6267\u884c\u5e76\u4e0d\u4f1a\u7b49\u5230 DP \u5168\u90e8\u7ed3\u675f\u540e\u624d\u5f00\u59cb\uff0c\u800c\u662f\u4e00\u65e6 DP \u5b8c\u6210\u4e86\u4e00\u5c0f\u90e8\u5206\u5c31\u4f1a\u628a\u5904\u7406\u540e\u7684\u6570\u636e\u76f4\u63a5\u4f20\u5165 Training \u90e8\u5206\u3002\u6d41\u6c34\u5904\u7406\u6709\u6548\u51cf\u5c11 GPU idle \u65f6\u95f4\u5e76\u7f29\u77ed\u6574\u4e2a\u7aef\u5230\u7aef RTC \u8bad\u7ec3\u65f6\u95f4\u3002<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s2.\/oss\/202206\/02\/f96dd5f7274b37ba79c766eac958129f106ba7.png\" style=\"width: 522px;height: 180px\" class=\"aligncenter\"><\/p>\n<h3>\u57fa\u4e8e Ray Datasets \u7684 RayRTC pipeline \u5b9e\u73b0<\/h3>\n<p style=\"text-align: justify\">RayRTC pipeline \u7248\u672c\u4e00\uff1a\u628a DP \u90e8\u5206\u5f53\u505a\u9ed1\u76d2<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s6.\/oss\/202206\/02\/456421711bbf366b09585751a42aa526305140.png\" style=\"width: 729px;height: 168px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u8003\u8651\u5230 RTC \u4e2d DP \u7684\u590d\u6742\u903b\u8f91\uff0c\u5728 RayRTC pipeline \u7248\u672c\u4e00\u4e2d\uff0c\u6211\u4eec\u628a DP \u5f53\u4f5c\u9ed1\u76d2\u5904\u7406\u3002\u6539\u9020\u9700\u6c42\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>DP\uff08\u542b IO, trasforms, \u6570\u636e\u96c6 split \u7b49\u903b\u8f91\uff09\u4e0e Training \u9700\u8981\u4ee5 window \u7c92\u5ea6\u6d41\u6c34\u5e76\u884c\uff0c\u5176\u4e2d DP \u7684 input \u662f\u6587\u4ef6\u8def\u5f84 fp_i\uff0coutput \u662f\u8bad\u7ec3\u548c\u9a8c\u8bc1\u6570\u636e\u96c6{'T':Ti, 'V':Vi}\u3002<\/li>\n<li>DP \u4e2d\u7684 split \u903b\u8f91\u8981\u4fdd\u8bc1\u591a epoch \u8bad\u7ec3\u4e2d\u6bcf\u4e2a epoch \u62ff\u5230\u7684\u8bad\u7ec3\/\u9a8c\u8bc1\u6570\u636e\u96c6\u90fd\u76f8\u540c\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u6570\u636e\u6cc4\u9732\u3002\u591a epoch \u8bad\u7ec3\u4e2d\uff0c\u53ea\u6709\u7b2c\u4e00\u4e2a epoch \u62ff\u5230\u7684\u8bad\u7ec3\/\u9a8c\u8bc1\u6570\u636e\u96c6\u771f\u6b63\u7ecf\u5386 DP\uff0c\u5176\u4f59 epoch \u90fd\u590d\u7528\u4e4b\u524d\u5df2\u7ecf\u5904\u7406\u5206\u5272\u597d\u7684\u6570\u636e\u96c6\u3002<\/li>\n<\/ol>\n<p style=\"text-align: justify\">\u4e3a\u6ee1\u8db3\u4ee5\u4e0a\u9700\u6c42\uff0c\u6211\u4eec\u5229\u7528 Ray Datasets \u7684 API \u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>dsp= ray.data.from_items([fp1, fp2, \u2026., fpn],parallelism=n)<br>.window(blocks_per_window=2).map(dp).repeat().split(2)<\/pre>\n<p style=\"text-align: justify\">\u4f46\u662f\uff0c\u4ee5\u4e0a\u6539\u9020\u65e0\u6cd5\u6ee1\u8db3\u201c\u6bcf\u4e2a\u8bad\u7ec3 worker \u62ff\u5230\u76f8\u540c\u6570\u76ee\u7684 training instances\u201d\u8fd9\u4e2a\u9700\u6c42\uff0c\u56e0\u4e3a\u8be5\u6539\u9020\u4e2d\u7684 split \u7684\u7c92\u5ea6\u5176\u5b9e\u8fd8\u662f\u201c\u6587\u4ef6\u201d\u800c\u975e\u201ctraining instances\u201d\uff0c\u800c\u6bcf\u4e2a\u6587\u4ef6\u4e2d\u5305\u542b\u7684 training instances \u6570\u5f88\u53ef\u80fd\u4e0d\u4e00\u6837\u3002\u4e3a\u4e86\u6ee1\u8db3\u8fd9\u4e2a\u9700\u6c42\uff0c\u6211\u4eec\u66f4\u65b0\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>dsp_train= ray.data.from_items([fp1, fp2, \u2026., fpn],parallelism=n)<br>.window(blocks_per_window=2).map(dp).flat_map(takeT).repeat()<br>.split(2, equal=True)<br><br>dsp_valid= ray.data.from_items([fp1, fp2, \u2026., fpn],parallelism=n)<br>.window(blocks_per_window=2).map(dp).flat_map(takeV).repeat()<br>.split(2, equal=True)<\/pre>\n<p>\u5176\u4e2d\uff1a<\/p>\n<pre>def takeT(row):<br>    train_data = row['T'].iter_rows()<br>    for data in train_data:<br>        yield data.as_pydict()<br><br>def takeV(row):<br>    train_data = row['V'].iter_rows()<br>    for data in train_data:<br>        yield data.as_pydict()<\/pre>\n<p style=\"text-align: justify\">\u4f46\u662f\u66f4\u65b0\u540e\u7684\u5b9e\u73b0\u5e26\u6765\u4e86\u65b0\u95ee\u9898\uff1adsp_train \u548c dsp_valid \u5b9e\u9645\u5bf9\u5e94\u4e24\u6b21\u4e0d\u540c\u7684 DP split \u903b\u8f91\uff0c\u4ece\u800c\u5bfc\u81f4\u4e86\u6570\u636e\u6cc4\u9732\u3002\u6211\u4eec\u9700\u8981\u7c7b\u4f3c\u5982\u4e0b\u5b9e\u73b0\u6765\u89e3\u51b3\uff1a<\/p>\n<pre>dsp_train\uff0cdsp_valid = ray.data.from_items([fp1, fp2, \u2026., fpn],parallelism=n)<br>.window(blocks_per_window=2).map(dp).unzip_and_flat_map('T', 'V')<br>.repeat().split(2, equal=True)<\/pre>\n<p style=\"text-align: justify\">\u5176\u4e2d, unzip_and_flat_map \u65e2\u6709\u7c7b\u4f3c unzip \u529f\u80fd\uff0c\u628a\u539f\u6570\u636e\u96c6\u5206\u5272\u6210\u4e24\u4e2a\u6570\u636e\u96c6\uff0c\u539f\u6765\u6570\u636e\u96c6\u7684 Row={'T':Ti, 'V':Vi} \u53d8\u6210\u4e24\u4e2a\u65b0\u6570\u636e\u96c6\u7684 Row1=Ti\uff0cRow2=Vi\uff1b\u53c8\u6709 flat_map \u529f\u80fd\uff0c\u628a\u6570\u636e\u96c6\u7684 Row1=Ti \u771f\u6b63\u5c55\u5f00\u6210 Row=Training Instance\u3002\u8003\u8651\u5230\u8fd9\u4e2a API \u5b9e\u73b0\u590d\u6742\u4e14\u4e0d\u5177\u901a\u7528\u6027\uff0c\u6211\u4eec\u653e\u5f03\u4e86\u8be5\u7248\u672c\u6539\u9020\uff0c\u8f6c\u5411\u4e86 RayRTC pipeline \u7684\u7248\u672c\u4e8c\u5b9e\u73b0\uff0c\u628a DP \u4e2d\u7684\u6570\u636e\u96c6\u5206\u5272\u903b\u8f91\u62bd\u53d6\u51fa\u6765\u5e76\u63d0\u524d\uff0c\u4ece\u5f00\u59cb\u5c31\u6784\u9020\u72ec\u7acb\u7684\u8bad\u7ec3\/\u9a8c\u8bc1 pipeline\uff0c\u5176\u4f59\u5269\u4e0b\u7684 DP \u903b\u8f91\u4fdd\u7559\u3002<\/p>\n<p style=\"text-align: justify\"><strong>RayRTC pipeline \u7248\u672c\u4e8c\uff1a<\/strong>\u628a DP \u4e2d\u7684\u6570\u636e\u96c6 Split \u903b\u8f91\u62bd\u53d6\u51fa\u6765\u5e76\u63d0\u524d<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/s5.\/oss\/202206\/02\/99ef55e771c96b96d5992150db8e3bd80284bc.png\" style=\"width: 729px;height: 134px\" class=\"aligncenter\"><\/p>\n<p style=\"text-align: justify\">\u5728 RayRTC pipeline \u7248\u672c\u4e8c\u5b9e\u73b0\u4e2d\uff0c\u6211\u4eec\u5c06\u6570\u636e\u96c6 scaling \u548c split \u903b\u8f91\u62bd\u53d6\u51fa\u6765\u5f80\u524d\u79fb\uff0c\u5148\u6784\u9020\u8bad\u7ec3\u548c\u9a8c\u8bc1\u6570\u636e\u96c6\u3002\u7136\u540e\uff0c\u5206\u522b\u4ece\u8fd9\u4e24\u4e2a\u6570\u636e\u96c6\u6784\u9020\u76f8\u5e94\u7684\u8bad\u7ec3\/\u9a8c\u8bc1 pipelines\u3002\u5177\u4f53\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre>train_dataset, valid_dataset = self.get_datasets()<br><br>train_dataset_pipeline = train_dataset.window(blocks_per_window=2)<br>.flat_map(dp).repeat()<br>.random_shuffle_each_window().split(2, equal=True) # 2 is #trainWorkers<br><br>valid_dataset_pipeline = valid_dataset.window(blocks_per_window=2)<br>.flat_map(dp).repeat().split(2, equal=True) # 2 is #trainWorkers<\/pre>\n<p>\u5176\u4e2d:<\/p>\n<pre>def get_datasets(self):<br>    # read dataset from hdfs<br>    new_dataset = ray.data.read_api.read_json(partition_info_list)<br>    # scale dataset up<br>    scaled_dataset = new_dataset.flat_map(scale)<br>    # shuffle dataset<br>    shuffled_dataset = scaled_dataset.random_shuffle()<br>    # split dataset into training and validation datasets<br>    train_valid_ratio = 0.9<br>    return shuffled_dataset.split_at_indices([int(shuffled_dataset.count() * train_valid_ratio)])<\/pre>\n<p style=\"text-align: justify\">\u63a5\u7740\uff0ctrain_dataset_pipeline \u548c valid_dataset_pipeline \u88ab\u4f20\u5165 trainer\uff1a\u5728\u6bcf\u4e2a training worker \u7684 setup() \u4e2d\uff0c\u6839\u636e\u81ea\u5df1\u7684 rank \u5f97\u5230\u76f8\u5e94\u7684\u5b50 pipeline\u3002<\/p>\n<pre>self.train_dataset_pipeline = self.train_pipeline[self.world_rank]<br>self.train_dataset_pipeline_epoch = self.train_dataset_pipeline.iter_epochs()<br>self.valid_dataset_pipeline = self.valid_pipeline[self.world_rank]<br>self.valid_dataset_pipeline_epoch = self.valid_dataset_pipeline.iter_epochs()<\/pre>\n<p style=\"text-align: justify\">\u5728 training worker \u7684 train_epoch() \u4e2d\uff0c\u4ece\u5b50 training pipeline \u4e2d\u83b7\u53d6 training instances \u8bad\u7ec3\u3002<\/p>\n<pre>def train_epoch():<br>    dataset_for_this_epoch = next(self.train_dataset_pipeline_epoch)<br>    train_dataset = self.data_parser.parse(dataset_for_this_epoch)<br>    train_loader = DataLoader(train_dataset)<br>    for batch_idx, batch in enumerate(train_loader):<br>        metrics = self.train_batch(batch, batch_info)<\/pre>\n<p style=\"text-align: justify\">\u5728 training worker \u7684 validate() \u4e2d, \u4ece\u5b50 validation pipeline \u4e2d\u83b7\u53d6 validation instances \u9a8c\u8bc1\u3002<\/p>\n<pre>def validate():<br>    dataset_for_this_epoch = next(self.valid_dataset_pipeline_epoch)<br>    valid_dataset = self.data_parser.parse(dataset_for_this_epoch)<br>    valid_loader = DataLoader(valid_dataset)<br>    for batch_idx, batch in enumerate(valid_loader):<br>        metrics = self.validate_batch(batch, batch_info)<\/pre>\n<p><strong>\u5b9e\u9a8c\u6548\u679c\uff1a<\/strong><\/p>\n<p style=\"text-align: justify\">\u4e3a\u9a8c\u8bc1 RayRTC-pipeline \u6548\u679c\uff0c\u6211\u4eec\u968f\u673a\u9009\u62e9\u4e2d\u7b49\u89c4\u6a21 RTC training job \uff08\u7ea6 168 \u4e07\u6761 instance\uff09\uff0c\u4f7f\u7528\u540c\u7b49\u8ba1\u7b97\u8d44\u6e90\uff082CPUs, 2GPUs\uff09\u7b80\u5355\u505a\u4e86\u5982\u4e0b\u5bf9\u6bd4\u5b9e\u9a8c\u3002\u7ed3\u679c\u663e\u793a\uff0c\u4f7f\u7528 pipeline \u540e\uff0cGPU idle \u65f6\u95f4\u4ece\u539f\u6765\u7684 245s \u51cf\u5c11\u5230\u4e86 102s\uff0c\u7ea6 2.5 \u500d\u964d\u4f4e\u3002\u7aef\u5230\u7aef\u65f6\u95f4\u4e5f\u6bd4\u539f\u6765\u51cf\u5c11\u4e86 158s\u3002\u9664\u6b64\u4e4b\u5916\uff0c\u76f8\u6bd4\u4e8e\u9636\u6bb5\u4e00\u5b9e\u73b0\uff0c\u6211\u4eec\u4e0d\u4f46\u5728\u521d\u59cb\u9636\u6bb5\u5bf9\u6574\u4e2a\u6570\u636e\u96c6\u8fdb\u884c random_shuffle\uff0c\u5728\u6bcf\u4e2a window \u7684\u8bad\u7ec3\u6570\u636e\u4ece pipeline \u51fa\u6765\u65f6\uff0c\u4e5f\u901a\u8fc7 random shuffle \u5bf9 window \u4e2d\u7684\u8bad\u7ec3\u6570\u636e\u518d\u6b21\u8fdb\u884c shuffle\u3002\u7ed3\u679c\u663e\u793a\uff0c\u5145\u5206\u7684\u5168\u5c40\u548c\u5c40\u90e8 shuffle \u6709\u6548\u63d0\u9ad8\u6a21\u578b\u7cbe\u5ea6\u3002<\/p>\n<table style=\"width: 100%;border-collapse: collapse\">\n<tbody>\n<tr>\n<td style=\"vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>Version<\/p>\n<\/td>\n<td style=\"vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>Accuracy<\/p>\n<\/td>\n<td style=\"vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>Precision<\/p>\n<\/td>\n<td style=\"vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>Recall<\/p>\n<\/td>\n<td style=\"vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>f1-measure<\/p>\n<\/td>\n<td style=\"vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>GPU idle time<\/p>\n<\/td>\n<td style=\"vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>E2E time<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>RayRTC-phase1<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.804<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.637<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.571<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.602<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>245s<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>2296s<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;vertical-align: top;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>RayRTC-pipeline<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.821<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.715<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.556<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>0.625<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>102s<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>2138s<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>Improve<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>+0.017<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>+0.078<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>-0.015<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>+0.023<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>-143s<\/p>\n<\/td>\n<td style=\"text-align: center;vertical-align: top;background: white none repeat scroll 0% 0%;min-width: auto;margin: 4px 8px;padding: 4px 8px;cursor: default\">\n<p>-158s<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u603b\u7ed3<\/h2>\n<p style=\"text-align: justify\">RayRTC \u4ee5 Ray \u4e3a\u5206\u5e03\u5f0f\u8ba1\u7b97\u5b66\u4e60\u5f15\u64ce\uff0c\u5bf9\u5b57\u8282 RTC NLP \u6846\u67b6\u7684\u5168\u9762\u6539\u9020\u5347\u7ea7\u4e0d\u4ec5\u5b9e\u73b0\u4e86\u6027\u80fd\u7684\u6781\u81f4\u4f18\u5316\uff085 \u5c0f\u65f6\u5230 30 \u5206\u949f\uff09\uff0c\u540c\u65f6\u901a\u8fc7\u6d41\u6c34\u5e76\u884c\u6781\u5927\u964d\u4f4e\u4e86 GPU \u8d44\u6e90\u7684 idle \u65f6\u95f4\uff0860% reduction\uff09\u3002RayRTC \u4ee5\u677e\u8026\u5408\u7684\u5f62\u5f0f\u5bf9\u73b0\u6709\u4e1a\u52a1\u7684\u4fb5\u5165\u6781\u5c0f\uff08&lt;1% loc\uff09\uff0c\u540c\u65f6\u4e3a\u540e\u7eed\u53ef\u63d2\u62d4 low-level \u4f18\u5316\u548c serverless autoscaling \u63d0\u4f9b\u4e86 API \u652f\u6301\u3002\u53ef\u4ee5\u9884\u89c1\uff0c\u540e\u7eed RayRTC \u5728\u66f4\u5927\u89c4\u6a21\u4e0a\u8fdb\u884c\u8d85\u53c2\u4ee5\u53ca\u4e0e\u63a8\u7406\u6253\u901a\uff0c\u5c06\u4f1a\u5f62\u6210\u66f4\u9ad8\u6548\u7684\u7aef\u5230\u7aef Serverless NLP Pipeline\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>RayRTC \u662f\u5b57\u8282\u57fa\u7840\u67b6\u6784\u7ec4\u4e0e\u5b57\u8282 AML \u7ec4\u5171\u540c\u5408\u4f5c\uff0c\u5728\u5185\u90e8 RTC\uff08Realtime Text Clas [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":336820,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-336819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/336819","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=336819"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/336819\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/336820"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=336819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=336819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=336819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}