





{"id":6410,"date":"2025-10-11T10:29:46","date_gmt":"2025-10-11T02:29:46","guid":{"rendered":"https:\/\/www.killtest.hk\/?p=6410"},"modified":"2025-10-11T10:29:46","modified_gmt":"2025-10-11T02:29:46","slug":"%e5%a4%a7%e6%a8%a1%e5%9e%8b%e6%8e%a8%e7%90%86%e9%81%8e%e7%a8%8b%e4%b8%ad%e7%9a%84%e6%95%88%e8%83%bd%e6%9c%80%e4%bd%b3%e5%8c%96%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.killtest.hk\/index.php\/killtest\/%e5%a4%a7%e6%a8%a1%e5%9e%8b%e6%8e%a8%e7%90%86%e9%81%8e%e7%a8%8b%e4%b8%ad%e7%9a%84%e6%95%88%e8%83%bd%e6%9c%80%e4%bd%b3%e5%8c%96%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u5927\u6a21\u578b\u63a8\u7406\u904e\u7a0b\u4e2d\u7684\u6548\u80fd\u6700\u4f73\u5316\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u672c\u6587\u4ecb\u7d39\u5927\u6a21\u578b\u63a8\u7406\u6548\u80fd\u7684\u6700\u4f73\u5316\u65b9\u6cd5\u3002<br>\u5305\u62ec\u4e09\u500b\u65b9\u9762\uff1a\u670d\u52d9\u8abf\u5ea6\u3001\u8a08\u7b97\u5f15\u64ce\u548c\u6a21\u578b\u6f14\u7b97\u6cd5\u3002<br>\u672c\u6587\u53c3\u8003\uff1a\u5b6b\u6176\u864e\uff08\u6545\u5317\uff09\uff0c\u516c\u773e\u865f\uff1a\u963f\u91cc\u96f2\u958b\u767c\u8005<br>\u3010\u842c\u5b57\u9577\u6587\u3011\u5927\u6a21\u578b\u8a13\u7df4\u63a8\u7406\u548c\u6027\u80fd\u512a\u5316\u6f14\u7b97\u6cd5\u7e3d\u7d50\u548c\u5be6\u8e10<br>\u512a\u5316\u5927\u6a21\u578b\u63a8\u7406\u6027\u80fd\uff0c\u5c31\u662f\u627e\u4e00\u7a2e\u5e73\u8861 \u2014\u2014 \u65e2\u8981\u8b93 GPU \u7b97\u5f97\u5feb\u3001\u4e0d\u9592\u8457\uff0c\u53c8\u8981\u5c11\u4f54\u986f\u5b58\u3001\u5c11\u9867\u5e36\u5bec\uff0c\u9084\u5f97\u517c\u9867\u541e\u5410\u91cf\u548c\u5ef6\u9072\u7684\u77db\u76fe\u3002<br>\u670d\u52d9\u5c64\u5f9e\u8abf\u5ea6\u5165\u624b\uff1aContinuous Batching \u4f5c\u70ba\u8abf\u5ea6\u54e1\uff0c\u6bcf\u751f\u6210\u4e00\u500b <a href=\"https:\/\/www.killtest.net\/\">token<\/a> \u5c31\u8abf\u6574\u6279\u6b21\uff0c\u8b93\u65e9\u7d50\u675f\u7684\u8acb\u6c42\u9a30\u4f4d\u7f6e\u3001\u65b0\u8acb\u6c42\u63d2\u968a\uff0c\u514d\u5f97 GPU \u7a7a\u8f49\uff1b\u6d41\u5f0f\u751f\u6210\u908a\u7b97\u908a\u8fd4\u56de\uff0c\u9084\u80fd\u4e2d\u9014\u6253\u65b7\uff0c\u65e2\u8b93\u7528\u6236\u7b49\u5f97\u77ed\uff0c\u53c8\u7701\u4e86\u7121\u6548\u8a08\u7b97\uff1b\u6d41\u5f0f\u751f\u6210\u908a\u7b97\u908a\u8fd4\u56de\uff0c\u9084\u80fd\u4e2d\u9014\u6253\u65b7\uff0c\u65e2\u8b93\u7528\u6236\u7b49\u5f97\u77ed\uff0c\u53c8\u7701\u4e86\u7121\u6548\u8a08\u7b97\uff1b\u6d41\u5f0f\u751f\u6210\u908a\u7b97\u908a\u8fd4\u56de\uff0c\u9084\u80fd\u4e2d\u9014\u6253\u65b7\uff0c\u65e2\u8b93\u7528\u6236\u7b49\u5f97\u77ed\uff0c\u53c8\u7701\u4e86\u7121\u6548\u8a08\u7b97\uff1b (n\u00d7k)\uff0c\u8b93\u6a21\u578b\u80fd \u300c\u5543\u300d \u9577\u6587\u4ef6\u9084\u4e0d\u8cbb\u592a\u591a\u529b\u3002<br>\u63a8\u7406\u5f15\u64ce\u5c64\u5f9e\u6548\u7387\u5165\u624b\uff1a<br>KV-Cache \u50cf\u8a18\u7b46\u8a18\uff0c\u5b58\u4e0b\u6b77\u53f2\u8a08\u7b97\u7d50\u679c\u907f\u514d\u91cd\u8907\u52de\u52d5\uff1bPagedAttention \u5b78\u64cd\u4f5c\u7cfb\u7d71\u5206\u9801\uff0c\u89e3\u6c7a\u986f\u5b58\u788e\u7247\u554f\u984c\uff0c\u8b93\u5167\u5b58\u7528\u5f97\u66f4\u900f\uff1b<br>APC \u5247\u6293 \u201c\u91cd\u8907\u524d\u7db4\u201d\uff0c\u6bd4\u5982 100 \u500b\u7528\u6236\u554f\u540c\u4e00\u7bc7\u8ca1\u5831\uff0c\u5b83\u53ea\u7b97\u4e00\u6b21\u524d\u7db4\u7684\u7de9\u5b58\uff0c\u5269\u4e0b 99\u6b21\u76f4\u63a5\u5fa9\u7528\uff0c\u7701\u4e86\u5927\u534a\u7b97\u529b\uff1b<br>\u5206\u4f48\u5f0f\u4e26\u884c\uff08TP+PP\uff09\u201c\u5206\u5de5\u5408\u4f5c\u201d\uff0c\u628a\u5927\u6a21\u578b\u62c6\u7d66\u591a\u5361\u5e79\uff0c\u4f60\u7b97\u9019\u90e8\u5206\u6211\u7b97\u90a3\u90e8\u5206\uff0c\u65e2\u88dd\u4e0b\u5927\u6a21\u578b\u53c8\u63d0\u901f\uff1b<br>\u7b97\u5b50\u878d\u5408\u5247\u628a\u96f6\u6563\u7684\u8a08\u7b97\u6b65\u9a5f\u6346\u6210\u4e00\u5718\uff0c\u5c11\u8b80\u5beb\u986f\u5b58\u3001\u5c11\u555f\u52d5 Kernel\uff0c\u8b93\u6578\u64da\u5728 GPU \u88e1\u66f4\u9806\u3002<br>\u6a21\u578b\u91cf\u5316\u5c64\u5247\u662f \u300c\u7626\u8eab\u8853\u300d\uff1a<br>\u628a 32 \u4f4d\u6d6e\u9ede\u6578\u58d3\u6210 8 \u4f4d\u751a\u81f3 4 \u4f4d\u6574\u6578\uff0c\u7528\u9ede\u7cbe\u5ea6\u640d\u5931\u63db\u986f\u5b58\u6e1b\u534a\u3001\u901f\u5ea6\u7ffb\u500d\uff0c\u63a5\u8457\u9760 SmoothQuant\u3001GPTQ \u9019\u4e9b\u6280\u5de7\uff0c\u8b93 \u201c\u7626\u8eab\u5f8c\u201d \u7684\u6a21\u578b\u4f9d\u7136\u80fd\u6253\u3002<br>\u4ee5\u4e0b\u662f\u9019\u4e09\u500b\u5c64\u9762\u7684\u8a73\u7d30\u95e1\u8ff0\uff1a<br>\u4e00\u3001\u670d\u52d9\u5c64\u512a\u5316<br>\uff08\u4e00\uff09Continuous Batching\u50b3\u7d71\u975c\u614b\u6279\u6b21\uff08\u4f8b\u5982\u4ee5\u524d\u7528 Triton \u7684 Static Batching\uff09\u6700\u5927\u7684\u6d6a\u8cbb\u662f \u201ctoken \u7d1a\u7a7a\u8f49\u201d\u2014\u2014\u4e00\u6279 token \u8acb\u6c42\u53ea\u9700\u8981 5 \u500b token\uff0c\u5176\u4ed6\u8981 50 \u500b\uff0c\u90a3\u524d 45 \u500b token \u751f\u6210\u6642\uff0c \u6bd4\u5982\u8aaa\uff0c\u9019\u500b\u4f4d\u7f6e\u9084\u6d3b\u5f97\u4e86\uff0c\u90a3\u9ebc\u7d50\u675fContinuous Batching \u7684\u95dc\u9375\u662f \u201c\u6309\u63a8\u7406\u6b65\u8abf\u5ea6\u201d\uff0c\u6bcf\u751f\u6210\u4e00\u500b token\uff08\u4e5f\u5c31\u662f\u8d70\u4e00\u6b65\u63a8\u7406\uff09\u5c31\u91cd\u65b0\u6392\u4e00\u6b21\u968a\uff1a<br>\u628a\u90a3\u4e9b Early-Finished\uff08\u65e9\u7d50\u675f\uff09\u7684\u8acb\u6c42\u8e22\u51fa\u53bb\u9a30\u4f4d\u7f6e\uff0c\u518d\u628a\u65b0\u9032\u4f86\u7684 Late-Joining\uff08\u665a\u52a0\u5165\uff09\u8acb\u6c42\u585e\u9032\u53bb\uff0c\u9019\u6a23 GPU \u7684\u8a08\u7b97\u55ae\u5143\u6bcf\u4e00\u6b65\u90fd\u6eff\u6eff\uff0c\u6c92\u6709\u6bcf\u4e00\u6b65\u90fd\u6eff\u6eff\u3002<br>\u4f46\u9019\u88e1\u4e0d\u662f\u96a8\u4fbf\u585e\uff0c\u5f97\u8655\u7406\u597d\u8acb\u6c42\u9577\u5ea6\u5dee\u7570\uff0c\u4e0d\u7136\u77ed\u8acb\u6c42\u6703\u88ab\u9577\u8acb\u6c42\u5835\u6b7b\uff0c\u6240\u4ee5\u73fe\u5728\u5927\u591a\u6703\u5206 \u201c\u9577\u5ea6\u6876\u201d\uff0c\u628a\u5dee\u4e0d\u591a\u9577\u5ea6\u7684\u8acb\u6c42\u653e\u4e00\u500b\u6876\u88e1\u8abf\u5ea6\uff0c\u6e1b\u5c11\u8abf\u5ea6\u51fa\u73fe\u788e\u7247\u5316\uff08\u9577\u77ed\u4e0d\u4e00\u5c0e\u81f4\u7684\uff09\uff0c\u6bd4\u5982 100-200token \u7684\u653e\u4e00\u6876\uff0c200-300 \u7684\u5ef6\u9072\uff0c\u53e6\u4e00\u6876\uff0c\u53e6\u4e00\u58d3\u6392\u653e\uff0c\u5404\u81ea\u65e2\u5b89\u5168\u53c8\u4e0d\u52a0\u8abf\u5ea6\u3002 <br>Continuous Batching\u9069\u5408\u8655\u7406\u4e0d\u540c\u9577\u5ea6\u7684prompt\uff0c\u56e0\u70ba\u5927\u6a21\u578b\u63a8\u7406\u6642\uff0c\u6709\u7684\u8acb\u6c42\u53ef\u80fd\u53ea\u9700\u89815\u500btoken\u5c31\u5b8c\u6210\uff0c\u6709\u7684\u53ef\u80fd\u9700\u898150\u500b\uff0c\u50b3\u7d71\u6279\u8655\u7406\u6703\u70ba\u4e86\u6700\u9577\u7684\u90a3\u500b\u8acb\u6c42\u7b49\u5f88\u4e45\uff0c\u800cContinuous Batching\u53ef\u4ee5\u5be6\u6642\u8abf\u6574\uff0c\u8b93GPU\u4e00\u76f4\u5728\u5e79\u6d3b\uff0c\u4e0d\u9592\u8457\u3002 <br>\u5b83\u5728\u6bcf\u6b21GPU\u63a8\u7406\u7684\u9593\u9699\uff0c\u4e5f\u5c31\u662f&#8221;\u5beb\u5b8c\u4e00\u500btoken\u7684\u7a7a\u6a94&#8221;\uff0c\u5077\u5077\u505a\u9ede\u8abf\u5ea6\u5de5\u4f5c\u3002\u7cfb\u7d71\u6703\u5373\u6642\u76e3\u63a7\u6bcf\u500b\u8acb\u6c42\u7684\u9032\u5ea6\uff0c\u4e00\u65e6\u767c\u73fe\u67d0\u500b\u8acb\u6c42\u63d0\u524d\u5beb\u5b8c\u4e86\uff08Early-Finished\uff09\uff0c\u5c31\u628a\u5b83\u5f9e\u7576\u524d\u6279\u6b21\u4e2d\u79fb\u9664\uff0c\u9a30\u51fa\u4f4d\u7f6e\u7d66\u65b0\u4f86\u7684\u8acb\u6c42\u3002\u540c\u6642\uff0c\u7576\u65b0\u8acb\u6c42\u5230\u9054\u6642\uff08Late-Joining\uff09\uff0c\u5b83\u4e5f\u80fd\u7acb\u5373\u63d2\u5165\u5230\u76ee\u524d\u6279\u6b21\u4e2d\uff0c\u4e0d\u9700\u8981\u7b49\u5f85\u76ee\u524d\u6279\u6b21\u5b8c\u6210\u3002 <\/p>\n\n\n\n<p>\uff08\u4e8c\uff09\u4e32\u6d41\u5f0f\u751f\u6210\u518d\u770b\u6d41\u5f0f\u4e92\u52d5\u5f0f\u751f\u6210\uff0c\u4e32\u6d41\u751f\u6210\u5176\u5be6\u662f KV-Cache \u5728\u670d\u52d9\u5c64\u7684\u53e6\u4e00\u7a2e\u61c9\u7528\uff0c\u5b83\u4e0d\u53ea\u662f \u300c\u908a\u751f\u6210\u908a\u56de\u994b\u300d \u9019\u9ebc\u7c21\u55ae\u3002<br>\u50b3\u7d71\u975e\u6d41\u5f0f\u662f\u7b49\u6a21\u578b\u628a\u6240\u6709 token \u90fd\u7b97\u5b8c\u518d\u8fd4\u56de\uff0c\u9019\u88e1\u6709\u5169\u500b\u5927\u554f\u984c\uff1a<br>\u4e00\u662f\u7528\u6236\u7b49\u5f97\u4e45\uff0c<br>\u4e8c\u662f \u201c\u8cc7\u6e90\u4f54\u7528\u9577\u5c3e\u201d\uff1a1\u500b\u8981\u751f\u6210 100 \u500b token \u7684\u8acb\u6c42\uff0c\u5f97\u4f54\u8457 KV-Cache \u6574\u6574 100 \u6b65\uff0c\u671f\u9593\u5176\u4ed6\u8acb\u6c42\u9032\u4e0d\u4f86\u3002<br>\u6d41\u5f0f\u751f\u6210= \u589e\u91cf\u89e3\u78bc + \u4e2d\u9014\u6253\u65b7\uff0c\u751f\u6210\u4e00\u500b token \u5c31\u8fd4\u56de\u4e00\u500b\uff0c\u540c\u6642\u628a\u9019\u500b token \u5c0d\u61c9\u7684\u81e8\u6642\u8a08\u7b97\u7d50\u679c\uff08\u4e0d\u662f KV-Cache\uff0cKV-Cache \u9084\u5f97\u7559\u8457\u7b97\u4e0b\u4e00\u500b\uff09\u91cb\u653e\u6389\uff0c\u66f4\u91cd\u8981\u7684\u662f\u7528\u6236\u80fd\u96a8\u6642\u558a\u505c\uff0c\u6bd4\u5982\u6a21\u578b\u751f\u6210\u5230\u7b2c 10 \u500b token\uff0c\u7528\u6236\u89ba\u5f97\u4e0d\u5c0d\uff0c\u76f4\u63a5\u7d42\u6b62\u4e86 90 \u7701\u800c\u4e14\u5e95\u5c64\u5fc5\u9808\u8ddf KV-Cache \u806f\u52d5\uff0c\u56e0\u70ba\u6bcf\u4e00\u6b65\u53ea\u7b97\u7576\u524d token\uff0c\u5f97\u9760 KV-Cache \u8abf\u51fa\u524d\u9762\u7684\u6b77\u53f2\u4fe1\u606f\uff0c\u4e0d\u7136\u6bcf\u4e00\u6b65\u90fd\u5f97\u91cd\u7b97\u524d\u9762\u6240\u6709 token\uff0c\u53cd\u800c\u66f4\u6162\u3002 <br>\uff08\u4e09\uff09\u9577\u5e8f\u5217\u63a8\u7406\u9577\u5e8f\u5217\u63a8\u7406\u9019\u584a\uff0c\u75db\u9ede\u662f\u50b3\u7d71 Transformer \u7684 Attention \u8a08\u7b97\u662f O (n\u00b2)\uff0cn \u662f\u5e8f\u5217\u9577\u5ea6\uff0cn \u5f9e 1k \u6f32\u5230 10k\uff0c\u8a08\u7b97\u91cf\u76f4\u63a5\u5f9e 1e6 \u98c6\u5230 1e8\uff0c\u986f\u5b58\u548c\u7b97\u529b\u90fd\u625b\u4e0d\u4f4f\u3002<br>\u6240\u4ee5\u6240\u6709\u9577\u5e8f\u5217\u512a\u5316\uff0c\u672c\u8cea\u90fd\u662f&#8211;\u5982\u4f55\u5728\u4e0d\u5931\u53bb\u95dc\u9375\u8a0a\u606f\u7684\u524d\u63d0\u4e0b\uff0c\u628a O (n\u00b2) \u964d\u5230 O (n) \u6216 O (nk)\uff08k \u662f\u67d0\u500b\u5c0f\u5e38\u6578\uff09\u3002 <br>\u82f1\u5049\u9054\u7684 Star Attention\uff0c\u5b83\u8ced\u7684\u662f \u300c\u5c40\u90e8\u6027\u5047\u8a2d\u300d\u2014\u2014 \u7576\u524d token \u4e3b\u8981\u8ddf\u9644\u8fd1\u7684 token \u6709\u95dc\uff0c\u8b80\u6587\u7ae0\u6642\uff0c\u4e00\u53e5\u8a71\u88e1\u7684\u8a5e\u5927\u6982\u7387\u53ea\u548c\u524d\u5f8c\u5e7e\u53e5\u95dc\u806f\uff0c\u4e0d\u7528\u8ddf\u958b\u982d\u7684\u8a5e\u626f\u95dc\u4fc2\u3002<br>\u6240\u4ee5\u5b83\u5206\u5169\u968e\u6bb5\uff1a\u7b2c\u4e00\u968e\u6bb5\u628a\u9577\u5e8f\u5217\u5207\u6210\u5c0f\u584a\uff0c\u6bcf\u500b\u584a\u53ea\u7b97\u81ea\u5df1\u548c\u524d\u4e00\u500b\u584a\u7684 Attention\uff0c\u6293 \u201c\u77ed\u671f\u4f9d\u8cf4\u201d\uff0c\u9019\u4e00\u6b65\u8a08\u7b97\u91cf\u662f O (nk)\uff08k \u662f\u584a\u5927\u5c0f\uff09\uff1b\u7b2c\u4e8c\u968e\u6bb5\u7528\u5168\u5c40 Attention \u628a\u6240\u6709\u584a\u7684\u7d50\u679c\u62fc\u8d77\u4f86\uff0c\u5168\u5c40 \u201c\u9577\u671f\u4f9d\u8cf4\u201d\uff0c\u4f46\u63a7\u5236\u8a08\u7b97\u6642\u53ea\u7b97\u584a\u7d1a\u7684\u7279\u5fb5\uff0c\u5c0d\u65bc\u6bcf\u500b token\uff0c\u6240\u4ee5\u7e3d\u91cf\u4e0d\u662f\u53ef\u63a7\u3002\u4f8b\u5982 k=512\uff0cn=10k\uff0c\u8a08\u7b97\u91cf\u76f4\u63a5\u964d 10 \u500d\uff0c\u9084\u80fd\u4fdd\u4f4f\u9577\u8ddd\u96e2\u95dc\u806f\u3002<br> Star Attention \u7684\u5169\u968e\u6bb5\u8a08\u7b97\uff1a\u7b2c\u4e00\u968e\u6bb5\u662f \u201c\u5c40\u90e8\u6ce8\u610f\u529b\u201d\uff0c\u628a\u9577\u5e8f\u5217\u5207\u6210\u5927\u5c0f\u70ba k \u7684\u5340\u584a\u3002\u4f8b\u5982 n=10000\uff0ck=512\uff0c\u90a3\u5927\u6982\u53ef\u4ee5\u5207\u6210 10000\u00f7512\u224820 \u500b\u584a\uff08\u53d6\u6574\u6578\u65b9\u4fbf\u7b97\uff09\u3002<br>\u6bcf\u500b\u5340\u584a\u53ea\u95dc\u6ce8 \u300c\u81ea\u5df1\u5167\u5728\u7684 token\u300d \u548c \u300c\u524d\u4e00\u500b\u5340\u584a\u7684 token\u300d\uff08\u6293\u77ed\u671f\u4f9d\u8cf4\uff09\u3002<\/p>\n\n\n\n<p>\u6bcf\u500b\u5340\u584a\u6709 k \u500b token\uff0c\u524d\u4e00\u500b\u5340\u584a\u4e5f\u6709 k \u500b\uff0c\u6240\u4ee5\u6bcf\u500b token \u9700\u8981\u548c k\uff08\u81ea\u5df1\u5340\u584a\uff09+k\uff08\u524d\u4e00\u500b\u5340\u584a\uff09=2k \u500b token \u7b97\u6ce8\u610f\u529b\u3002<br>\u90a3\u4e00\u500b\u5340\u584a\u7684\u8a08\u7b97\u91cf\u5c31\u662f\uff1ak \u500b token \u00d7 2k \u6b21\u8a08\u7b97 = 2k\u00b2\u3002 <\/p>\n\n\n\n<p>20 \u500b\u5340\u584a\u7684\u7e3d\u8a08\u7b97\u91cf\u5c31\u662f\uff1a20 \u00d7 2k\u00b2 = 40k\u00b2\u3002\u4ee3\u5165 k=512\uff0c\u5c31\u662f 40\u00d7512\u00d7512\u22481048 \u842c\u6b21\u3002<br>\u7b2c\u4e8c\u968e\u6bb5\u662f \u201c\u5168\u5c40\u6ce8\u610f\u529b\u201d\uff0c\u6293\u4f4f\u9577\u671f\u4f9d\u8cf4\u3002\u9019\u6642\u5019\u4e0d\u7d30\u7b97\u6bcf\u500b token \u4e86\uff0c\u800c\u662f\u7d66\u6bcf\u500b\u5340\u584a\u63d0\u4e00\u500b \u300c\u7e3d\u7d50\u7279\u5fb5\u300d\uff08\u4f8b\u5982\u7528\u5340\u584a\u5167\u6240\u6709 token \u7684\u5e73\u5747\u503c\u6216\u6700\u5927\u503c\u7576\u4ee3\u8868\uff09\uff0c20 \u500b\u5340\u584a\u5c31\u6709 20 \u500b\u7e3d\u7d50\u7279\u5fb5\u3002<br>\u5168\u5c40\u6ce8\u610f\u529b\u5c31\u662f\u9019 20 \u500b\u7279\u5fb5\u4e4b\u9593\u4e92\u76f8\u8a08\u7b97\uff0c\u8a08\u7b97\u91cf\u662f 20\u00d720=400 \u6b21\uff08\u548c\u7b2c\u4e00\u968e\u6bb5\u6bd4\u5e7e\u4e4e\u53ef\u4ee5\u5ffd\u7565\uff09\u3002<br>\u6240\u4ee5 Star Attention \u7684\u7e3d\u8a08\u7b97\u91cf\u2248\u7b2c\u4e00\u968e\u6bb5\u7684 1,048 \u842c\u6b21 + \u7b2c\u4e8c\u968e\u6bb5\u7684 400 \u6b21\u22481,048 \u842c\u6b21\u3002<\/p>\n\n\n\n<p>\u50b3\u7d71 Attention \u662f 1 \u5104\u6b21\uff0c1 \u5104 \u00f71048 \u842c\u22489.5\uff0c\u5dee\u4e0d\u591a 10 \u500d\u58c1\u4ede\u7684 \u201c\u5206\u6bb5 + \u72c0\u614b\u5411\u91cf\u201d \u66f4\u96de\u8cca\uff0c\u72c0\u614b\u5411\u91cf\u5176\u5be6\u662f\u524d\u4e00\u6bb5\u7684 \u201c\u8a9e\u7fa9\u6458\u8981\u201d\uff0c\u5c31\u50cf\u4f60\u8b80\u8ad6\u6587\u8a18\u6bb5\u843d\u5927\u610f\uff0c\u4e0d\u7528\u8a18\u6bcf\u53e5\u8a71\uff0c\u5f8c\u9762\u6bb5\u843d\u57fa\u65bc\u5927\u610f\u7b97\uff0c\u4e0d\u7528\u7b97\u6bcf\u53e5\u8a71\u56de\u982d\u7b97\u6bcf\u53e5\u8a71\u7684 Attention\u3002\u9019\u88e1\u7684\u95dc\u9375\u662f\u72c0\u614b\u5411\u91cf\u5f97\u5c0f\uff0c\u4f8b\u5982\u628a\u524d\u4e00\u6bb5 1000 \u500b token \u7684 Attention \u8f38\u51fa\u58d3\u7e2e\u6210 256 \u7dad\u5411\u91cf\uff0c\u65e2\u7701\u7a7a\u9593\u53c8\u80fd\u4fdd\u7559\u95dc\u9375\u8a0a\u606f\uff0c\u4e0d\u7136\u5b58\u72c0\u614b\u5411\u91cf\u4e5f\u4f54\u986f\u5b58\u3002 FlexPrefill \u7684 \u300c\u52d5\u614b\u8abf\u6574\u7bc4\u570d\u300d \u662f \u300c\u6ce8\u610f\u529b\u7a00\u758f\u5316\u300d \u7684\u8b8a\u7a2e\uff0c\u5b83\u4e0d\u662f\u56fa\u5b9a\u5340\u584a\u5927\u5c0f\uff0c\u800c\u662f\u9760\u4e00\u500b\u8f15\u91cf\u7684 \u300c\u8a9e\u610f\u5206\u6790\u5668\u300d \u5224\u65b7\u76ee\u524d\u5167\u5bb9\u7684 \u300c\u5bc6\u5ea6\u300d\u2014 \u9047\u5230 \u300c\u7d9c\u4e0a\u6240\u8ff0\u300d \u9019\u7a2e\u7e3d\u7d50\u53e5\uff0c\u5c31\u64f4\u5927 Attention \u7bc4\u570d\uff0c\u95dc\u806f\u6027\u5206\u6790\u5668\u300d \u5224\u65b7\u76ee\u524d\u5167\u5bb9\u7684 \u300c\u5bc6\u5ea6\u300d\uff0d \u9047\u5230 \u300c\u7d9c\u4e0a\u6240\u8ff0\u300d \u9019\u7a2e\u7e3d\u7d50\u53e5\uff0c\u5c31\u64f4\u5927 Attention \u7bc4\u570d\uff0c\u95dc\u806f\u6027\u5206\u6790\u5668\u300d \u9047\u5230 \u300c\u4f8b\u5982\u300d\u9019\u500b\u8209\u4f8b\u95dc\u806f\uff0c \u9019\u7a2e\u7e3d\u7d50\u53e5\uff0c\u5c31\u64f4\u5927 Attention \u7bc4\u570d\uff0c\u95dc\u806f\u6027\u7684\u66f4\u5b89\u5168\uff1b \u300c\u4ee5\u5b58\u63db\u7b97\u300d \u6280\u8853\uff1a\u5229\u7528\u986f\u5b58\u548c\u78c1\u789f\u5b58\u5132\uff0c\u628a\u4e0d\u5e38\u7528\u7684\u8cc7\u6599\u653e\u5230\u986f\u5b58\u5916\uff0c\u9700\u8981\u6642\u518d\u8abf\u56de\u4f86\u3002<\/p>\n\n\n\n<p>\u6211\u5011\u5148\u641e\u6e05\u695a \u201c\u5b58\u4ec0\u9ebc\u63db\u4ec0\u9ebc\u201d\uff0c\u5b58\u7684\u662f\u4e0d\u5e38\u7528\u7684 KV-Cache \u6216 Attention \u6b0a\u91cd\uff0c\u63db\u7684\u662f\u986f\u5b58\u7a7a\u9593\uff0c\u4f46\u5f97\u63a7\u5236\u63db\u5165\u63db\u51fa\u7684\u5ef6\u9072\uff0c\u6bd4\u5982\u628a\u524d 1000 \u500b token \u7684 KV-Cache \u653e\u5230 SSD\uff0c\u4f46\u4e0d\u80fd\u7b49\u8981\u7528\u4e86\u624d\u8abf\uff0c\u5f97\u524d GPU \u7b49\u5167\u5b58\uff0c<\/p>\n\n\n\n<p>\u4e8c\u3001\u63a8\u7406\u5f15\u64ce\u512a\u5316<\/p>\n\n\n\n<p>\uff08\u4e00\uff09KV-Cache\u6a5f\u5236\u5927\u6a21\u578b\u63a8\u7406\u7684\u50b3\u7d71\u65b9\u6cd5\u6bcf\u6b21\u751f\u6210\u65b0token\u90fd\u8981\u91cd\u65b0\u8a08\u7b97\u6240\u6709\u6b77\u53f2token\u7684\u9375\u503c\u5c0d\uff0c\u5c31\u50cf\u6bcf\u6b21\u5beb\u65b0\u53e5\u5b50\u90fd\u8981\u91cd\u65b0\u8b80\u4e00\u904d\u524d\u9762\u6240\u6709\u5167\u5bb9\uff0c\u9019\u592a\u6d6a\u8cbb\u6642\u9593\u4e86\u3002 <\/p>\n\n\n\n<p>KV-Cache \u4f60\u53ef\u80fd\u77e5\u9053\u662f\u5b58 K \u548c V\uff0c\u4f46\u70ba\u4ec0\u9ebc\u662f K \u548c V\uff0c\u4e0d\u662f Q\uff1f\u56e0\u70ba Q \u662f\u76ee\u524d token \u7684\u67e5\u8a62\uff0c\u6bcf\u6b21\u90fd\u4e0d\u4e00\u6a23\uff0c\u6c92\u6cd5\u5b58\uff1bK \u662f\u6b77\u53f2 token \u7684 \u300c\u9375\u300d\uff08\u7279\u5fb5\u6a19\u8b58\uff09\uff0cV \u662f\u6b77\u53f2 token \u7684 \u300c\u503c\u300d\uff08\u8cc7\u8a0a\u5167\u5bb9\uff09\uff0c\u9019\u5169\u500b\u662f\u56fa\u5b9a\u7684\uff0c\u751f\u6210\u65b0 token \u6642\u53ea\u9700\u8981\u7528\u65b0 Q \u53bb\u67e5\u820a KV\uff0c\u6240\u4ee5\u80fd\u5b58\u3002<\/p>\n\n\n\n<p>\u800c\u4e14 KV-Cache \u7684\u5132\u5b58\u683c\u5f0f\u4e0d\u592a\u4e00\u6a23\uff0c\u4e00\u822c\u6309\u8a3b\u610f\u529b\u982d\u62c6\u5206\uff0c\u6bcf\u500b\u982d\u7684 KV \u55ae\u7368\u5b58\uff0c\u9019\u6a23\u5f8c\u9762\u505a TP\uff08\u5f35\u91cf\u4e26\u884c\uff09\u6642\uff0c\u80fd\u76f4\u63a5\u628a\u6bcf\u500b\u982d\u7684 KV \u5207\u5206\u5230\u4e0d\u540c GPU\uff0c\u4e0d\u7528\u8de8\u5361\u50b3\u6578\u64da\uff0c\u7701\u901a\u4fe1\u91cf\u3002<br>\u9084\u6709\u52d5\u614b\u64f4\u5bb9\u554f\u984c\uff0c\u4e00\u958b\u59cb\u4e0d\u77e5\u9053\u8acb\u6c42\u8981\u751f\u6210\u591a\u5c11 token\uff0c\u4e0d\u80fd\u9810\u5206\u914d\u592a\u5927\u7a7a\u9593\uff08\u6d6a\u8cbb\uff09\uff0c\u4e5f\u4e0d\u80fd\u592a\u5c0f\uff08\u4e0d\u5920\u7528\u8981\u64f4\u5bb9\uff0c\u62f7\u8c9d\u6578\u64da\u8cbb\u6642\u9593\uff09\uff0c\u6240\u4ee5\u73fe\u5728\u90fd\u7528 \u201c\u9810\u5206\u914d\u5c0f\u584a + \u52d5\u614b\u62fc\u63a5\u201d\uff0c\u6bd4\u5982\u6bcf\u500b\u8acb\u6c42\u5148\u7d66 64 \u500b token \u7684 KV \u584a\uff0c\u4e0d\u5920\u4e86\u518d\u8ffd\u52a0\uff0c\u62fc\u63a5\u201d\uff0c\u6bd4\u5982\u6bcf\u500b\u8acb\u6c42\u5148\u7d66 64 \u500b token \u7684 KV \u584a\uff0c\u4e0d\u5920\u4e86\u518d\u8ffd\u52a0\uff0c\u5167\u5b58\u788e\u7247\u5c11\uff0c\u64f4\u5bb9\u5feb\u3002<br>\u83ef\u70ba\u7684 UCM \u6280\u8853\u662f KV-Cache \u7684\u5347\u7d1a\u7248\uff0c\u641e \u201c\u4e09\u7d1a\u7de9\u5b58\u201d\uff1a\u71b1\u6578\u64da\uff08\u6700\u8fd1\u7528\u7684\uff09\u653e\u986f\u5b58\uff0c\u6eab\u6578\u64da\uff08\u8fd1\u671f\u53ef\u80fd\u7528\u7684\uff09\u653e\u5167\u5b58\uff0c\u51b7\u6578\u200b\u200b\u64da\uff08\u5f88\u4e45\u4e0d\u7528\u7684\uff09\u653e SSD\uff0c\u9084\u6703\u8ddf\u8e2a\u6bcf\u500b KV \u584a\u7684\u8a2a\u554f\u983b\u7387\uff0c\u6bd4\u5982 5 \u5206\u9418\u6c92\u78b0\u904e\u5c31\u4e1f SSD\uff0c1\u5206\u9418\u5167\u78b0\u904e\u5c31\u653e\u5167\u5b58\uff0c\u9019\u6a23\u65e2\u7701\u986f\u5b58\uff0c\u53c8\u80fd\u900f\u904e\u9810\u53d6\u6e1b\u5c11\u8abf\u6578\u64da\u7684\u5ef6\u9072\uff0c\u6bd4\u5982\u5728\u7576\u524d\u8a08\u7b97\u5feb\u7528\u5b8c\u986f\u5b58\u6642\uff0c\u63d0\u524d\u628a\u4e0b\u4e00\u6bb5\u9700\u8981\u7684 KV \u5f9e SSD \u8abf\u5230\u5167\u5b58\uff0c\u4e0d\u8b93 GPU \u7b49\u3002 <br>\uff08\u4e8c\uff09PagedAttentionPagedAttention \u662f\u89e3\u6c7a KV-Cache \u7684 \u300c\u8a18\u61b6\u9ad4\u7247\u6bb5\u5316\u300d \u75db\u9ede\uff0c\u50b3\u7d71 KV-Cache \u8981\u5206\u914d\u9023\u7e8c\u986f\u5b58\uff0c\u4f8b\u5982\u4e00\u500b\u8acb\u6c42\u8981 100 \u500b token\uff0c\u5f97\u627e\u4e00\u584a 100token \u7684\u9023\u7e8c\u7a7a\u9593\uff0c\u8981\u662f\u986f\u5b58\u88e1\u6709 10 \u500b token\uff0c\u5f97\u627e\u4e00\u584a 100token \u7684\u9023\u7e8c\u7a7a\u9593\uff0c\u8981\u662f\u986f\u5b58\u6709 10 \u500b 10token \u7684\u7a7a\u9592\u584a\uff0c\u4e5f\u53ea\u80fd\u7528\u7a7a\u584a\u3002 <br>PagedAttention \u5b78\u4f5c\u696d\u7cfb\u7d71\u7684\u8a18\u61b6\u9ad4\u5206\u9801\uff0c\u628a KV-Cache \u5207\u6210\u56fa\u5b9a\u5927\u5c0f\u7684 \u300c\u9801\u300d\uff08\u4f8b\u5982\u6bcf\u9801\u5b58 64 \u500b token \u7684 KV\uff09\uff0c\u4e00\u500b\u8acb\u6c42\u7684 KV \u4e0d\u7528\u9023\u7e8c\u5b58\uff0c\u5206\u6563\u5728\u591a\u500b\u9801\u88e1\uff0c\u7528 \u201c\u9801\u8868\u201d \u8a18\u6bcf\u500b\u9801\u7684\u4f4d\u7f6e\uff0c\u9019\u6a23\u4e0d\u7ba1\u7a7a\u9592\u9801\u5728\u54ea\uff0c\u6578\u91cf\u5920\u7528\uff0c\u5fb9\u5e95\u89e3\u6c7a\u788e\u7247\u3002\u4f8b\u5982\u4e00\u500b\u8acb\u6c42\u8981 100 \u500b token\uff0c\u62ff 2 \u500b\u9801\uff0864+36\uff0c\u7b2c\u4e8c\u9801\u53ea\u7528 36 \u500b\u4f4d\u7f6e\uff09\u5c31\u884c\uff0c\u4e0d\u7528\u7ba1\u9019\u5169\u500b\u9801\u5728\u986f\u5b58\u7684\u54ea\u500b\u89d2\u843d\u3002<br>\u800c\u4e14\u5b83\u9084\u652f\u63f4 \u201c\u9801\u5171\u4eab\u201d\uff0c\u4f8b\u5982\u5169\u500b\u8acb\u6c42\u6709\u76f8\u540c\u7684\u524d\u7db4\uff08\u4f8b\u5982\u90fd\u7528\u540c\u4e00\u6bb5\u6587\u6a94\u7576\u4e0a\u4e0b\u6587\uff09\uff0c\u5b83\u5011\u7684\u524d\u7db4 KV \u9801\u80fd\u5171\u4eab\uff0c\u4e0d\u7528\u5b58\u5169\u4efd\uff0c\u9019\u5c31\u8ddf\u5f8c\u9762\u7684 APC \u806f\u52d5\u4e0a\u4e86\u3002\u6dd8\u6c70\u7b56\u7565\u4e5f\u4e0d\u662f\u7c21\u55ae LRU\uff0c\u662f \u201c\u5f15\u7528\u8a08\u6578 + LRU\u201d\uff0c\u4f8b\u5982\u4e00\u500b\u9801\u88ab 3 \u500b\u8acb\u6c42\u5171\u4eab\uff0c\u5f15\u7528\u8a08\u6578\u662f 3\uff0c\u53ea\u6709\u6240\u6709\u8acb\u6c42\u90fd\u4e0d\u7528\u4e86\uff0c\u8a08\u6578\u6b78 0\uff0c\u624d\u6703\u88ab\u6dd8\u6c70\uff0c\u4e0d\u6703\u8aa4\u522a\u5171\u4eab\u9801\u3002 \uff08\u4e09\uff09\u81ea\u52d5\u524d\u7db4\u5feb\u53d6(APC)\u81ea\u52d5\u524d\u7db4\u5feb\u53d6 (APC) \u89e3\u6c7a\u7684\u662f \u201c\u524d\u7db4\u91cd\u8907\u8a08\u7b97\u201d \u7684\u5927\u5751\uff0c\u4f8b\u5982 100 \u500b\u7528\u6236\u554f \u201c\u9019\u4efd 2025 \u8ca1\u5831\u7684\u5229\u6f64\u662f\u591a\u5c11\u201d\u201c\u9019\u4efd 2025 \u8ca1\u5831\u7684\u71df\u6536\u662f\u591a\u5c11\u201d\uff0c\u524d\u9762\u90fd\u5e36\u76f8\u540c\u7684 1000 \u5b57 0 100 \u6b21\uff0c\u7d14\u6d6a\u8cbb\u3002 <br>APC \u7684\u6838\u5fc3\u662f \u201c\u524d\u7db4\u7279\u5fb5\u54c8\u5e0c + \u9801\u5171\u4eab\u201d\uff0c\u4e0d\u662f\u76f4\u63a5\u5c0d token \u54c8\u5e0c\uff0c\u800c\u662f\u5c0d\u524d\u7db4\u5c0d\u61c9\u7684 KV \u9801\u7279\u5fb5\u505a\u54c8\u5e0c\uff08\u6bd4\u5982\u628a\u6bcf\u500b KV \u9801\u7684\u7279\u5fb5\u58d3\u7e2e\u6210\u54c8\u5e0c\u503c\uff09\uff0c\u9019\u6a23\u5373\u4f7f\u524d\u7db4\u7565\u6709\u4e0d\u540c\uff08\u6bd4\u5982 \u201c2025 \u8ca1\u5831\u201d \u548c \u201c2025 \u5e74\u5ea6\u8ca1\u5831\u201d\uff09\uff0c\u4e5f\u80fd\u5339\u914d\u5230\u76f8\u4f3c KV \u9801\uff0c\u63d0\u9ad8\u547d\u4e2d\u7387\u3002<br>\u800c\u4e14\u5b83\u80fd \u201c\u52d5\u614b\u5339\u914d\u5b50\u96c6\u201d\uff0c\u4f8b\u5982\u524d\u7db4 A \u662f \u201c\u8ca1\u5831\u7b2c\u4e00\u7ae0\u201d\uff0c\u524d\u7db4 B \u662f \u201c\u8ca1\u5831\u7b2c\u4e00\u7ae0\u7b2c\u4e00\u7bc0\u201d\uff0cAPC \u80fd\u8a8d\u51fa B \u662f A \u7684\u5b50\u96c6\uff0c\u76f4\u63a5\u5171\u4eab A \u88e1\u7b2c\u4e00\u7bc0\u7684 KV \u9801\uff0c\u4e0d\u7528\u91cd\u7b97\u3002 vLLM \u88e1\u7684APC \u9084\u8ddf\u8acb\u6c42\u968a\u5217\u7d81\u5728\u4e00\u8d77\uff0c\u65b0\u8acb\u6c42\u9032\u4f86\u5148\u67e5\u54c8\u5e0c\u8868\uff0c\u6709\u5339\u914d\u7684\u7de9\u5b58\u5c31\u76f4\u63a5\u52a0\u8f09\uff0c\u8df3\u904e\u6700\u8cbb\u7b97\u529b\u7684 prefill \u968e\u6bb5\uff08\u8a08\u7b97\u524d\u7db4 KV \u7684\u968e\u6bb5\uff09\uff0c\u76f4\u63a5\u9032 decode \u968e\u6bb5\uff08\u751f\u6210\u56de\u7b54 token\uff09\uff0cprefill \u968e\u6bb5\u672c\u4f86\u5c31\u4f54\u76f4\u63a5\u7b97\u529b\u7684 70% \u4ee5\u4e0a\uff0c\u6240\u4ee5 APC \u4e00\u4e0a\uff0c\u541e\u5410\u91cf\u597d\u5e7e\u6f32\u597d\u5e7e\u500d\u3002\u53e6\u5916\uff0cAPC \u5f97\u8655\u7406 \u201c\u5feb\u53d6\u904e\u671f\u201d\uff0c\u4f8b\u5982\u8ca1\u5831\u66f4\u65b0\u4e86\uff0c\u820a\u5feb\u53d6\u5c31\u5f97\u522a\uff0c\u6240\u4ee5\u6bcf\u500b\u5feb\u53d6\u5340\u584a\u90fd\u6709 \u201c\u7248\u672c\u865f\u201d \u548c \u201c\u6642\u9593\u6233\u201d\uff0c\u6587\u4ef6\u4e00\u66f4\u65b0\uff0c\u81ea\u52d5\u6dd8\u6c70\u820a\u7248\uff0c\u907f\u514d\u56de\u50b3\u932f\u8aa4\u8cc7\u6599\u3002 <br>\uff08\u56db\uff09\u5206\u6563\u5f0f\u63a8\u7406\u4e26\u884c\u65b9\u6848TP\u548cPP\u9019\u5169\u7a2e\u5206\u4f48\u5f0f\u63a8\u7406\u4e26\u884c\u65b9\u6848\u5176\u5be6\u662f\u89e3\u6c7a\u63a8\u7406\u6642&#8221;\u4eba\u591a\u529b\u91cf\u5927&#8221;\u4f46\u53c8&#8221;\u5225\u6436\u8457\u5e79\u6d3b&#8221;\u7684\u554f\u984c\u3002 <br>TP\uff08\u5f35\u91cf\u4e26\u884c\uff09\u662f\u628a\u4e00\u500b\u5927\u86cb\u7cd5\u5207\u6210\u591a\u584a\uff0c\u6bcf\u584a\u7531\u4e0d\u540c\u7684\u4eba\u8ca0\u8cac\u5207\uff0c\u4f46\u6700\u7d42\u8981\u62fc\u6210\u4e00\u500b\u5b8c\u6574\u7684\u86cb\u7cd5\u3002<br>\u5177\u9ad4\u4f86\u8aaa\uff0cTP\u628a\u6a21\u578b\u7684\u5f35\u91cf\uff08\u4f8b\u5982\u591a\u982d\u6ce8\u610f\u529b\u4e2d\u7684\u6bcf\u500b\u982d\uff09\u5206\u6563\u5230\u591a\u500bGPU\u4e0a\uff0c\u6bcf\u500bGPU\u53ea\u8ca0\u8cac\u4e00\u90e8\u5206\u8a08\u7b97\uff0c\u4f8b\u5982MHA\u4e26\u884c\u5c31\u662f\u628a\u591a\u982d\u6ce8\u610f\u529b\u7684\u6bcf\u500b\u982d\u5207\u5206\u5230\u4e0d\u540cGPU\uff0cKV\u5feb\u53d6\u4e5f\u8ddf\u8457\u5207\u5206\u3002<br>\u9019\u6a23\uff0c\u7576\u6a21\u578b\u5f88\u5927\u6642\uff0c\u55ae\u4e00GPU\u653e\u4e0d\u4e0b\uff0cTP\u5c31\u80fd\u628a\u4e00\u500b\u5927\u904b\u7b97\u4efb\u52d9\u62c6\u6210\u5c0f\u584a\uff0c\u8b93\u591a\u500bGPU\u4e00\u8d77\u5de5\u4f5c\uff0c\u907f\u514d\u4e86\u55ae\u5361\u8a18\u61b6\u9ad4\u4e0d\u8db3\u7684\u554f\u984c\uff0c\u800c\u4e14\u9084\u80fd\u540c\u6642\u8655\u7406KV\u5feb\u53d6\u7684\u5207\u5206\uff0c\u8b93\u63a8\u7406\u6548\u7387\u66f4\u9ad8\u3002 <br>PP\uff08\u7ba1\u7dda\u4e26\u884c\uff09\u628a\u6574\u500b\u6a21\u578b\u4f9d\u5c64\u5207\u6210\u591a\u500b\u968e\u6bb5\uff0c\u6bcf\u500bGPU\u8ca0\u8cac\u4e00\u500b\u968e\u6bb5\u7684\u8a08\u7b97\uff0c\u5c31\u50cf\u751f\u7522\u7dda\u4e0a\u7684\u4e0d\u540c\u5de5\u4f4d\u4e00\u6a23\u3002<br>\u4f8b\u5982\u7b2c\u4e00\u5c64\u5728GPU1\u4e0a\u7b97\uff0c\u7b97\u5b8c\u5f8c\u628a\u7d50\u679c\u50b3\u7d66GPU2\u7b97\u7b2c\u4e8c\u5c64\uff0cGPU1\u7a7a\u9592\u4e86\u53c8\u80fd\u63a5\u65b0\u4efb\u52d9\u3002\u9019\u6a23\u7576\u8acb\u6c42\u91cf\u5927\u6642\uff0cGPU1\u53ef\u4ee5\u7e7c\u7e8c\u8655\u7406\u65b0\u8acb\u6c42\uff0c\u800cGPU2\u9084\u5728\u8655\u7406\u4e0a\u4e00\u500b\u8acb\u6c42\u7684\u5f8c\u7e8c\u5c64\uff0c\u5927\u5927\u6e1b\u5c11\u4e86\u8a2d\u5099\u7a7a\u9592\u6642\u9593\u3002 <br>PP\u6700\u53b2\u5bb3\u7684\u662f\u5b83\u901a\u8a0a\u91cf\u5c0f\uff0c\u56e0\u70ba\u53ea\u50b3\u5c64\u9593\u7684\u555f\u52d5\u503c\uff0cKV\u5feb\u53d6\u662f\u7368\u7acb\u7684\uff0c\u4e0d\u9700\u8981\u8de8\u88dd\u7f6e\u50b3\u905e\uff0c\u6240\u4ee5\u80fd\u652f\u63f4\u66f4\u5927\u7684batch_size\uff0c\u56e0\u70ba\u55ae\u4e00GPU\u53ea\u5b58\u6a21\u578b\u7684\u4e00\u90e8\u5206\uff0c\u7bc0\u7d04\u4e0b\u4f86\u7684\u986f\u5b58\u53ef\u4ee5\u5b58\u66f4\u591aKV\u5feb\u53d6\u3002 <br>TP \u662f \u201c\u6c34\u5e73\u5207\u5206\u201d\uff0c\u5c07\u540c\u4e00\u5c64\u7684\u6a21\u578b\u6b0a\u91cd\u62c6\u5230\u591a\u5361\uff0c\u4f8b\u5982 16 \u500b\u982d\u7684 Attention\uff0c\u7528 4 \u5361 TP\uff0c\u6bcf\u5361\u8ca0\u8cac 4 \u500b\u982d\uff0c\u89e3\u6c7a \u201c\u55ae\u5361\u88dd\u4e0d\u4e0b\u5927\u6a21\u578b\u201d \u7684\u554f\u984c\u3002\u4f46 TP \u6709\u4e0a\u9650\uff0c\u4e26\u884c\u5ea6\u4e0d\u80fd\u8d85\u904e\u6a21\u578b\u7684 \u201c\u53ef\u5207\u5206\u7dad\u5ea6\u201d\uff0c\u4f8b\u5982\u53ea\u6709 16 \u500b\u982d\uff0c\u6700\u591a 16 \u5361 TP\uff0c\u518d\u591a\u5c31\u6c92\u6cd5\u5207\u4e86\uff0c\u6240\u4ee5\u9069\u5408\u4e2d\u5c0f\u898f\u6a21\u4e26\u884c\u3002 <br>PP \u662f \u201c\u5782\u76f4\u5207\u5206\u201d\uff0c\u628a\u4e0d\u540c\u5c64\u62c6\u5230\u591a\u5361\uff0c\u4f8b\u5982 100 \u5c64\u6a21\u578b\uff0c\u7528 10 \u5361 PP\uff0c\u6bcf\u5361\u8ca0\u8cac 10 \u5c64\uff0c\u89e3\u6c7a \u201c\u5c64\u6578\u592a\u591a\u8a08\u7b97\u6162\u201d \u7684\u554f\u984c\u3002 <br>PP \u7684\u95dc\u9375\u662f\u6e1b\u5c11 \u201c\u6d41\u6c34\u7dda\u6c23\u6ce1\u201d\uff0c\u525b\u958b\u59cb\u5361 2 \u8981\u7b49\u5361 1 \u7b97\u5b8c\u624d\u52d5\uff0c\u6709\u500b\u7a7a\u7a97\u671f\uff0c\u73fe\u5728\u90fd\u7528 \u201c\u91cd\u758a\u901a\u4fe1\u201d\uff0c\u5361 1 \u8981\u7b49\u5361 1 \u7b97\u5b8c\u624d\u52d5\uff0c\u6709\u500b\u7a7a\u7a97\u671f\uff0c\u73fe\u5728\u90fd\u7528 \u201c\u91cd\u758a\u901a\u4fe1\u201d\uff0c\u5361 1 \u7b97\u5b8c\u4e00\u5c64\u5c31\u628a\u4e2d\u9593\u7d50\u679c\u50b3\u7d66\u5361 2\uff0c\u4e0d\u7528\u7b49 10 \u5c64\u90fd\u7b97\u5b8c\uff0c\u6c23\u6ce1\u5c31\u5c0f\u7b97\u4e86\u3002 TP \u548c PP \u53ef\u4ee5\u9019\u6a23\u6df7\u5408\u7528\uff1a\u5148\u6309 TP \u628a\u6bcf\u5c64\u62c6\u6210 M \u5361\uff0c\u518d\u6309 PP \u628a M \u5361\u4e00\u7d44\u7684\u5c64\u62c6\u6210 N \u7d44\uff0c\u7e3d\u5171 M*N \u5361\uff0c\u4f8b\u5982 4 \u5361 TP+2 \u5361 PP=8 \u5361\uff0c\u65e2\u80fd\u88dd\u4e0b\u5927\u6a21\u578b\uff08TP \u89e3\u5927\u5c0f\uff09\uff0c\u53c8\u80fd\u63d0\u901f\uff08PP \u89e3\u5c64\u6578\u591a\uff09\u3002<br>\u83ef\u70ba\u7684 \u300c1 \u5361 1 \u5c08\u5bb6\u300d \u662f MoE \u6a21\u578b\u7684\u4e26\u884c\uff0c\u6bcf\u500b\u5c08\u5bb6\u653e\u4e00\u5361\uff0cTP \u5207\u5206\u55ae\u4e00\u5c08\u5bb6\u7684\u6b0a\u91cd\uff0cPP \u5207\u5206 MoE \u7684\u5c64\uff0c\u65e2\u7528 MoE \u7684\u7a00\u758f\u6027\uff08\u6bcf\u6b21\u53ea\u6fc0\u6d3b\u90e8\u5206\u5c08\u5bb6\uff09\uff0c\u53c8\u89e3\u6c7a\u5c08\u5bb6\u6578\u91cf\u591a\u7684\u554f\u984c\u3002 <br>DistriFusion \u662f\u5f71\u50cf\u7522\u751f\u7684\u4e26\u884c\uff0c\u628a\u5f71\u50cf\u5340\u584a\u4ee5\u7a7a\u9593\u5207\u5206\uff0c\u6bcf\u5361\u7b97\u4e00\u500b\u5340\u584a\uff0c\u6e1b\u5c11\u908a\u7de3\u901a\u4fe1\uff0c\u672c\u8cea\u662f TP \u7684\u8b8a\u7a2e\u3002 <br>\uff08\u4e94\uff09\u7b97\u5b50\u878d\u5408\u512a\u5316\u7b97\u5b50\u878d\u5408\u5176\u5be6\u5c31\u662f\u8b93\u795e\u7d93\u7db2\u8def\u7684\u904b\u7b97\u6d41\u7a0b\u8b8a\u5f97\u66f4\u7dca\u6e4a\uff0c\u4f60\u505a\u83dc\u7684\u8a71\uff0c\u4e0d\u53ef\u80fd\u6bcf\u5207\u4e00\u584a\u8089\u5c31\u8981\u6d17\u4e00\u6b21\u5200\uff0c\u63db\u4e00\u6b21\u7827\u677f\u3002\u7b97\u5b50\u878d\u5408\u5c31\u662f\u628a\u5207\u8089\u3001\u6d17\u5200\u3001\u63db\u7827\u677f\u9019\u4e9b\u6b65\u9a5f\u5408\u4f75\u6210\u4e00\u500b\u9023\u8cab\u7684\u52d5\u4f5c\uff0c\u76f4\u63a5\u628a\u8089\u5207\u597d\u5c31\u4e0b\u934b\uff0c\u4e0d\u7528\u4f86\u56de\u6298\u9a30\u3002<br>\u7b97\u5b50\u878d\u5408\u4e0d\u662f\u7c21\u55ae \u201c\u5408\u4f75\u6b65\u9a5f\u201d\uff0c\u800c\u662f\u6293 \u201c\u986f\u5b58\u983b\u5bec\u74f6\u9838\u201d\u3002\u6bcf\u500b\u7b97\u5b50\u555f\u52d5\u4e00\u6b21 CUDA Kernel \u8981\u82b1\u5e7e\u5341\u5fae\u79d2\uff0c\u5169\u500b\u7b97\u5b50\u555f\u52d5\u5169\u6b21\u5c31\u591a\u4e00\u7b46\u958b\u92b7\uff0c\u9019\u9084\u662f\u5c0f\u4e8b\u3002<br>\u66f4\u8981\u547d\u7684\u662f\u6c92\u878d\u5408\u6642\uff0cAdd \u7684\u8f38\u51fa\u8981\u5beb\u56de\u986f\u5b58\uff0cLayerNorm \u518d\u5f9e\u986f\u5b58\u8b80\uff0c\u4e00\u5beb\u4e00\u8b80\u4f54\u5169\u6b21\u983b\u5bec\uff0c\u986f\u5b58\u983b\u5bec\u672c\u4f86\u5c31\u4e0d\u5920\uff0c\u9019\u4e00\u5835\u5c31\u6162\u4e86\u3002<br>\u878d\u5408\u5f8c\uff0cAdd \u7684\u8f38\u51fa\u76f4\u63a5\u5728 GPU \u7684\u66ab\u5b58\u5668\uff08\u6216\u5171\u4eab\u8a18\u61b6\u9ad4\uff09\u50b3\u7d66 LayerNorm\uff0c\u4e0d\u7528\u78b0\u986f\u5b58\uff0c\u5c11\u4e86\u5169\u6b21\u983b\u5bec\u4f54\u7528\uff0c\u9084\u7701\u4e86\u4e00\u6b21 Kernel \u555f\u52d5\u958b\u92b7\u3002<br>\u4f46\u878d\u5408\u5f97\u770b \u201c\u4f9d\u8cf4\u548c\u76f8\u5bb9\u6027\u201d\uff0c\u4f8b\u5982 Add \u548c LayerNorm \u662f\u524d\u5f8c\u4f9d\u8cf4\uff0c\u9084\u5728\u540c\u4e00\u7dad\u5ea6\u64cd\u4f5c\uff0c\u624d\u80fd\u5408\u3002<br>\u9019\u7a2e\u512a\u5316\u4e0d\u6539\u8b8a\u8a08\u7b97\u908f\u8f2f\uff0c\u53ea\u662f\u628a\u8a08\u7b97\u6d41\u7a0b\u91cd\u7d44\u4e86\uff0c\u53ea\u662f\u628a\u6211\u5011\u7d44\u54e1\u7684\u5de5\u4f4d\u5408\u4f75\uff0c\u4e0d\u7528\u4f86\u56de\u8d70\u52d5\u3002<br>\u5728Transformer\u9019\u7a2e\u7d50\u69cb\u88e1\uff0c\u9019\u7a2e\u878d\u5408\u7279\u5225\u6709\u6548\uff0c\u56e0\u70ba\u50cfAdd\u548cLayerNorm\u9019\u7a2e\u64cd\u4f5c\u672c\u4f86\u5c31\u662f\u524d\u5f8c\u4f9d\u8cf4\u7684\uff0c\u5b8c\u5168\u53ef\u4ee5\u5408\u4f75\u3002<br> FasterTransformer \u628a MultiHeadAttention \u7684\u6574\u5957\u6d41\u7a0b\uff08QKV \u6295\u5f71\u2192Scaled Dot-Product\u2192\u591a\u982d\u62fc\u63a5\u2192\u7dda\u6027\u5c64\uff09\u90fd\u878d\u5408\u6210\u4e00\u500b Kernel\uff0c\u539f\u4f86\u8981\u555f\u52d5 5-6 \u6b21 Kernel\uff0c\u73fe\u5728\u4e00\u6b21\u641e\u5b9a\uff0c\u4e2d\u9593\u8cc7\u6599\u5168\u5728\u5171\u4eab\u5167\u5b58\u88e1\u50b3\uff0c\u986f\u5b58\u8a2a\u554f\u5c11 80% \u4ee5\u4e0a\uff0c\u901f\u5ea6\u76f4\u63a5\u7ffb\u500d\u3002<br>\u4e09\u3001\u6a21\u578b\u91cf\u5316\u6280\u8853\u6700\u5f8c\u662f\u6a21\u578b\u91cf\u5316\uff0c\u505a\u5230\u5e73\u8861\u7cbe\u5ea6\u640d\u5931\u548c\u7bc0\u7701\u8cc7\u6e90\u3002<br>\u5927\u6a21\u578b\u7684\u5751\u5728\u65bc\u6d3b\u5316\u503c\u548c\u6b0a\u91cd\u5206\u4f48\u6975\u4e0d\u5747\u52fb\uff0c\u4f8b\u5982\u6d3b\u5316\u503c\u88e1\u53ef\u80fd\u6709\u5e7e\u500b 100 \u7684\u96e2\u7fa4\u503c\uff0c\u5927\u90e8\u5206\u5728 &#8211; 1 \u5230 1 \u4e4b\u9593\uff0c\u666e\u901a\u5c0d\u7a31\u91cf\u5316\u6703\u628a\u7bc4\u570d\u62c9\u5230 [-100,100]\uff0c\u5c0f\u503c\u5168\u88ab\u91cf\u5316\u6210 0\uff0c\u5931\u771f\u56b4\u91cd\u3002 <br>SmoothQuant \u7684\u8fa6\u6cd5\u662f \u201c\u8f49\u79fb\u8aa4\u5dee\u201d\uff0c\u7d66\u6d3b\u5316\u503c\u4e58 0.1 \u7e2e\u5230 [-10,10]\uff0c\u6b0a\u91cd\u4e58 10 \u64f4\u5230 [-100,100]\uff0c\u8b93\u5169\u8005\u91cf\u5316\u7bc4\u570d\u63a5\u8fd1\uff0c\u5931\u771f\u8b8a\u5c0f\u3002 <br>LLM.int8 \u662f \u201c\u6df7\u5408\u7cbe\u5ea6\u201d\uff0c\u6b0a\u91cd\u7528 INT8\uff0c\u6fc0\u6d3b\u503c\u88e1\u7684\u96e2\u7fa4\u503c\u7528 FP16\uff0c\u56e0\u70ba\u96e2\u7fa4\u503c\u5c11\u4f46\u5f71\u97ff\u5927\uff0c\u9019\u6a23\u65e2\u7701\u8cc7\u6e90\u53c8\u4fdd\u7cbe\u5ea6\uff0c\u6bd4\u5982 99% \u7684\u6578\u7528 INT8\uff0c1% \u7528 FP16\uff0c\u986f\u5b58\u53ea\u591a\u4e00\u9ede\uff0c\u7cbe\u5ea6\u8ddf FP16 \u5dee\u4e0d\u591a\u3002 <br>GPTQ \u66f4\u72e0\uff0c\u91cf\u5316\u524d\u5148\u5fae\u8abf\uff0c\u628a\u6b0a\u91cd\u5207\u6210\u5c0f\u584a\uff0c\u6bcf\u584a\u91cf\u5316\u5f8c\u7b97\u8aa4\u5dee\uff0c\u518d\u8abf\u6574\u672a\u91cf\u5316\u7684\u6b0a\u91cd\u88dc\u511f\u8aa4\u5dee\uff0c\u76f8\u7576\u65bc \u201c\u7626\u8eab\u6642\u88dc\u71df\u990a\u201d\uff0c\u8b93\u6a21\u578b\u7626\u4e86\u9084\u6709\u529b\u6c23\u3002<br>\u4f8b\u5982 16B \u6a21\u578b FP16 \u8981 32GB \u986f\u5b58\uff0cINT4 \u91cf\u5316\u5f8c\u53ea\u8981 10GB\uff0c\u666e\u901a\u986f\u793a\u5361\u5c31\u80fd\u8dd1\uff0cbatch_size \u9084\u80fd\u7ffb\u500d\uff0c\u901f\u5ea6\u5feb 4 \u500d\u4ee5\u4e0a\u3002\u5bd2\u6b66\u7d00\u7684 vLLM-MLU \u7528 INT8\uff0c\u662f\u56e0\u70ba MLU \u7684 INT8 \u8a08\u7b97\u55ae\u5143\u6bd4 FP16 \u591a\uff0c\u4f8b\u5982\u6bcf\u500b\u6838\u5fc3\u6709 1024 \u500b INT8 ALU\uff0c\u53ea\u6709 256 \u500b FP16 \u7684\uff0c\u4e0d\u7528 INT8 \u5c31\u6d6a\u8cbb\u786c\u9ad4\u7b97\u529b\u3002<br>\u53e6\u5916\uff0c\u91cf\u5316\u9084\u5f97\u9632 \u201c\u6ea2\u51fa\u201d\uff0cINT8 \u7bc4\u570d\u662f &#8211; 128 \u5230 127\uff0c\u8a08\u7b97\u524d\u5f97\u628a\u8f38\u5165\u7e2e\u5230\u4f4d\uff0c\u4e0d\u7136\u4e00\u6ea2\u51fa\u7d50\u679c\u5c31\u932f\u4e86\uff0c\u73fe\u5728\u7684\u91cf\u5316\u7b97\u5b50\u90fd\u6709\u52d5\u614b\u7e2e\u653e\uff0c\u5c31\u662f\u505a\u9019\u4ef6\u4e8b\u60c5\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ecb\u7d39\u5927\u6a21\u578b\u63a8\u7406\u6548\u80fd\u7684\u6700\u4f73\u5316\u65b9\u6cd5\u3002\u5305\u62ec\u4e09\u500b\u65b9\u9762\uff1a\u670d\u52d9\u8abf\u5ea6\u3001\u8a08\u7b97\u5f15\u64ce\u548c\u6a21\u578b\u6f14\u7b97\u6cd5\u3002\u672c\u6587\u53c3\u8003\uff1a\u5b6b\u6176\u864e\uff08\u6545\u5317\uff09\uff0c\u516c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6410","post","type-post","status-publish","format-standard","hentry","category-killtest"],"_links":{"self":[{"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/posts\/6410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/comments?post=6410"}],"version-history":[{"count":1,"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/posts\/6410\/revisions"}],"predecessor-version":[{"id":6411,"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/posts\/6410\/revisions\/6411"}],"wp:attachment":[{"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/media?parent=6410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/categories?post=6410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.killtest.hk\/index.php\/wp-json\/wp\/v2\/tags?post=6410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}