{"id":98545,"date":"2026-09-01T06:59:33","date_gmt":"2026-08-31T22:59:33","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/98545.html"},"modified":"2026-09-01T06:59:33","modified_gmt":"2026-08-31T22:59:33","slug":"%e5%a4%a7%e8%af%ad%e8%a8%80%e6%a8%a1%e5%9e%8b%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/98545.html","title":{"rendered":"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840"},"content":{"rendered":"<h3>\u4e00\u3001 \u5927\u8bed\u8a00\u6a21\u578b\u7684\u6570\u5b66\u672c\u8d28\u4e0e\u6f14\u8fdb\u673a\u7406<\/h3>\n<h4>1.1 \u8bed\u8a00\u6a21\u578b\u7684\u5f62\u5f0f\u5316\u5b9a\u4e49<\/h4>\n<p>\u4ece\u6982\u7387\u8bba\u4e0e\u7edf\u8ba1\u5b66\u89c6\u89d2\u6765\u770b&#xff0c;\u8bed\u8a00\u6a21\u578b&#xff08;Language Model, LM&#xff09;\u7684\u76ee\u6807\u662f\u5efa\u7acb\u4e00\u4e2a\u8ba1\u7b97\u81ea\u7136\u8bed\u8a00\u5e8f\u5217\u6982\u7387\u5206\u5e03\u7684\u6570\u5b66\u6a21\u578b\u3002<\/p>\n<p>\u8bbe\u4e00\u6bb5\u6587\u672c\u7531\u6309\u65f6\u5e8f\u6392\u5217\u7684\u8bcd\u5143&#xff08;Token&#xff09;\u5e8f\u5217\u7ec4\u6210&#xff1a;W &#061; (w_1, w_2, w_3, &#8230;, w_n)\u3002\u6839\u636e\u6761\u4ef6\u6982\u7387\u7684\u94fe\u5f0f\u6cd5\u5219&#xff0c;\u8be5\u5e8f\u5217\u7684\u8054\u5408\u6982\u7387\u5206\u5e03\u53ef\u4ee5\u4e25\u683c\u5c55\u5f00\u4e3a&#xff1a;<\/p>\n<p>P(W) &#061; P(w_1, w_2, &#8230;, w_n) &#061; \u220f [i&#061;1 \u5230 n] P(w_i | w_1, w_2, &#8230;, w_{i-1})<\/p>\n<p>\u5bf9\u4e8e\u81ea\u56de\u5f52\u8bed\u8a00\u6a21\u578b&#xff08;Autoregressive LM&#xff09;\u800c\u8a00&#xff0c;\u5176\u6838\u5fc3\u4efb\u52a1\u662f\u5728\u7ed9\u5b9a\u5386\u53f2\u4e0a\u4e0b\u6587 (w_1, w_2, &#8230;, w_{t-1}) \u7684\u6761\u4ef6\u4e0b&#xff0c;\u9884\u6d4b\u4e0b\u4e00\u4e2a\u8bcd\u5143 w_t \u51fa\u73b0\u7684\u6761\u4ef6\u6982\u7387\u5206\u5e03&#xff1a;<\/p>\n<p>P(w_t | w_1, w_2, &#8230;, w_{t-1}) &#061; Softmax( f_\u03b8(w_1, w_2, &#8230;, w_{t-1}) )<\/p>\n<p>\u5176\u4e2d&#xff0c;f_\u03b8 \u4ee3\u8868\u7531\u6570\u5341\u4ebf\u81f3\u6570\u4e07\u4ebf\u53c2\u6570 \u03b8 \u6784\u6210\u7684\u6df1\u5ea6\u795e\u7ecf\u7f51\u7edc&#xff0c;\u5176\u8f93\u51fa\u4e3a\u4e00\u4e2a\u7ef4\u5ea6\u7b49\u4e8e\u8bcd\u8868\u5927\u5c0f&#xff08;Vocabulary Size&#xff09;\u7684\u672a\u5f52\u4e00\u5316\u5206\u6570\u503c&#xff08;Logits&#xff09;&#xff0c;\u901a\u8fc7 Softmax \u51fd\u6570\u5c06\u5176\u8f6c\u5316\u4e3a\u5404\u8bcd\u5143\u7684\u9884\u6d4b\u6982\u7387\u3002<\/p>\n<p>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502                   \u8bed\u8a00\u6a21\u578b\u5386\u53f2\u6f14\u8fdb\u6280\u672f\u8def\u5f84                   \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                               \u2502<br \/>\n 1. \u7edf\u8ba1\u8bed\u8a00\u6a21\u578b (N-gram)      \u9a6c\u5c14\u53ef\u592b\u5047\u8bbe \u2794 \u77e9\u9635\u7a00\u758f \u2794 \u65e0\u6cd5\u5efa\u6a21\u957f\u8ddd\u79bb\u4f9d\u8d56<br \/>\n                               \u2502<br \/>\n 2. \u5faa\u73af\u795e\u7ecf\u7f51\u7edc (RNN \/ LSTM)  \u65f6\u5e8f\u9690\u85cf\u72b6\u6001\u4f20\u9012 \u2794 \u987a\u5e8f\u4f9d\u8d56 \u2794 \u65e0\u6cd5\u786c\u4ef6\u9ad8\u5ea6\u5e76\u884c<br \/>\n                               \u2502<br \/>\n 3. \u53cc\u5411\u7f16\u7801\u6a21\u578b (BERT \u7cfb\u5217)   \u63a9\u7801\u8bed\u8a00\u6a21\u578b (MLM) \u2794 \u53cc\u5411\u4e0a\u4e0b\u6587 \u2794 \u64c5\u957f\u5224\u522b&#xff0c;\u751f\u6210\u8f83\u5f31<br \/>\n                               \u2502<br \/>\n 4. \u81ea\u56de\u5f52\u5927\u6a21\u578b (GPT \/ Llama) Decoder-Only Transformer \u2794 \u7edf\u4e00\u751f\u6210\u4e0e\u7406\u89e3\u4efb\u52a1<\/p>\n<h4>1.2 \u4e3a\u4ec0\u4e48\u4f20\u7edf\u6a21\u578b\u88ab Transformer Decoder-Only \u53d6\u4ee3&#xff1f;<\/h4>\n<p>\u5728\u6df1\u5ea6\u5b66\u4e60\u53d1\u5c55\u53f2\u4e0a&#xff0c;NLP \u9886\u57df\u7ecf\u5386\u8fc7\u591a\u6b21\u8303\u5f0f\u8fed\u4ee3&#xff1a;<\/p>\n<li>\n<p>N-gram \u7edf\u8ba1\u6a21\u578b&#xff1a;\u5f15\u5165\u9636\u6570\u4e3a N \u7684\u9a6c\u5c14\u53ef\u592b\u5047\u8bbe&#xff08;\u5373\u5f53\u524d\u8bcd\u53ea\u4e0e\u524d N-1 \u4e2a\u8bcd\u76f8\u5173&#xff09;\u3002\u7f3a\u70b9\u662f\u65e0\u6cd5\u6355\u83b7\u957f\u8ddd\u79bb\u8bed\u4e49&#xff0c;\u4e14\u8bcd\u8868\u7ec4\u5408\u968f N \u589e\u52a0\u5448\u6307\u6570\u7ea7\u7206\u70b8\u3002<\/p>\n<\/li>\n<li>\n<p>RNN \/ LSTM \/ GRU&#xff1a;\u5f15\u5165\u9690\u85cf\u72b6\u6001\u5faa\u73af\u4f20\u9012\u3002\u7f3a\u70b9\u662f\u65f6\u95f4\u6b65\u4e4b\u95f4\u5b58\u5728\u5f3a\u5e8f\u5217\u4f9d\u8d56&#xff0c;\u8ba1\u7b97\u65e0\u6cd5\u5728 GPU \u4e0a\u8fdb\u884c\u65f6\u95f4\u7ef4\u5ea6\u7684\u5e76\u884c\u5316&#xff0c;\u4e14\u9690\u85cf\u72b6\u6001\u5728\u957f\u5e8f\u5217\u4e0b\u5b58\u5728\u4fe1\u606f\u74f6\u9888\u548c\u68af\u5ea6\u6d88\u5931\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>BERT&#xff08;Encoder-Only \u53cc\u5411\u6a21\u578b&#xff09;&#xff1a;\u91c7\u7528 Transformer \u7f16\u7801\u5668\u7ed3\u6784&#xff0c;\u5229\u7528\u4e0a\u4e0b\u6587\u53cc\u5411\u6ce8\u610f\u529b\u673a\u5236&#xff0c;\u5728\u5206\u7c7b\u3001\u5b9e\u4f53\u8bc6\u522b\u7b49\u5224\u522b\u5f0f\u4efb\u52a1\u4e0a\u8868\u73b0\u4f18\u5f02&#xff0c;\u4f46\u5728\u81ea\u7531\u6587\u672c\u751f\u6210\u4efb\u52a1\u4e2d&#xff0c;\u81ea\u7f16\u7801&#xff08;Masked LM&#xff09;\u673a\u5236\u4e0e\u5b9e\u9645\u63a8\u65ad\u65f6\u9010\u5b57\u751f\u6210\u7684\u6d41\u7a0b\u5b58\u5728\u5929\u7136\u8131\u8282\u3002<\/p>\n<\/li>\n<li>\n<p>Decoder-Only \u67b6\u6784&#xff1a;\u901a\u8fc7\u5355\u5411\u56e0\u679c\u63a9\u7801&#xff08;Causal Mask&#xff09;&#xff0c;\u5c06\u6240\u6709\u81ea\u7136\u8bed\u8a00\u5904\u7406\u4efb\u52a1\u7edf\u4e00\u62bd\u8c61\u4e3a\u201c\u6839\u636e\u4e0a\u4e0b\u6587\u9884\u6d4b\u4e0b\u4e00\u4e2a\u8bcd\u201d\u7684\u81ea\u56de\u5f52\u751f\u6210\u4efb\u52a1&#xff0c;\u5b9e\u73b0\u4e86\u751f\u6210\u80fd\u529b\u3001\u6cdb\u5316\u80fd\u529b\u4e0e\u5927\u89c4\u6a21\u5e76\u884c\u8bad\u7ec3\u6548\u7387\u7684\u5e73\u8861\u3002<\/p>\n<\/li>\n<h4>1.3 \u7f29\u653e\u6cd5\u5219&#xff08;Scaling Laws&#xff09;\u4e0e\u6d8c\u73b0\u80fd\u529b&#xff08;Emergence&#xff09;<\/h4>\n<p>OpenAI \u5728 2020 \u5e74\u63d0\u51fa\u7684 Kaplan Scaling Law \u4ee5\u53ca DeepMind \u5728 2022 \u5e74\u4fee\u6b63\u7684 Chinchilla Scaling Law \u8868\u660e&#xff1a;\u6a21\u578b\u7684\u6027\u80fd&#xff08;\u4ea4\u53c9\u71b5\u635f\u5931 Loss&#xff09;\u4e0e\u8ba1\u7b97\u91cf&#xff08;Compute, C&#xff09;\u3001\u53c2\u6570\u91cf&#xff08;Parameters, N&#xff09; \u548c \u8bad\u7ec3\u6570\u636e\u96c6\u5927\u5c0f&#xff08;Dataset Size, D&#xff09; \u4e4b\u95f4\u5b58\u5728\u4e25\u683c\u7684\u5e42\u5f8b\u4f9d\u8d56\u5173\u7cfb&#xff1a;<\/p>\n<p>Loss(N, D) &#061; (N_c \/ N)^\u03b1_N &#043; (D_c \/ D)^\u03b1_D &#043; L_0<\/p>\n<p>\u6839\u636e Chinchilla \u6700\u4f18\u8ba1\u7b97\u914d\u7f6e&#xff1a;\u5f53\u8ba1\u7b97\u9884\u7b97\u589e\u52a0\u65f6&#xff0c;\u53c2\u6570\u91cf N \u4e0e\u8bad\u7ec3 Token \u6570 D \u5e94\u5f53\u540c\u6bd4\u4f8b\u7b49\u901f\u6269\u5f20&#xff08;\u5373\u6bcf\u589e\u52a0 1 \u500d\u53c2\u6570\u91cf&#xff0c;\u5e94\u5bf9\u5e94\u63d0\u4f9b 1 \u500d\u8bad\u7ec3\u6570\u636e&#xff0c;\u901a\u5e38\u6bd4\u4f8b\u7ea6\u4e3a 1:20&#xff09;\u3002<\/p>\n<p>\u8bc4\u4f30\u6307\u6807\u8868\u73b0<br \/>\n    \u25b2<br \/>\n    \u2502                                \u250c\u2500\u2500\u2500\u2500\u2500\u2500 \u9ad8\u9636\u63a8\u7406\/\u4ee3\u7801\u751f\u6210\/\u6570\u5b66\u903b\u8f91<br \/>\n    \u2502                                \u2502      (\u7a81\u53d8\u5f0f\u63d0\u5347: \u6d8c\u73b0\u80fd\u529b)<br \/>\n    \u2502                       \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n    \u2502                      \u2571<br \/>\n    \u2502             \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518  &lt;&#8211; \u4e34\u754c\u9608\u503c (\u901a\u5e38\u53c2\u6570\u91cf &gt; 10B~100B, \u6570\u636e\u91cf &gt; 1T Tokens)<br \/>\n    \u2502            \u2571<br \/>\n    \u2502    \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 (\u5e38\u89c4\u611f\u77e5\/\u7b80\u5355\u8bed\u6cd5\u4efb\u52a1: \u5e73\u6ed1\u63d0\u5347)<br \/>\n    \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25ba \u8bad\u7ec3\u7b97\u529b \/ \u53c2\u6570\u89c4\u6a21<\/p>\n<p>\u5f53\u6a21\u578b\u53c2\u6570\u91cf\u4e0e\u6570\u636e\u91cf\u8de8\u8d8a\u7279\u5b9a\u7684\u7b97\u529b\u9608\u503c\u65f6&#xff0c;\u6a21\u578b\u5728\u591a\u6b65\u7b97\u672f\u3001\u7b26\u53f7\u63a8\u7406\u3001\u4ee3\u7801\u751f\u6210\u53ca\u4e0a\u4e0b\u6587\u5c11\u6837\u672c\u5b66\u4e60&#xff08;In-Context Learning&#xff09;\u7b49\u590d\u6742\u4efb\u52a1\u4e0a\u7684\u51c6\u786e\u7387\u4f1a\u51fa\u73b0\u975e\u7ebf\u6027\u7684\u8dc3\u5347&#xff0c;\u8fd9\u79cd\u73b0\u8c61\u5728\u5b66\u672f\u754c\u88ab\u79f0\u4e3a\u6d8c\u73b0\u80fd\u529b&#xff08;Emergent Abilities&#xff09;\u3002<\/p>\n<h3>\u4e8c\u3001 Tokenization&#xff1a;\u6587\u672c\u4e0e\u6570\u503c\u4e16\u754c\u7684\u6865\u6881<\/h3>\n<p>\u8ba1\u7b97\u673a\u5e95\u5c42\u53ea\u80fd\u5904\u7406\u5f20\u91cf\u77e9\u9635&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u7406\u89e3\u5b57\u7b26\u3002\u5206\u8bcd\u5668&#xff08;Tokenizer&#xff09; \u662f\u5c06\u539f\u59cb\u81ea\u7136\u8bed\u8a00\u6587\u672c\u8f6c\u5316\u4e3a\u79bb\u6563\u6574\u6570\u5e8f\u5217&#xff08;Token IDs&#xff09;\u7684\u9884\u5904\u7406\u7ec4\u4ef6\u3002<\/p>\n<h4>2.1 \u5206\u8bcd\u7c92\u5ea6\u7684\u5de5\u7a0b\u6743\u8861<\/h4>\n<p>\u5206\u8bcd\u7b97\u6cd5\u5728\u7c92\u5ea6\u5212\u5206\u4e0a\u4e3b\u8981\u6709\u4e09\u79cd\u53d6\u820d&#xff1a;<\/p>\n<table>\n<tr>\n<td>\u5206\u8bcd\u7c92\u5ea6<\/td>\n<td>\u8bcd\u8868\u5927\u5c0f (Vocab Size)<\/td>\n<td>\u5e8f\u5217\u957f\u5ea6 (Sequence Length)<\/td>\n<td>\u4e3b\u8981\u7f3a\u9677<\/td>\n<\/tr>\n<tbody>\n<tr>\n<td>\u5b57\u7b26\u7ea7 (Character-level)<\/td>\n<td>\u6781\u5c0f&#xff08;\u51e0\u767e&#xff09;<\/td>\n<td>\u6781\u957f&#xff08;\u81a8\u80c0 3~5 \u500d&#xff09;<\/td>\n<td>\u5e8f\u5217\u8fc7\u957f\u5bfc\u81f4\u6ce8\u610f\u529b\u8ba1\u7b97\u5f00\u9500\u5267\u589e&#xff1b;\u5355\u5b57\u7b26\u627f\u8f7d\u8bed\u4e49\u7a00\u758f<\/td>\n<\/tr>\n<tr>\n<td>\u8bcd\u7ea7 (Word-level)<\/td>\n<td>\u6781\u5927&#xff08;\u6570\u767e\u4e07&#xff09;<\/td>\n<td>\u8f83\u77ed<\/td>\n<td>\u65e0\u6cd5\u5904\u7406\u672a\u767b\u5f55\u8bcd&#xff08;OOV, Out-Of-Vocabulary&#xff09;&#xff1b;\u8bcd\u8868\u77e9\u9635\u6781\u5927&#xff0c;\u5360\u7528\u5927\u91cf\u663e\u5b58<\/td>\n<\/tr>\n<tr>\n<td>\u5b50\u8bcd\u7ea7 (Subword-level)<\/td>\n<td>\u9002\u4e2d&#xff08;32K ~ 128K&#xff09;<\/td>\n<td>\u9002\u4e2d<\/td>\n<td>\u76ee\u524d\u5de5\u4e1a\u7ea7\u6807\u51c6&#xff1a;\u517c\u987e\u8bcd\u8868\u7d27\u51d1\u5ea6\u4e0e\u957f\u8ddd\u79bb\u8bed\u4e49\u8868\u8fbe<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.2 \u4e3b\u6d41\u5b50\u8bcd\u7b97\u6cd5&#xff1a;BPE&#xff08;Byte-Pair Encoding&#xff09;<\/h4>\n<p>\u76ee\u524d Llama\u3001GPT \u7cfb\u5217\u666e\u904d\u91c7\u7528 Byte-level BPE&#xff08;\u5b57\u8282\u7ea7\u5b57\u8282\u5bf9\u7f16\u7801&#xff09; \u7b97\u6cd5\u3002<\/p>\n<p>BPE \u7b97\u6cd5\u7684\u6784\u5efa\u8fc7\u7a0b&#xff1a;<\/p>\n<li>\n<p>\u521d\u59cb\u5316&#xff1a;\u5c06\u57fa\u7840\u8bcd\u8868\u5b9a\u4e49\u4e3a\u6240\u6709\u5355\u5b57\u8282\u5b57\u7b26&#xff08;0~255 \u7684 Byte&#xff09;\u53ca\u57fa\u7840\u7b26\u53f7\u3002<\/p>\n<\/li>\n<li>\n<p>\u7edf\u8ba1\u9891\u6b21&#xff1a;\u904d\u5386\u8bad\u7ec3\u8bed\u6599\u5e93&#xff0c;\u7edf\u8ba1\u6240\u6709\u76f8\u90bb\u5b57\u7b26\/\u5b50\u8bcd\u5bf9\u7684\u5171\u73b0\u9891\u6b21\u3002<\/p>\n<\/li>\n<li>\n<p>\u5408\u5e76\u6700\u9ad8\u9891\u5bf9&#xff1a;\u5c06\u51fa\u73b0\u9891\u7387\u6700\u9ad8\u7684\u5b50\u8bcd\u5bf9&#xff08;\u4f8b\u5982 (&#039;l&#039;, &#039;o&#039;)&#xff09;\u5408\u5e76\u4e3a\u65b0\u7684\u8bcd\u5143&#xff08;&#039;lo&#039;&#xff09;&#xff0c;\u5e76\u5c06\u5176\u52a0\u5165\u8bcd\u8868\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fed\u4ee3\u5faa\u73af&#xff1a;\u91cd\u590d\u4e0a\u8ff0\u7edf\u8ba1\u4e0e\u5408\u5e76\u8fc7\u7a0b&#xff0c;\u76f4\u5230\u8bcd\u8868\u5927\u5c0f\u8fbe\u5230\u9884\u8bbe\u76ee\u6807&#xff08;\u5982 32,000 \u6216 128,256&#xff09;\u3002<\/p>\n<\/li>\n<p># \u6781\u7b80 BPE \u5408\u5e76\u903b\u8f91\u5b9e\u73b0\u793a\u4f8b<br \/>\nimport collections<\/p>\n<p>def get_stats(vocab):<br \/>\n    pairs &#061; collections.defaultdict(int)<br \/>\n    for word, freq in vocab.items():<br \/>\n        symbols &#061; word.split()<br \/>\n        for i in range(len(symbols) &#8211; 1):<br \/>\n            pairs[symbols[i], symbols[i&#043;1]] &#043;&#061; freq<br \/>\n    return pairs<\/p>\n<p>def merge_vocab(pair, v_in):<br \/>\n    v_out &#061; {}<br \/>\n    bigram &#061; &#039; &#039;.join(pair)<br \/>\n    replacement &#061; &#039;&#039;.join(pair)<br \/>\n    for word in v_in:<br \/>\n        w_out &#061; word.replace(bigram, replacement)<br \/>\n        v_out[w_out] &#061; v_in[word]<br \/>\n    return v_out<\/p>\n<p># \u6a21\u62df\u8bcd\u9891\u8bed\u6599<br \/>\nvocab &#061; {&#039;l o w &lt;\/w&gt;&#039;: 5, &#039;l o w e r &lt;\/w&gt;&#039;: 2, &#039;n e w e s t &lt;\/w&gt;&#039;: 6, &#039;w i d e s t &lt;\/w&gt;&#039;: 3}<br \/>\npairs &#061; get_stats(vocab)<br \/>\nbest_pair &#061; max(pairs, key&#061;pairs.get)<br \/>\nvocab &#061; merge_vocab(best_pair, vocab)<br \/>\nprint(f&#034;\u6700\u9ad8\u9891\u5408\u5e76\u5bf9: {best_pair}&#034;)<\/p>\n<h4>2.3 Byte-fallback \u673a\u5236\u4e0e\u591a\u8bed\u8a00\u6548\u7387<\/h4>\n<p>\u5728\u5904\u7406\u751f\u50fb\u5b57\u7b26\u3001\u8868\u60c5\u7b26\u53f7&#xff08;Emoji&#xff09;\u6216\u591a\u8bed\u8a00\u6df7\u5408\u6587\u672c\u65f6&#xff0c;\u4f20\u7edf\u5206\u8bcd\u5668\u5bb9\u6613\u751f\u6210\u65e0\u6cd5\u8bc6\u522b\u7684 &lt;UNK&gt; \u7b26\u53f7\u3002<\/p>\n<p>Byte-fallback \u7b56\u7565&#xff1a;\u5f53\u9047\u5230\u672a\u5728\u8bcd\u8868\u4e2d\u6536\u5f55\u7684\u7ec4\u5408\u65f6&#xff0c;\u5206\u8bcd\u5668\u76f4\u63a5\u5c06\u5176\u5206\u89e3\u4e3a\u5e95\u5c42\u7684 UTF-8 \u5355\u5b57\u8282\u5e8f\u5217&#xff08;\u5982 \\\\xe4\\\\xbd\\\\xa0&#xff09;\u3002\u8fd9\u4e00\u673a\u5236\u4fdd\u8bc1\u4e86\u8bcd\u8868\u7684\u7edd\u5bf9\u95ed\u5408&#xff0c;\u5f7b\u5e95\u6d88\u9664\u4e86 OOV \u73b0\u8c61\u3002<\/p>\n<p>\u8bcd\u8868\u5927\u5c0f\u5bf9\u6a21\u578b\u6027\u80fd\u6709\u76f4\u63a5\u5f71\u54cd&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8bcd\u8868\u8fc7\u5c0f&#xff08;\u5982 32K&#xff09;&#xff1a;\u540c\u4e00\u6bb5\u4e2d\u6587\u6587\u672c\u5207\u5206\u51fa\u7684 Token \u6570\u91cf\u504f\u591a&#xff0c;\u5bfc\u81f4\u6a21\u578b\u63a8\u7406\u65f6\u9700\u8981\u6267\u884c\u66f4\u591a\u6b65\u7684\u89e3\u7801&#xff0c;\u4e14\u957f\u6587\u672c\u4e0a\u4e0b\u6587\u5bb9\u7eb3\u7684\u5b9e\u9645\u4fe1\u606f\u91cf\u7f29\u6c34\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bcd\u8868\u8fc7\u5927&#xff08;\u5982 128K\/256K&#xff09;&#xff1a;\u867d\u7136\u538b\u7f29\u7387\u9ad8\u3001\u63a8\u7406\u6b65\u6570\u5c11&#xff0c;\u4f46 Embedding \u67e5\u627e\u5c42\u548c\u8f93\u51fa LM Head \u5206\u7c7b\u5c42\u7684\u663e\u5b58\u5f00\u9500\u4e0e\u53c2\u6570\u91cf\u663e\u8457\u589e\u52a0\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e09\u3001 \u57fa\u77f3\u67b6\u6784&#xff1a;Transformer Decoder-Only \u6df1\u5ea6\u89e3\u5256<\/h3>\n<p>\u73b0\u4ee3\u4e3b\u6d41\u5927\u8bed\u8a00\u6a21\u578b&#xff08;\u5982 GPT-4\u3001Llama 3\u3001DeepSeek\u3001Qwen&#xff09;\u5728\u9aa8\u5e72\u67b6\u6784\u4e0a\u9ad8\u5ea6\u4e00\u81f4&#xff0c;\u5747\u7531\u591a\u4e2a\u5806\u53e0\u7684 Transformer Decoder Block \u7ec4\u6210\u3002<\/p>\n<p>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502               \u5355\u4e2a Transformer Decoder \u5c42\u7ed3\u6784               \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u2502<br \/>\n                              \u25bc \u8f93\u5165\u5f20\u91cf X [Batch, SeqLen, HiddenDim]<br \/>\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                 \u2502       RMSNorm \u5f52\u4e00\u5316     \u2502<br \/>\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u25bc<br \/>\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                 \u2502  Q, K, V \u6295\u5f71 (\u542b RoPE)  \u2502<br \/>\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u25bc<br \/>\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                 \u2502 \u56e0\u679c\u6ce8\u610f\u529b\u673a\u5236 (GQA \/ MHA)\u2502<br \/>\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u25bc<br \/>\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                 \u2502    \u6b8b\u5dee\u8fde\u63a5 (Residual)   \u2502 \u25c4\u2500\u2500\u2500 (\u4e0e\u8f93\u5165 X \u76f8\u52a0)<br \/>\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u25bc<br \/>\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                 \u2502       RMSNorm \u5f52\u4e00\u5316     \u2502<br \/>\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u25bc<br \/>\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                 \u2502   SwiGLU \u524d\u9988\u524d\u5411\u7f51\u7edc    \u2502<br \/>\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u25bc<br \/>\n                 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                 \u2502    \u6b8b\u5dee\u8fde\u63a5 (Residual)   \u2502 \u25c4\u2500\u2500\u2500 (\u4e0e\u524d\u7ea7\u8f93\u51fa\u76f8\u52a0)<br \/>\n                 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                              \u25bc \u8f93\u51fa\u4f20\u9012\u7ed9\u4e0b\u4e00\u5c42<\/p>\n<h4>3.1 \u81ea\u6ce8\u610f\u529b\u673a\u5236&#xff08;Self-Attention&#xff09;\u4e0e\u56e0\u679c\u63a9\u7801<\/h4>\n<p>\u81ea\u6ce8\u610f\u529b\u673a\u5236\u7684\u6838\u5fc3\u662f\u8ba1\u7b97\u5e8f\u5217\u4e2d\u6bcf\u4e2a\u8bcd\u5143\u4e0e\u5176\u4ed6\u6240\u6709\u8bcd\u5143\u4e4b\u95f4\u7684\u76f8\u5173\u5ea6\u6743\u91cd\u3002<\/p>\n<p>\u8f93\u5165\u5411\u91cf\u7ecf\u8fc7\u4e09\u4e2a\u4e0d\u540c\u7684\u7ebf\u6027\u53d8\u6362\u77e9\u9635\u6620\u5c04&#xff0c;\u5206\u522b\u751f\u6210&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u67e5\u8be2\u77e9\u9635&#xff08;Query, Q&#xff09;&#xff1a;\u8868\u793a\u5f53\u524d\u8bcd\u5143\u5728\u5bfb\u627e\u4ec0\u4e48\u4fe1\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u952e\u77e9\u9635&#xff08;Key, K&#xff09;&#xff1a;\u8868\u793a\u5f53\u524d\u8bcd\u5143\u5305\u542b\u4ec0\u4e48\u7279\u5f81\u4ee5\u4f9b\u5339\u914d\u3002<\/p>\n<\/li>\n<li>\n<p>\u503c\u77e9\u9635&#xff08;Value, V&#xff09;&#xff1a;\u8868\u793a\u5f53\u524d\u8bcd\u5143\u5b9e\u9645\u627f\u8f7d\u7684\u5185\u5bb9\u8868\u5f81\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6807\u51c6\u7f29\u653e\u70b9\u79ef\u6ce8\u610f\u529b&#xff08;Scaled Dot-Product Attention&#xff09;\u8ba1\u7b97\u903b\u8f91&#xff1a;<\/p>\n<p>Attention(Q, K, V) &#061; Softmax( (Q \u00b7 K^T) \/ \u221ad_k &#043; M ) \u00b7 V<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>\n<p>d_k \u4e3a\u6ce8\u610f\u529b\u5934\u7ef4\u5ea6&#xff08;Head Dimension&#xff09;&#xff0c;\u9664\u4ee5 \u221ad_k \u662f\u4e3a\u4e86\u9632\u6b62\u9ad8\u7ef4\u5411\u91cf\u70b9\u79ef\u8fc7\u5927\u5bfc\u81f4 Softmax \u68af\u5ea6\u8fdb\u5165\u9971\u548c\u533a&#xff08;\u68af\u5ea6\u5f25\u6563&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>M \u4e3a\u56e0\u679c\u63a9\u7801\u77e9\u9635&#xff08;Causal Mask&#xff09;\u3002\u5728 Decoder-Only \u67b6\u6784\u4e2d&#xff0c;\u4e3a\u4e86\u4fdd\u8bc1\u65f6\u5e8f\u5355\u5411\u81ea\u56de\u5f52\u7279\u6027&#xff0c;\u5fc5\u987b\u5c06\u5f53\u524d\u4f4d\u7f6e t \u4e4b\u540e\u7684\u6240\u6709\u672a\u6765\u4f4d\u7f6e j &gt; t \u7684\u6ce8\u610f\u529b\u6743\u91cd\u8bbe\u7f6e\u4e3a\u8d1f\u65e0\u7a77\u5927&#xff08;-inf&#xff09;&#xff0c;\u7ecf\u8fc7 Softmax \u540e\u5176\u5bf9\u5e94\u6743\u91cd\u53d8\u4e3a 0&#xff0c;\u4ece\u800c\u9632\u6b62\u6a21\u578b\u201c\u770b\u5230\u672a\u6765\u7684\u7b54\u6848\u201d\u3002<\/p>\n<\/li>\n<\/ul>\n<p>import torch<br \/>\nimport torch.nn.functional as F<\/p>\n<p>def scaled_dot_product_attention(Q, K, V, mask&#061;None):<br \/>\n    &#034;&#034;&#034;<br \/>\n    Q, K, V \u5f62\u72b6: [batch_size, num_heads, seq_len, head_dim]<br \/>\n    &#034;&#034;&#034;<br \/>\n    d_k &#061; Q.size(-1)<br \/>\n    scores &#061; torch.matmul(Q, K.transpose(-2, -1)) \/ (d_k ** 0.5)<\/p>\n<p>    if mask is not None:<br \/>\n        # \u5c06\u63a9\u7801\u4e3a 0 \u7684\u672a\u6765\u4f4d\u7f6e\u586b\u5145\u4e3a\u8d1f\u65e0\u7a77<br \/>\n        scores &#061; scores.masked_fill(mask &#061;&#061; 0, float(&#039;-inf&#039;))<\/p>\n<p>    attention_weights &#061; F.softmax(scores, dim&#061;-1)<br \/>\n    output &#061; torch.matmul(attention_weights, V)<br \/>\n    return output, attention_weights<\/p>\n<h4>3.2 \u6ce8\u610f\u529b\u53d8\u4f53\u6f14\u8fdb&#xff1a;MHA \u2794 MQA \u2794 GQA<\/h4>\n<p>\u5728\u5927\u6a21\u578b\u63a8\u7406\u9636\u6bb5&#xff0c;\u4e3a\u4e86\u7f13\u5b58\u5386\u53f2\u4e0a\u4e0b\u6587&#xff0c;\u7cfb\u7edf\u9700\u8981\u5c06\u6240\u6709\u5386\u53f2 Token \u7684 K \u548c V \u5f20\u91cf\u4fdd\u5b58\u5728 GPU \u663e\u5b58\u4e2d&#xff08;\u5373 KV Cache&#xff09;\u3002\u968f\u7740\u5e76\u53d1\u8bf7\u6c42\u6570\u548c\u5e8f\u5217\u957f\u5ea6\u589e\u52a0&#xff0c;KV Cache \u4f1a\u5360\u7528\u5927\u91cf\u663e\u5b58&#xff0c;\u6210\u4e3a\u7cfb\u7edf\u5e76\u53d1\u74f6\u9888\u3002<\/p>\n<p>\u4e3a\u6b64&#xff0c;\u5de5\u4e1a\u754c\u5bf9\u4f20\u7edf\u7684\u6ce8\u610f\u529b\u673a\u5236\u8fdb\u884c\u4e86\u6301\u7eed\u4f18\u5316&#xff1a;<\/p>\n<p>\u3010MHA (\u591a\u5934\u6ce8\u610f\u529b)\u3011          \u3010GQA (\u5206\u7ec4\u67e5\u8be2\u6ce8\u610f\u529b)\u3011        \u3010MQA (\u591a\u67e5\u8be2\u6ce8\u610f\u529b)\u3011<br \/>\nQ \u5934: 8, KV \u5934: 8            Q \u5934: 8, KV \u5934: 2 (4\u7ec4\u5171\u4eab1\u5bf9)  Q \u5934: 8, KV \u5934: 1 (\u5168\u5c40\u5171\u4eab1\u5bf9)<\/p>\n<p>Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8     Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8     Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8<br \/>\n \u2502  \u2502  \u2502  \u2502  \u2502  \u2502  \u2502  \u2502      \u2572  \u2571  \u2572  \u2571  \u2572  \u2571  \u2572  \u2571       \u2572  \u2572  \u2502  \u2502  \u2502  \u2502  \u2571  \u2571<br \/>\nK1 K2 K3 K4 K5 K6 K7 K8        K1    K2    K3    K4                 KV1<br \/>\nV1 V2 V3 V4 V5 V6 V7 V8        V1    V2    V3    V4        (\u6240\u6709 Q \u5171\u4eab\u5355\u7ec4 KV)<br \/>\n(\u663e\u5b58\u6d88\u8017\u6700\u5927&#xff0c;\u8868\u8fbe\u529b\u6700\u5f3a)   (\u663e\u5b58\u4e0e\u6027\u80fd\u7684\u6700\u4f73\u5e73\u8861\u70b9)    (\u663e\u5b58\u6781\u4f4e&#xff0c;\u8868\u8fbe\u529b\u8f7b\u5fae\u4e0b\u964d)<\/p>\n<li>\n<p>MHA&#xff08;Multi-Head Attention&#xff09;&#xff1a;\u6bcf\u4e2a Query \u5934\u5bf9\u5e94\u4e00\u7ec4\u72ec\u7acb\u7684 Key \u548c Value \u5934\u3002KV Cache \u663e\u5b58\u5360\u7528\u6700\u9ad8\u3002<\/p>\n<\/li>\n<li>\n<p>MQA&#xff08;Multi-Query Attention&#xff09;&#xff1a;\u6240\u6709 Query \u5934\u5171\u4eab\u540c\u4e00\u7ec4 Key \u548c Value \u5934\u3002KV Cache \u663e\u5b58\u5360\u7528\u964d\u4f4e\u81f3 1 \/ num_heads&#xff0c;\u4f46\u53ef\u80fd\u4f1a\u5728\u590d\u6742\u4efb\u52a1\u4e2d\u635f\u5931\u4e00\u5b9a\u7684\u8868\u5f81\u7cbe\u5ea6\u3002<\/p>\n<\/li>\n<li>\n<p>GQA&#xff08;Grouped-Query Attention&#xff09;&#xff1a;\u6298\u4e2d\u65b9\u6848&#xff08;\u5982 Llama 3\u3001DeepSeek \u6240\u91c7\u7528&#xff09;\u3002\u5c06 Query \u5934\u5206\u4e3a\u82e5\u5e72\u7ec4&#xff08;\u5982 8 \u7ec4&#xff09;&#xff0c;\u6bcf\u7ec4\u5185\u7684 Query \u5934\u5171\u4eab\u4e00\u7ec4 Key \u548c Value \u5934\u3002\u5728\u4fdd\u6301\u63a5\u8fd1 MHA \u6a21\u578b\u8d28\u91cf\u7684\u540c\u65f6&#xff0c;\u5c06 KV Cache \u663e\u5b58\u5360\u7528\u964d\u4f4e\u6570\u500d\u3002<\/p>\n<\/li>\n<h4>3.3 \u65cb\u8f6c\u4f4d\u7f6e\u7f16\u7801&#xff08;RoPE, Rotary Position Embedding&#xff09;<\/h4>\n<p>Transformer \u5185\u90e8\u7684\u6ce8\u610f\u529b\u8ba1\u7b97\u5177\u6709\u7f6e\u6362\u4e0d\u53d8\u6027&#xff08;Permutation Invariance&#xff09;&#xff0c;\u56e0\u6b64\u5fc5\u987b\u5411\u8bcd\u5411\u91cf\u4e2d\u6ce8\u5165\u4f4d\u7f6e\u7f16\u7801&#xff08;Positional Encoding&#xff09;\u3002<\/p>\n<p>\u65e9\u671f\u7684\u7edd\u5bf9\u4f4d\u7f6e\u7f16\u7801&#xff08;\u5982\u53ef\u5b66\u4e60\u4f4d\u7f6e\u5411\u91cf\u3001\u6b63\u4f59\u5f26\u9759\u6001\u7f16\u7801&#xff09;\u5728\u5904\u7406\u8d85\u51fa\u8bad\u7ec3\u957f\u5ea6\u7684\u5916\u63a8\u65f6\u8868\u73b0\u4e0d\u4f73\u3002\u5f53\u524d\u884c\u4e1a\u666e\u904d\u91c7\u7528 Su \u7b49\u4eba\u63d0\u51fa\u7684 RoPE&#xff08;\u65cb\u8f6c\u4f4d\u7f6e\u7f16\u7801&#xff09;\u3002<\/p>\n<p>RoPE \u7684\u6838\u5fc3\u601d\u60f3&#xff1a;\u901a\u8fc7\u7edd\u5bf9\u4f4d\u7f6e\u7f16\u7801\u7684\u5f62\u5f0f&#xff0c;\u5b9e\u73b0\u76f8\u5bf9\u4f4d\u7f6e\u7f16\u7801\u7684\u6548\u679c\u3002<\/p>\n<p>\u5728\u4e8c\u7ef4\u5e73\u9762\u4e0a&#xff0c;\u5bf9\u4e8e\u4f4d\u4e8e\u4f4d\u7f6e m \u7684\u5411\u91cf x &#061; (x_1, x_2)&#xff0c;\u5c06\u5176\u4e58\u4ee5\u4e00\u4e2a\u65cb\u8f6c\u6b63\u4ea4\u77e9\u9635&#xff1a;<\/p>\n<p>R_\u03b8,m &#061; | cos(m\u03b8)  -sin(m\u03b8) |<br \/>\n        | sin(m\u03b8)   cos(m\u03b8) |<\/p>\n<p>\u5f53\u8ba1\u7b97\u4f4d\u7f6e m \u7684 Query \u5411\u91cf\u4e0e\u4f4d\u7f6e n \u7684 Key \u5411\u91cf\u7684\u70b9\u79ef\u65f6&#xff0c;\u4e24\u8005\u7684\u5185\u79ef\u7ed3\u679c\u4ec5\u53d6\u51b3\u4e8e\u76f8\u5bf9\u4f4d\u7f6e\u5dee\u503c m &#8211; n&#xff1a;<\/p>\n<p>&lt; R_\u03b8,m \u00b7 Q,  R_\u03b8,n \u00b7 K &gt; &#061; Q^T \u00b7 R_\u03b8,(n &#8211; m) \u00b7 K<\/p>\n<p>RoPE \u5177\u5907\u81ea\u7136\u7684\u8870\u51cf\u7279\u6027&#xff08;\u76f8\u5bf9\u8ddd\u79bb\u8d8a\u8fdc&#xff0c;\u5185\u79ef\u671f\u671b\u503c\u8d8a\u5c0f&#xff09;&#xff0c;\u5e76\u4e14\u4fbf\u4e8e\u901a\u8fc7\u63d2\u503c&#xff08;Linear Interpolation\u3001NTK-Aware Scaling\u3001YaRN&#xff09;\u5c06\u4e0a\u4e0b\u6587\u7a97\u53e3\u6269\u5c55\u81f3 32K\u3001128K \u4e43\u81f3 1M\u3002<\/p>\n<h4>3.4 \u5f52\u4e00\u5316\u4e0e\u6fc0\u6d3b\u51fd\u6570\u4f18\u5316<\/h4>\n<p>\u73b0\u4ee3 LLM \u5728\u7ecf\u5178 Transformer \u7ed3\u6784\u57fa\u7840\u4e0a\u8fdb\u884c\u4e86\u4e24\u4e2a\u5173\u952e\u7684\u57fa\u7840\u7ec4\u4ef6\u66ff\u6362&#xff1a;<\/p>\n<h5>1. RMSNorm&#xff08;Root Mean Square Normalization&#xff09;<\/h5>\n<p>\u4f20\u7edf\u7684 LayerNorm \u9700\u8981\u8ba1\u7b97\u5747\u503c&#xff08;Mean&#xff09;\u548c\u65b9\u5dee&#xff08;Variance&#xff09;\u4e24\u4e2a\u7edf\u8ba1\u91cf\u3002\u7814\u7a76\u8868\u660e&#xff0c;LayerNorm \u7684\u6838\u5fc3\u7f29\u653e\u7279\u6027\u6765\u81ea\u4e8e\u5747\u65b9\u6839&#xff0c;\u5747\u503c\u4e2d\u5fc3\u5316\u5bf9\u6a21\u578b\u7a33\u5b9a\u6027\u7684\u8d21\u732e\u5fae\u4e4e\u5176\u5fae\u3002<\/p>\n<p>RMSNorm \u8ba1\u7b97\u516c\u5f0f&#xff1a;<\/p>\n<p>RMS(x) &#061; sqrt( (1 \/ d) * \u2211 [i&#061;1 \u5230 d] (x_i)^2 &#043; \u03b5 )<br \/>\ny &#061; (x \/ RMS(x)) * \u03b3<\/p>\n<p>\u53bb\u9664\u4e86\u5747\u503c\u8ba1\u7b97\u540e&#xff0c;RMSNorm \u5c06\u8bad\u7ec3\u4e0e\u63a8\u7406\u901f\u5ea6\u63d0\u5347\u4e86 10%~50%&#xff0c;\u4e14\u6570\u503c\u7a33\u5b9a\u6027\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<h5>2. SwiGLU \u6fc0\u6d3b\u51fd\u6570<\/h5>\n<p>\u4f20\u7edf\u7684 FFN&#xff08;\u524d\u9988\u5168\u8fde\u63a5\u5c42&#xff09;\u91c7\u7528 ReLU \u6216 GELU\u3002\u73b0\u4ee3 LLM \u5e7f\u6cdb\u91c7\u7528 SwiGLU&#xff08;Swish Gated Linear Unit&#xff09; \u95e8\u63a7\u7ebf\u6027\u5355\u5143\u67b6\u6784&#xff1a;<\/p>\n<p>SwiGLU(x) &#061; ( x \u00b7 W_gate * Sigmoid(x \u00b7 W_gate * \u03b2) ) \u2297 ( x \u00b7 W_up ) \u00b7 W_down<\/p>\n<p>\u5f15\u5165\u95e8\u63a7\u673a\u5236\u540e&#xff0c;\u6a21\u578b\u53c2\u6570\u7684\u8868\u8fbe\u5bb9\u91cf\u663e\u8457\u63d0\u5347&#xff0c;\u5728\u76f8\u540c\u53c2\u6570\u89c4\u6a21\u4e0b\u6536\u655b\u901f\u5ea6\u66f4\u5feb\u3001\u4e0b\u6e38\u6307\u6807\u8868\u73b0\u66f4\u4f18\u3002<\/p>\n<h3>\u56db\u3001 \u5927\u6a21\u578b\u7684\u5b8c\u6574\u8bad\u7ec3\u6d41\u6c34\u7ebf<\/h3>\n<p>\u4ece\u96f6\u6784\u5efa\u4e00\u4e2a\u53ef\u5546\u7528\u7684\u5927\u6a21\u578b&#xff0c;\u5fc5\u987b\u7ecf\u5386\u4e25\u683c\u7684\u4e09\u9636\u6bb5\u751f\u547d\u5468\u671f\u3002<\/p>\n<p>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502                        \u5927\u6a21\u578b\u4e09\u9636\u6bb5\u8bad\u7ec3\u5168\u666f\u8def\u7ebf\u56fe                      \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                                    \u2502<br \/>\n 1. \u9884\u8bad\u7ec3\u9636\u6bb5 (Pre-training)       \u6d77\u91cf\u65e0\u6807\u6ce8\u6587\u672c \u2794 \u81ea\u76d1\u7763\u9884\u6d4b\u4e0b\u4e00\u4e2a\u8bcd \u2794 \u57fa\u5ea7\u6a21\u578b (Base Model)<br \/>\n                                    \u2502 (\u6d88\u8017 95% \u4ee5\u4e0a\u7684\u603b\u7b97\u529b\u4e0e\u6570\u636e)<br \/>\n                                    \u25bc<br \/>\n 2. \u76d1\u7763\u5fae\u8c03\u9636\u6bb5 (SFT)              \u9ad8\u8d28\u91cf\u6307\u4ee4\u95ee\u7b54\u5bf9 \u2794 \u5b66\u4e60\u95ee\u7b54\u5bf9\u8bdd\u8303\u5f0f \u2794 \u6307\u4ee4\u6a21\u578b (Instruct Model)<br \/>\n                                    \u2502 (\u6570\u636e\u91cf\u901a\u5e38\u5728 10\u4e07 ~ \u767e\u4e07\u7ea7\u9ad8\u8d28\u91cf\u5bf9)<br \/>\n                                    \u25bc<br \/>\n 3. \u4eba\u7c7b\u504f\u597d\u5bf9\u9f50 (RLHF \/ DPO)       \u4eba\u7c7b\u504f\u597d\u6253\u5206 \u2794 \u5f3a\u5316\u5b66\u4e60\/\u76f4\u63a5\u504f\u597d\u4f18\u5316 \u2794 \u5b89\u5168\u5bf9\u9f50\u6a21\u578b (Chat Model)<br \/>\n                                      (\u6291\u5236\u6709\u5bb3\u8a00\u8bba\u3001\u51cf\u5c11\u5e7b\u89c9\u3001\u5bf9\u9f50\u4eba\u7c7b\u4ef7\u503c\u89c2)<\/p>\n<h4>4.1 \u7b2c\u4e00\u9636\u6bb5&#xff1a;\u6d77\u91cf\u6570\u636e\u9884\u8bad\u7ec3&#xff08;Pre-training&#xff09;<\/h4>\n<p>\u9884\u8bad\u7ec3\u662f\u5927\u6a21\u578b\u83b7\u53d6\u901a\u7528\u8bed\u8a00\u7406\u89e3\u80fd\u529b\u3001\u903b\u8f91\u7ed3\u6784\u4e0e\u4e16\u754c\u5e38\u8bc6\u7684\u6700\u6838\u5fc3\u9636\u6bb5\u3002<\/p>\n<h5>1. \u6570\u636e\u5de5\u7a0b\u6d41\u6c34\u7ebf&#xff08;Data Pipeline&#xff09;<\/h5>\n<p>\u9ad8\u8d28\u91cf\u7684\u8bed\u6599\u6570\u636e\u662f\u5927\u6a21\u578b\u6027\u80fd\u7684\u51b3\u5b9a\u6027\u56e0\u7d20\u3002\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5904\u7406\u6b65\u9aa4&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6570\u636e\u6536\u96c6&#xff1a;\u6293\u53d6\u7f51\u9875&#xff08;Common Crawl&#xff09;\u3001\u6743\u5a01\u56fe\u4e66\u3001\u5b66\u672f\u671f\u520a\u8bba\u6587&#xff08;arXiv&#xff09;\u3001\u5f00\u6e90\u4ee3\u7801\u4ed3\u5e93&#xff08;GitHub&#xff09;\u3001\u767e\u79d1\u8bcd\u6761\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u6587\u672c\u6e05\u6d17\u4e0e\u683c\u5f0f\u63d0\u53d6&#xff1a;\u53bb\u9664 HTML \u6807\u7b7e\u3001\u8fc7\u6ee4\u65e0\u610f\u4e49\u5b57\u7b26\u4e0e\u4f4e\u8d28\u5e7f\u544a\u6587\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5927\u89c4\u6a21\u53bb\u91cd&#xff08;Deduplication&#xff09;&#xff1a;\u5229\u7528 MinHash LSH \u6216 Exact Substring Matching \u7b97\u6cd5\u53bb\u9664\u91cd\u590d\u7f51\u9875&#xff0c;\u907f\u514d\u6a21\u578b\u6b7b\u8bb0\u786c\u80cc\u91cd\u590d\u6587\u672c&#xff0c;\u63d0\u5347\u6cdb\u5316\u80fd\u529b\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b89\u5168\u8fc7\u6ee4\u4e0e\u9690\u79c1\u64e6\u9664&#xff1a;\u8fc7\u6ee4\u6d89\u9ec4\u3001\u66b4\u529b\u8a00\u8bba&#xff0c;\u8131\u654f\u8eab\u4efd\u8bc1\u3001\u4fe1\u7528\u5361\u3001\u624b\u673a\u53f7\u7b49 PII \u9690\u79c1\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>2. \u8bad\u7ec3\u76ee\u6807\u4e0e\u635f\u5931\u51fd\u6570<\/h5>\n<p>\u9884\u8bad\u7ec3\u9636\u6bb5\u91c7\u7528\u81ea\u76d1\u7763\u7684\u81ea\u56de\u5f52\u4ea4\u53c9\u71b5\u635f\u5931\u51fd\u6570&#xff08;Cross-Entropy Loss&#xff09;\u3002\u8bbe\u8bcd\u8868\u5927\u5c0f\u4e3a V&#xff0c;\u771f\u5b9e\u4e0b\u4e00\u4e2a Token \u7684\u72ec\u70ed\u7f16\u7801\u4e3a y_t&#xff0c;\u6a21\u578b\u9884\u6d4b\u6982\u7387\u5206\u5e03\u4e3a p_t&#xff1a;<\/p>\n<p>Loss &#061; &#8211; (1 \/ T) * \u2211 [t&#061;1 \u5230 T] log( p_t(w_t) )<\/p>\n<h5>3. \u5206\u5e03\u5f0f\u5e76\u884c\u8bad\u7ec3\u7b56\u7565<\/h5>\n<p>\u5f53\u6a21\u578b\u53c2\u6570\u91cf\u8fbe\u5230 70B \u751a\u81f3\u66f4\u5927\u65f6&#xff0c;\u5355\u4e2a GPU \u663e\u5b58&#xff08;\u5982 A100\/H100 80GB&#xff09;\u5b8c\u5168\u65e0\u6cd5\u5bb9\u7eb3\u6a21\u578b\u53c2\u6570\u3001\u68af\u5ea6\u53ca\u4f18\u5316\u5668\u72b6\u6001&#xff08;AdamW \u4f18\u5316\u5668\u6bcf\u4e2a\u53c2\u6570\u9700\u5360\u7528 16 \u5b57\u8282\u663e\u5b58&#xff09;\u3002\u5fc5\u987b\u7ec4\u5408\u4f7f\u7528\u591a\u79cd\u5206\u5e03\u5f0f\u5e76\u884c\u6280\u672f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6570\u636e\u5e76\u884c&#xff08;DDP \/ ZeRO&#xff09;&#xff1a;ZeRO&#xff08;Zero Redundancy Optimizer&#xff09;\u6280\u672f\u5c06\u4f18\u5316\u5668\u72b6\u6001&#xff08;ZeRO-1&#xff09;\u3001\u68af\u5ea6&#xff08;ZeRO-2&#xff09;\u548c\u6a21\u578b\u53c2\u6570&#xff08;ZeRO-3&#xff09;\u5206\u7247\u5207\u5206\u5b58\u50a8\u4e8e\u5404\u4e2a GPU \u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f20\u91cf\u5e76\u884c&#xff08;Tensor Parallelism, TP&#xff09;&#xff1a;\u5728\u5355\u4e2a\u7b97\u5b50\u5185\u90e8&#xff08;\u5982\u5c06\u77e9\u9635\u4e58\u6cd5 Y &#061; X \u00b7 W \u6309\u5217\u6216\u6309\u884c\u5207\u5206&#xff09;\u8fdb\u884c\u5206\u5e03\u5f0f\u8ba1\u7b97&#xff08;Megatron-LM \u67b6\u6784&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u6d41\u6c34\u7ebf\u5e76\u884c&#xff08;Pipeline Parallelism, PP&#xff09;&#xff1a;\u5c06\u6a21\u578b\u7684\u4e0d\u540c\u5c42&#xff08;Layer&#xff09;\u6309\u987a\u5e8f\u5206\u914d\u5230\u4e0d\u540c GPU \u4e0a\u6d41\u6c34\u7ebf\u6267\u884c\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>4.2 \u7b2c\u4e8c\u9636\u6bb5&#xff1a;\u76d1\u7763\u6307\u4ee4\u5fae\u8c03&#xff08;SFT, Supervised Fine-Tuning&#xff09;<\/h4>\n<p>\u7ecf\u8fc7\u9884\u8bad\u7ec3\u7684\u57fa\u5ea7\u6a21\u578b&#xff08;Base Model&#xff09;\u53ea\u5177\u5907\u201c\u6587\u5b57\u7eed\u5199\u201d\u80fd\u529b&#xff0c;\u4e0d\u7406\u89e3\u4eba\u7c7b\u7684\u201c\u63d0\u95ee-\u56de\u7b54\u201d\u6307\u4ee4\u4ea4\u4e92\u6a21\u5f0f\u3002<\/p>\n<p>SFT \u9636\u6bb5\u4f7f\u7528\u4eba\u5de5\u6807\u6ce8\u6216\u5927\u6a21\u578b\u5408\u6210\u7684\u9ad8\u8d28\u91cf\u683c\u5f0f\u6570\u636e (Instruction, Input, Response)&#xff0c;\u5728\u4fdd\u6301\u9884\u8bad\u7ec3\u6a21\u578b\u6743\u91cd\u57fa\u7840\u7684\u524d\u63d0\u4e0b&#xff0c;\u8ba9\u6a21\u578b\u5b66\u4f1a\u7406\u89e3\u6307\u4ee4\u3001\u9075\u5faa\u683c\u5f0f\u7ea6\u675f\u5e76\u626e\u6f14\u7279\u5b9a\u52a9\u624b\u89d2\u8272\u3002<\/p>\n<h5>\u53c2\u6570\u9ad8\u6548\u5fae\u8c03&#xff08;PEFT \/ LoRA&#xff09;<\/h5>\n<p>\u5728\u4f01\u4e1a\u843d\u5730\u573a\u666f\u4e2d&#xff0c;\u5168\u91cf\u53c2\u6570\u5fae\u8c03&#xff08;Full Fine-Tuning&#xff09;\u6210\u672c\u6781\u9ad8\u3002Edward Hu \u7b49\u4eba\u63d0\u51fa\u7684 LoRA&#xff08;Low-Rank Adaptation&#xff09; \u662f\u76ee\u524d\u6700\u5e7f\u6cdb\u91c7\u7528\u7684\u9ad8\u6548\u5fae\u8c03\u6280\u672f\u3002<\/p>\n<p>LoRA \u6838\u5fc3\u539f\u7406&#xff1a;\u5047\u5b9a\u6a21\u578b\u6743\u91cd\u5728\u7279\u5b9a\u4efb\u52a1\u9002\u5e94\u8fc7\u7a0b\u4e2d\u7684\u53c2\u6570\u66f4\u65b0\u91cf\u77e9\u9635 \u0394W \u5177\u6709\u6781\u4f4e\u7684\u201c\u5185\u5728\u79e9&#xff08;Intrinsic Rank&#xff09;\u201d\u3002<\/p>\n<p>\u5bf9\u4e8e\u539f\u59cb\u9884\u8bad\u7ec3\u51bb\u7ed3\u6743\u91cd W_0 (d \u00d7 k)&#xff0c;\u5c06\u5176\u66f4\u65b0\u91cf\u5206\u89e3\u4e3a\u4e24\u4e2a\u4f4e\u79e9\u77e9\u9635\u7684\u4e58\u79ef&#xff1a;<\/p>\n<p>W &#061; W_0 &#043; \u0394W &#061; W_0 &#043; (B \u00b7 A) * (\u03b1 \/ r)<\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u77e9\u9635 A \u7684\u7ef4\u5ea6\u4e3a r \u00d7 k&#xff0c;\u91c7\u7528\u9ad8\u65af\u5206\u5e03\u521d\u59cb\u5316&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u77e9\u9635 B \u7684\u7ef4\u5ea6\u4e3a d \u00d7 r&#xff0c;\u521d\u59cb\u5316\u4e3a\u5168 0&#xff1b;<\/p>\n<\/li>\n<li>\n<p>r \u4e3a\u8bbe\u5b9a\u7684\u79e9&#xff08;Rank&#xff0c;\u901a\u5e38\u8bbe\u4e3a 8\u300116\u300164&#xff0c;\u4e14 r &lt;&lt; min(d, k)&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u03b1 \u4e3a\u7f29\u653e\u56e0\u5b50\u5e38\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8f93\u5165 X<br \/>\n  \u251c\u2500\u2500\u25ba [ \u51bb\u7ed3\u7684\u539f\u59cb\u9884\u8bad\u7ec3\u6743\u91cd W_0 (d \u00d7 k) ] \u2500\u2500\u2500\u25ba \u8f93\u51fa Y_base \u2500\u2500\u2510<br \/>\n  \u2502                                                            \u251c\u2500\u2500\u25ba \u6700\u7ec8\u8f93\u51fa Y &#061; Y_base &#043; Y_lora<br \/>\n  \u2514\u2500\u2500\u25ba [ \u964d\u7ef4\u77e9\u9635 A (r \u00d7 k) ] \u2500\u2500\u25ba [ \u5347\u7ef4\u77e9\u9635 B (d \u00d7 r) ] \u2500\u2500\u25ba Y_lora \u2500\u2500\u2518<br \/>\n       (\u4ec5\u8bad\u7ec3\u53ef\u5b66\u4e60\u7684 A \u548c B&#xff0c;\u53c2\u6570\u91cf\u4ec5\u5360\u539f\u6a21\u578b\u7684 0.1%~1%)<\/p>\n<p>LoRA \u7684\u6838\u5fc3\u4f18\u52bf&#xff1a;\u8bad\u7ec3\u65f6\u65e0\u9700\u66f4\u65b0\u6d77\u91cf\u539f\u53c2\u6570&#xff0c;\u4ec5\u4fdd\u5b58\u5fae\u5c0f\u4f53\u79ef\u7684 Adapter \u6743\u91cd\u6743\u91cd\u6587\u4ef6&#xff08;\u901a\u5e38\u51e0\u5341\u5146\u5b57\u8282&#xff09;&#xff0c;\u4e14\u5728\u63a8\u7406\u9636\u6bb5\u53ef\u76f4\u63a5\u901a\u8fc7\u77e9\u9635\u52a0\u6cd5\u5408\u5e76\u56de\u539f\u59cb\u6743\u91cd W &#061; W_0 &#043; B \u00b7 A&#xff0c;\u4e0d\u589e\u52a0\u4efb\u4f55\u7ebf\u4e0a\u63a8\u7406\u5ef6\u8fdf\u3002<\/p>\n<h4>4.3 \u7b2c\u4e09\u9636\u6bb5&#xff1a;\u4eba\u7c7b\u504f\u597d\u5bf9\u9f50&#xff08;Alignment: RLHF \u4e0e DPO&#xff09;<\/h4>\n<p>\u5fae\u8c03\u540e\u7684\u6a21\u578b\u867d\u7136\u80fd\u56de\u7b54\u95ee\u9898&#xff0c;\u4f46\u53ef\u80fd\u8f93\u51fa\u5305\u542b\u865a\u5047\u5e7b\u89c9\u3001\u5371\u9669\u653b\u51fb\u6027\u8a00\u8bba\u6216\u8fdd\u80cc\u4eba\u7c7b\u4f26\u7406\u7684\u5185\u5bb9\u3002\u5bf9\u9f50\u6280\u672f\u7684\u76ee\u6807\u662f\u8ba9\u6a21\u578b\u8f93\u51fa\u7b26\u5408 3H \u6807\u51c6&#xff08;Helpful \u6709\u7528\u3001Honest \u8bda\u5b9e\u3001Harmless \u65e0\u5bb3&#xff09;\u3002<\/p>\n<h5>1. RLHF&#xff08;\u57fa\u4e8e\u4eba\u7c7b\u53cd\u9988\u7684\u5f3a\u5316\u5b66\u4e60&#xff09;\u7ecf\u5178\u4e09\u6b65\u6cd5<\/h5>\n<ul>\n<li>\n<p>\u7b2c\u4e00\u6b65&#xff1a;\u6536\u96c6\u63d0\u793a\u8bcd&#xff0c;\u7531\u6a21\u578b\u751f\u6210\u591a\u4e2a\u5019\u9009\u8f93\u51fa&#xff0c;\u4eba\u7c7b\u6807\u6ce8\u5458\u5bf9\u5019\u9009\u7b54\u6848\u6309\u8d28\u91cf\u8fdb\u884c\u6392\u5e8f\u6253\u5206\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e8c\u6b65&#xff1a;\u4f7f\u7528\u6392\u5e8f\u6570\u636e\u8bad\u7ec3\u4e00\u4e2a\u5956\u52b1\u6a21\u578b&#xff08;Reward Model, RM&#xff09;&#xff0c;\u8be5\u6a21\u578b\u8f93\u5165\u4e00\u6bb5\u95ee\u7b54&#xff0c;\u8f93\u51fa\u4e00\u4e2a\u6807\u91cf\u5206\u6570\u503c&#xff0c;\u7528\u4ee5\u6a21\u62df\u4eba\u7c7b\u7684\u8bc4\u5206\u6807\u51c6\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e09\u6b65&#xff1a;\u4f7f\u7528 PPO&#xff08;Proximal Policy Optimization&#xff09; \u5f3a\u5316\u5b66\u4e60\u7b97\u6cd5&#xff0c;\u5c06 LLM \u89c6\u4f5c\u7b56\u7565&#xff08;Policy&#xff09;&#xff0c;\u4ee5\u5956\u52b1\u6a21\u578b\u5f97\u5206\u6700\u9ad8\u4e3a\u76ee\u6807\u8fdb\u884c\u8fed\u4ee3\u66f4\u65b0&#xff0c;\u540c\u65f6\u5f15\u5165 KL \u6563\u5ea6\u60e9\u7f5a\u9879\u9632\u6b62\u6a21\u578b\u504f\u79bb\u539f\u59cb SFT \u6a21\u578b\u8fc7\u8fdc\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>2. DPO&#xff08;Direct Preference Optimization&#xff0c;\u76f4\u63a5\u504f\u597d\u4f18\u5316&#xff09;<\/h5>\n<p>\u7531\u4e8e RLHF \u9700\u8981\u540c\u65f6\u7ef4\u62a4 SFT \u6a21\u578b\u3001Actor \u6a21\u578b\u3001Critic \u6a21\u578b\u3001Reference \u6a21\u578b\u4ee5\u53ca Reward \u6a21\u578b&#xff0c;\u663e\u5b58\u5f00\u9500\u6781\u5927\u4e14\u5f3a\u5316\u5b66\u4e60\u8bad\u7ec3\u8fc7\u7a0b\u6781\u5176\u654f\u611f\u8106\u5f31\u3002<\/p>\n<p>Rafailov \u7b49\u4eba\u63d0\u51fa\u7684 DPO \u7b97\u6cd5\u901a\u8fc7\u6570\u5b66\u63a8\u5bfc\u8bc1\u660e&#xff1a;\u53ef\u4ee5\u7ed5\u8fc7\u663e\u5f0f\u8bad\u7ec3\u72ec\u7acb\u5956\u52b1\u6a21\u578b\u7684\u6b65\u9aa4&#xff0c;\u76f4\u63a5\u5229\u7528\u504f\u597d\u6570\u636e\u5bf9 (x, y_w, y_l)&#xff08;y_w \u4e3a\u4eba\u7c7b\u504f\u597d\u80dc\u51fa\u7b54\u6848&#xff0c;y_l \u4e3a\u4eba\u7c7b\u62d2\u7edd\u52a3\u8d28\u7b54\u6848&#xff09;\u4f18\u5316\u7b56\u7565\u6a21\u578b\u3002<\/p>\n<p>DPO \u635f\u5931\u51fd\u6570\u5f62\u5f0f&#xff1a;<\/p>\n<p>Loss_DPO &#061; &#8211; E [ log( Sigmoid( \u03b2 * log( \u03c0_\u03b8(y_w | x) \/ \u03c0_ref(y_w | x) ) &#8211; \u03b2 * log( \u03c0_\u03b8(y_l | x) \/ \u03c0_ref(y_l | x) ) ) ) ]<\/p>\n<p>DPO \u5927\u5e45\u7b80\u5316\u4e86\u5bf9\u9f50\u6d41\u6c34\u7ebf&#xff0c;\u5177\u5907\u66f4\u5f3a\u7684\u6536\u655b\u7a33\u5b9a\u6027\u4e0e\u8bad\u7ec3\u6548\u7387&#xff0c;\u5df2\u6210\u4e3a\u5f53\u524d\u5f00\u6e90\u5927\u6a21\u578b\u5bf9\u9f50\u7684\u4e3b\u6d41\u65b9\u6848\u3002<\/p>\n<h3>\u4e94\u3001 \u63a8\u7406\u91c7\u6837\u4e0e\u89e3\u7801\u7b56\u7565&#xff08;Decoding Strategies&#xff09;<\/h3>\n<p>\u5f53\u6a21\u578b\u8ba1\u7b97\u51fa\u4e0b\u4e00\u4e2a Token \u7684\u6982\u7387\u5206\u5e03\u5411\u91cf\u540e&#xff0c;\u89e3\u7801\u5668\u5fc5\u987b\u4f9d\u636e\u7279\u5b9a\u7684\u91c7\u6837\u7b56\u7565\u9009\u51fa\u6700\u7ec8\u8f93\u51fa\u7684 Token\u3002\u4e0d\u540c\u7684\u7b56\u7565\u76f4\u63a5\u51b3\u5b9a\u4e86\u8f93\u51fa\u6587\u672c\u7684\u903b\u8f91\u786e\u5b9a\u6027\u4e0e\u521b\u9020\u6027\u3002<\/p>\n<p>\u6a21\u578b\u8f93\u51fa Logits \u2500\u2500\u25ba \u6e29\u5ea6\u7f29\u653e (Temperature) \u2500\u2500\u25ba Top-K \/ Top-P \u622a\u65ad\u8fc7\u6ee4 \u2500\u2500\u25ba Softmax \u91c7\u6837 \u2500\u2500\u25ba \u8f93\u51fa\u6700\u7ec8 Token<\/p>\n<h4>5.1 \u91c7\u6837\u63a7\u5236\u53c2\u6570\u8be6\u89e3<\/h4>\n<li>\n<p>Greedy Search&#xff08;\u8d2a\u5a6a\u641c\u7d22&#xff09;&#xff1a;\u6bcf\u4e00\u6b65\u5747\u5f3a\u5236\u9009\u53d6\u6982\u7387\u6700\u9ad8\u7684\u5355\u4e2a Token&#xff08;argmax P(w_t)&#xff09;\u3002\u8f93\u51fa\u5b8c\u5168\u786e\u5b9a\u3001\u53ef\u590d\u73b0&#xff0c;\u4f46\u5728\u957f\u6587\u672c\u751f\u6210\u4e2d\u5bb9\u6613\u9677\u5165\u5c40\u90e8\u6700\u4f18\u548c\u6b7b\u5faa\u73af\u91cd\u590d\u3002<\/p>\n<\/li>\n<li>\n<p>Temperature&#xff08;\u91c7\u6837\u6e29\u5ea6 T&#xff09;&#xff1a;\u5728\u6267\u884c Softmax \u4e4b\u524d\u5bf9\u672a\u5f52\u4e00\u5316\u7684 Logits z_i \u8fdb\u884c\u5e73\u7f29\u653e&#xff1a;<\/p>\n<p>\u00a0<\/p>\n<p>P(w_i) &#061; exp(z_i \/ T) \/ \u2211_j exp(z_j \/ T)<\/p>\n<ul>\n<li>\n<p>\u5f53 T -&gt; 0 \u65f6&#xff1a;\u6781\u5927\u503c\u88ab\u65e0\u9650\u653e\u5927&#xff0c;\u6982\u7387\u5206\u5e03\u9000\u5316\u4e3a Dirac delta \u51fd\u6570&#xff0c;\u7b49\u4ef7\u4e8e\u8d2a\u5a6a\u641c\u7d22&#xff08;\u9002\u7528\u4e8e\u4ee3\u7801\u3001\u6570\u5b66\u63a8\u7406&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f53 T &gt; 1.0 \u65f6&#xff1a;\u9ad8\u6982\u7387\u4e0e\u4f4e\u6982\u7387\u4e4b\u95f4\u7684\u5dee\u8ddd\u88ab\u538b\u7f29&#xff0c;\u6982\u7387\u5206\u5e03\u8d8b\u4e8e\u5e73\u5766&#xff0c;\u589e\u52a0\u8f93\u51fa\u7684\u591a\u6837\u6027\u4e0e\u521b\u9020\u529b&#xff0c;\u4f46\u8fc7\u9ad8\u4f1a\u5bfc\u81f4\u8bed\u53e5\u8bed\u75c5\u548c\u80e1\u8a00\u4e71\u8bed\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Top-K \u91c7\u6837&#xff1a;\u4ec5\u4fdd\u7559\u6982\u7387\u6700\u9ad8\u7684\u524d K \u4e2a\u5019\u9009\u8bcd&#xff0c;\u5176\u4f59\u5019\u9009\u8bcd\u7684\u6982\u7387\u5f3a\u5236\u6e05\u96f6\u5e76\u91cd\u65b0\u5f52\u4e00\u5316\u3002<\/p>\n<\/li>\n<li>\n<p>Top-P&#xff08;\u6838\u91c7\u6837, Nucleus Sampling&#xff09;&#xff1a;\u5c06\u6240\u6709\u5019\u9009\u8bcd\u6309\u6982\u7387\u4ece\u5927\u5230\u5c0f\u964d\u5e8f\u6392\u5217\u5e76\u7d2f\u52a0&#xff0c;\u4ec5\u4fdd\u7559\u7d2f\u79ef\u6982\u7387\u8fbe\u5230\u9608\u503c P&#xff08;\u5982 0.9&#xff09;\u7684\u6700\u5c0f\u5019\u9009\u5b50\u96c6\u3002\u4e0e Top-K \u76f8\u6bd4&#xff0c;Top-P \u80fd\u591f\u6839\u636e\u4e0a\u4e0b\u6587\u52a8\u6001\u8c03\u6574\u5019\u9009\u8bcd\u6c60\u7684\u5927\u5c0f\u3002<\/p>\n<\/li>\n<li>\n<p>Presence \/ Frequency Penalty&#xff08;\u60e9\u7f5a\u56e0\u5b50&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>Frequency Penalty&#xff1a;\u6839\u636e\u8bcd\u5143\u5728\u5df2\u751f\u6210\u6587\u672c\u4e2d\u51fa\u73b0\u7684\u7edd\u5bf9\u9891\u6b21\u6309\u6bd4\u4f8b\u6263\u51cf Logits&#xff0c;\u6291\u5236\u9ad8\u9891\u65e0\u610f\u4e49\u5b57\u8bcd\u7684\u5355\u8c03\u91cd\u590d\u3002<\/p>\n<\/li>\n<li>\n<p>Presence Penalty&#xff1a;\u53ea\u8981\u8bcd\u5143\u5728\u5386\u53f2\u6587\u672c\u4e2d\u51fa\u73b0\u8fc7\u4e00\u6b21&#xff0c;\u5c31\u7ed9\u4e88\u56fa\u5b9a\u6570\u503c\u7684\u60e9\u7f5a&#xff0c;\u9f13\u52b1\u6a21\u578b\u5f15\u5165\u65b0\u7684\u8bdd\u9898\u4e0e\u8bcd\u6c47\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h3>\u516d\u3001 \u9ad8\u6548\u67b6\u6784\u4e0e\u524d\u6cbf\u6f14\u8fdb<\/h3>\n<p>\u5927\u8bed\u8a00\u6a21\u578b\u7684\u57fa\u7840\u67b6\u6784\u6b63\u5728\u5411\u66f4\u4f4e\u7684\u7b97\u529b\u6d88\u8017\u3001\u66f4\u957f\u7684\u4e0a\u4e0b\u6587\u627f\u8f7d\u4ee5\u53ca\u66f4\u6df1\u5ea6\u7684\u903b\u8f91\u63a8\u7406\u65b9\u5411\u6f14\u53d8\u3002<\/p>\n<p>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502                    \u5927\u8bed\u8a00\u6a21\u578b\u524d\u6cbf\u6280\u672f\u67b6\u6784\u6f14\u5316               \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                               \u2502<br \/>\n 1. \u6df7\u5408\u4e13\u5bb6\u67b6\u6784 (MoE)         \u7a00\u758f\u6761\u4ef6\u6fc0\u6d3b \u2794 \u63d0\u5347\u53c2\u6570\u5bb9\u91cf\u540c\u65f6\u4fdd\u6301\u56fa\u5b9a\u63a8\u7406\u7b97\u529b<br \/>\n                               \u2502<br \/>\n 2. \u663e\u5b58 IO \u6781\u81f4\u4f18\u5316           FlashAttention-1\/2\/3 \u2794 \u5206\u5757\u8ba1\u7b97 \u2794 \u6d88\u9664 HBM \u8bfb\u5199\u74f6\u9888<br \/>\n                               \u2502<br \/>\n 3. \u63a8\u7406\u671f\u8ba1\u7b97 (Reasoning)     \u601d\u7ef4\u94fe\u5f3a\u5316\u5b66\u4e60 \u2794 Test-time Compute \u2794 \u81ea\u6211\u53cd\u601d\u4e0e\u7ea0\u9519<\/p>\n<h4>6.1 \u6df7\u5408\u4e13\u5bb6\u6a21\u578b&#xff08;MoE, Mixture of Experts&#xff09;<\/h4>\n<p>\u5728\u4f20\u7edf\u7684\u7a20\u5bc6\u6a21\u578b&#xff08;Dense Model&#xff09;\u4e2d&#xff0c;\u6bcf\u4e2a Token \u5fc5\u987b\u6fc0\u6d3b\u5168\u91cf\u53c2\u6570\u8fdb\u884c\u524d\u5411\u4f20\u64ad\u3002\u6df7\u5408\u4e13\u5bb6\u6a21\u578b&#xff08;MoE&#xff0c;\u5982 DeepSeek-V3\u3001Mixtral&#xff09; \u5f15\u5165\u4e86\u7a00\u758f\u6761\u4ef6\u6fc0\u6d3b&#xff08;Sparse Activation&#xff09;\u673a\u5236&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5c06 Transformer \u4e2d\u7684\u6807\u51c6 FFN \u5c42\u66ff\u6362\u4e3a\u4e00\u7ec4\u5e76\u884c\u7684\u4e13\u5bb6\u524d\u9988\u7f51\u7edc&#xff08;Expert_1, Expert_2, &#8230;, Expert_E&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f15\u5165\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u95e8\u63a7\u8def\u7531\u7f51\u7edc&#xff08;Gating Router&#xff09;&#xff0c;\u8ba1\u7b97\u6bcf\u4e2a Token \u4e0e\u5404\u4e2a\u4e13\u5bb6\u7684\u5339\u914d\u5f97\u5206\u3002<\/p>\n<\/li>\n<li>\n<p>\u9488\u5bf9\u6bcf\u4e2a Token&#xff0c;\u4ec5\u52a8\u6001\u6311\u9009\u6392\u540d\u524d K \u4e2a&#xff08;\u5982 8 \u4e2a\u4e13\u5bb6\u4e2d\u6fc0\u6d3b 2 \u4e2a&#xff09;\u6700\u5339\u914d\u7684\u4e13\u5bb6\u53c2\u4e0e\u8ba1\u7b97&#xff0c;\u5176\u4f59\u4e13\u5bb6\u4fdd\u6301\u9759\u9ed8\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8f93\u5165 Token X<br \/>\n     \u2502<br \/>\n     \u25bc<br \/>\n[ \u95e8\u63a7\u8def\u7531\u7f51\u7edc Gating Router ] \u2500\u2500\u25ba \u8ba1\u7b97\u5339\u914d\u6743\u91cd: [Expert 2 (0.7), Expert 5 (0.3)]<br \/>\n     \u2502<br \/>\n     \u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n     \u25bc (\u4ec5\u8def\u7531\u5230\u6307\u5b9a Top-K \u4e13\u5bb6)       \u25bc<br \/>\n[ Expert 2 (FFN) ]            [ Expert 5 (FFN) ]<br \/>\n     \u2502                                 \u2502<br \/>\n     \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                      \u25bc \u52a0\u6743\u6c42\u548c<br \/>\n                 \u8f93\u51fa Y &#061; 0.7 * E_2(X) &#043; 0.3 * E_5(X)<\/p>\n<p>MoE \u6838\u5fc3\u6536\u76ca&#xff1a;\u5728\u5927\u5e45\u63d0\u5347\u6a21\u578b\u603b\u53c2\u6570\u91cf&#xff08;\u53c2\u6570\u5bb9\u91cf\u4e0e\u77e5\u8bc6\u5b58\u50a8\u7a7a\u95f4&#xff09;\u7684\u540c\u65f6&#xff0c;\u4f7f\u5355 Token \u63a8\u7406\u6240\u9700\u7684\u5b9e\u9645\u6d6e\u70b9\u8fd0\u7b97\u91cf&#xff08;FLOPs&#xff09;\u548c\u5ef6\u8fdf\u4fdd\u6301\u5728\u6781\u4f4e\u6c34\u5e73\u3002<\/p>\n<h4>6.2 \u663e\u5b58 IO \u6781\u81f4\u4f18\u5316&#xff1a;FlashAttention<\/h4>\n<p>\u5728\u5904\u7406\u8d85\u957f\u4e0a\u4e0b\u6587\u65f6&#xff0c;\u6ce8\u610f\u529b\u77e9\u9635 S &#061; Q \u00b7 K^T \u7684\u5c3a\u5bf8\u4e3a [SeqLen, SeqLen]\u3002\u5f53\u5e8f\u5217\u957f\u5ea6\u8fbe\u5230 128K \u65f6&#xff0c;\u7269\u5316\u8be5\u77e9\u9635\u9700\u8981\u6d88\u8017\u6570\u767e GB \u663e\u5b58&#xff0c;\u4e14\u9891\u7e41\u5728 GPU \u663e\u5b58&#xff08;SRAM \u4e0e HBM&#xff09;\u4e4b\u95f4\u8bfb\u5199\u6570\u636e\u4f1a\u5bfc\u81f4\u663e\u5b58\u5e26\u5bbd\u4e25\u91cd\u9971\u548c\u3002<\/p>\n<p>Tri Dao \u63d0\u51fa\u7684 FlashAttention \u4ece\u5e95\u5c42\u786c\u4ef6\u67b6\u6784\u51fa\u53d1&#xff0c;\u91cd\u6784\u4e86 Attention \u7684\u8ba1\u7b97\u903b\u8f91&#xff1a;<\/p>\n<li>\n<p>\u5206\u5757\u8ba1\u7b97&#xff08;Tiling&#xff09;&#xff1a;\u5c06\u8f93\u5165\u77e9\u9635 Q, K, V \u5207\u5206\u4e3a\u9002\u5408 GPU \u7247\u4e0a\u9ad8\u901f SRAM \u7f13\u5b58\u7684\u5c0f\u5757&#xff08;Block&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u7ebf Softmax&#xff08;Online Softmax&#xff09;&#xff1a;\u5229\u7528\u52a8\u6001\u7edf\u8ba1\u91cf\u7f29\u653e\u6280\u5de7&#xff0c;\u5728\u4e0d\u7269\u5316\u6574\u4e2a\u5927\u6ce8\u610f\u529b\u77e9\u9635\u7684\u524d\u63d0\u4e0b&#xff0c;\u9010\u6b65\u7d2f\u52a0\u4e2d\u95f4\u7ed3\u679c\u3002<\/p>\n<\/li>\n<li>\n<p>\u6838\u51fd\u6570\u878d\u5408&#xff08;Kernel Fusion&#xff09;&#xff1a;\u5c06\u77e9\u9635\u4e58\u6cd5\u3001Mask\u3001Softmax \u548c Dropout \u64cd\u4f5c\u878d\u5408\u5728\u4e00\u4e2a Triton\/CUDA Kernel \u4e2d\u5b8c\u6210&#xff0c;\u6d88\u9664\u5bf9\u4f4e\u901f HBM \u663e\u5b58\u7684\u591a\u4f59\u8bfb\u5199\u3002<\/p>\n<\/li>\n<p>FlashAttention \u5728\u6570\u5b66\u8ba1\u7b97\u7ed3\u679c\u4e0a\u4e0e\u6807\u51c6\u6ce8\u610f\u529b\u5b8c\u5168\u7b49\u4ef7&#xff0c;\u4f46\u5c06\u8fd0\u884c\u901f\u5ea6\u63d0\u5347\u4e86\u6570\u500d&#xff0c;\u5e76\u5c06 Attention \u663e\u5b58\u590d\u6742\u5ea6\u4ece O(N^2) \u5f7b\u5e95\u964d\u4e3a O(N)\u3002<\/p>\n<h4>6.3 \u6df1\u5ea6\u63a8\u7406\u8303\u5f0f\u8f6c\u79fb&#xff1a;\u63a8\u7406\u671f\u7b97\u529b&#xff08;Test-Time Compute&#xff09;<\/h4>\n<p>\u4ee5 OpenAI o1\/o3 \u53ca DeepSeek-R1 \u4e3a\u4ee3\u8868\u7684\u65b0\u4e00\u4ee3\u63a8\u7406\u6a21\u578b&#xff08;Reasoning Models&#xff09;&#xff0c;\u4ee3\u8868\u4e86\u5927\u6a21\u578b\u5e95\u5c42\u7684\u6700\u65b0\u6f14\u8fdb\u65b9\u5411&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f20\u7edf LLM&#xff1a;\u5c06\u5168\u90e8\u601d\u8003\u8fc7\u7a0b\u538b\u7f29\u5728\u5355\u6b21\u524d\u5411\u4f20\u9012\u4e2d&#xff0c;\u9047\u5230\u8d85\u96be\u95ee\u9898\u65f6\u5bb9\u6613\u4ea7\u751f\u8df3\u6b65\u548c\u903b\u8f91\u8c2c\u8bef\u3002<\/p>\n<\/li>\n<li>\n<p>\u63a8\u7406\u6a21\u578b&#xff1a;\u901a\u8fc7\u5927\u89c4\u6a21\u5f3a\u5316\u5b66\u4e60&#xff08;RL&#xff09;&#xff0c;\u8bf1\u5bfc\u6a21\u578b\u5728\u8f93\u51fa\u6700\u7ec8\u7b54\u6848\u4e4b\u524d&#xff0c;\u5728\u5185\u90e8\u751f\u6210\u6781\u957f\u3001\u5305\u542b\u81ea\u6211\u7ea0\u9519\u3001\u591a\u8def\u5f84\u5c1d\u8bd5\u4e0e\u63a8\u5bfc\u9a8c\u8bc1\u7684\u601d\u7ef4\u94fe&#xff08;Chain of Thought, CoT&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e00\u7a81\u7834\u5f00\u8f9f\u4e86\u5168\u65b0\u7684\u6269\u5c55\u7ef4\u5ea6\u2014\u2014\u63a8\u7406\u671f\u6269\u5c55\u5b9a\u5f8b&#xff08;Inference Scaling Law&#xff09;&#xff1a;\u5bf9\u4e8e\u9ad8\u96be\u5ea6\u79d1\u5b66\u4e0e\u903b\u8f91\u95ee\u9898&#xff0c;\u901a\u8fc7\u589e\u52a0\u6a21\u578b\u5728\u63a8\u7406\u9636\u6bb5\u7684\u601d\u8003\u65f6\u95f4\u4e0e\u8ba1\u7b97\u6b65\u6570&#xff08;Test-time Compute&#xff09;&#xff0c;\u6a21\u578b\u7684\u51c6\u786e\u7387\u53ef\u4ee5\u6301\u7eed\u7a81\u7834\u539f\u6709\u53c2\u6570\u89c4\u6a21\u7684\u4e0a\u9650\u3002<\/p>\n<h3>\u4e03\u3001 \u603b\u7ed3\u4e0e\u6280\u672f\u5168\u666f\u5bf9\u7167\u8868<\/h3>\n<p>\u5927\u8bed\u8a00\u6a21\u578b\u5e76\u4e0d\u662f\u795e\u79d8\u7684\u4e0d\u53ef\u77e5\u9ed1\u76d2&#xff0c;\u800c\u662f\u4e00\u5957\u5efa\u7acb\u5728\u4e25\u683c\u6982\u7387\u7edf\u8ba1\u3001\u77e9\u9635\u5fae\u79ef\u5206\u4e0e\u5927\u89c4\u6a21\u5206\u5e03\u5f0f\u5e76\u884c\u5de5\u7a0b\u4e4b\u4e0a\u7684\u7cbe\u5bc6\u7cfb\u7edf\u3002<\/p>\n<table>\n<tr>\n<td>\u6a21\u5757\u5206\u5c42<\/td>\n<td>\u6838\u5fc3\u6280\u672f \/ \u5173\u952e\u7ec4\u4ef6<\/td>\n<td>\u89e3\u51b3\u7684\u6838\u5fc3\u5de5\u7a0b\u4e0e\u6570\u5b66\u95ee\u9898<\/td>\n<\/tr>\n<tbody>\n<tr>\n<td>\u6570\u5b66\u57fa\u7840<\/td>\n<td>\u81ea\u56de\u5f52\u8054\u5408\u6982\u7387\u94fe\u5f0f\u6cd5\u5219<\/td>\n<td>\u7edf\u4e00\u5e8f\u5217\u7406\u89e3\u4e0e\u751f\u6210\u4efb\u52a1&#xff0c;\u5efa\u7acb\u57fa\u4e8e\u6982\u7387\u7684 Next-Token \u9884\u6d4b\u673a\u5236<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u4e0e\u7f16\u7801<\/td>\n<td>Byte-level BPE &#043; Byte-fallback<\/td>\n<td>\u5efa\u7acb\u7d27\u51d1\u7684\u79bb\u6563\u8bed\u4e49\u6620\u5c04&#xff0c;\u6d88\u9664\u672a\u767b\u5f55\u8bcd&#xff08;OOV&#xff09;\u5e76\u517c\u987e\u591a\u8bed\u8a00\u6548\u7387<\/td>\n<\/tr>\n<tr>\n<td>\u8ba1\u7b97\u9aa8\u5e72<\/td>\n<td>Decoder-Only &#043; RoPE &#043; GQA &#043; SwiGLU<\/td>\n<td>\u5b9e\u73b0\u786c\u4ef6\u53cb\u597d\u7684\u9ad8\u541e\u5410\u77e9\u9635\u5e76\u884c&#xff0c;\u4f18\u5316\u957f\u4e0a\u4e0b\u6587\u76f8\u5bf9\u4f4d\u7f6e\u611f\u77e5\u4e0e\u663e\u5b58\u5360\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u751f\u547d\u5468\u671f<\/td>\n<td>Pre-training \u2794 SFT \u2794 RLHF \/ DPO<\/td>\n<td>\u4f9d\u6b21\u5b8c\u6210\u901a\u8bc6\u77e5\u8bc6\u83b7\u53d6\u3001\u95ee\u7b54\u5bf9\u8bdd\u6307\u4ee4\u9075\u5faa\u4e0e\u4eba\u7c7b\u4ef7\u503c\u5b89\u5168\u5bf9\u9f50<\/td>\n<\/tr>\n<tr>\n<td>\u63a8\u7406\u7cfb\u7edf<\/td>\n<td>KV Cache &#043; Continuous Batching &#043; FlashAttention<\/td>\n<td>\u964d\u4f4e\u957f\u6587\u672c\u663e\u5b58 IO \u5f00\u9500\u4e0e\u65f6\u95f4\u590d\u6742\u5ea6&#xff0c;\u652f\u6301\u9ad8\u5e76\u53d1\u4f4e\u5ef6\u8fdf\u6d41\u5f0f\u4ea4\u4ed8<\/td>\n<\/tr>\n<tr>\n<td>\u524d\u6cbf\u6f14\u8fdb<\/td>\n<td>MoE \u7a00\u758f\u6fc0\u6d3b &#043; \u63a8\u7406\u671f\u5f3a\u5316\u5b66\u4e60 (RL-driven CoT)<\/td>\n<td>\u7a81\u7834\u7b97\u529b\u4e0e\u53c2\u6570\u89c4\u6a21\u74f6\u9888&#xff0c;\u5b9e\u73b0\u4ece\u7b80\u5355\u6587\u672c\u7eed\u5199\u5230\u590d\u6742\u903b\u8f91\u63a8\u7406\u7684\u8dc3\u8fc1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7406\u89e3\u5927\u6a21\u578b\u7684\u5e95\u5c42\u57fa\u7840&#xff0c;\u662f\u5f00\u53d1\u8005\u5728\u6a21\u578b\u9009\u578b\u3001\u7cfb\u7edf\u5fae\u8c03\u3001RAG \u68c0\u7d22\u589e\u5f3a\u8bbe\u8ba1\u4ee5\u53ca Agent \u667a\u80fd\u4f53\u7cfb\u7edf\u67b6\u6784\u4e2d\u505a\u51fa\u6b63\u786e\u5de5\u7a0b\u51b3\u7b56\u7684\u524d\u63d0\u3002\u968f\u7740\u786c\u4ef6\u67b6\u6784\u4e0e\u7b97\u6cd5\u673a\u5236\u7684\u6301\u7eed\u6f14\u8fdb&#xff0c;LLM \u6b63\u5728\u4ece\u5355\u7eaf\u7684\u81ea\u7136\u8bed\u8a00\u5904\u7406\u5de5\u5177&#xff0c;\u6f14\u8fdb\u4e3a\u4e0b\u4e00\u4ee3\u8ba1\u7b97\u5e73\u53f0\u7684\u667a\u80fd\u5185\u6838\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001 \u5927\u8bed\u8a00\u6a21\u578b\u7684\u6570\u5b66\u672c\u8d28\u4e0e\u6f14\u8fdb\u673a\u74061.1 \u8bed\u8a00\u6a21\u578b\u7684\u5f62\u5f0f\u5316\u5b9a\u4e49\u4ece\u6982\u7387\u8bba\u4e0e\u7edf\u8ba1\u5b66\u89c6\u89d2\u6765\u770b&#xff0c;\u8bed\u8a00\u6a21\u578b&#xff08;Language Model, LM&#xff09;\u7684\u76ee\u6807\u662f\u5efa\u7acb\u4e00\u4e2a\u8ba1\u7b97\u81ea\u7136\u8bed\u8a00\u5e8f\u5217\u6982\u7387\u5206\u5e03\u7684\u6570\u5b66\u6a21\u578b\u3002\u8bbe\u4e00\u6bb5\u6587\u672c\u7531\u6309\u65f6\u5e8f\u6392\u5217\u7684\u8bcd\u5143&#xff08;Token&#xff09;\u5e8f\u5217\u7ec4\u6210&#xff1a;W  (w_1, w_2, w_3, &#8230;, w_n)\u3002\u6839\u636e\u6761\u4ef6\u6982\u7387\u7684\u94fe\u5f0f\u6cd5\u5219&#xff0c;\u8be5\u5e8f\u5217\u7684\u8054\u5408\u6982\u7387\u5206\u5e03\u53ef\u4ee5\u4e25\u683c\u5c55\u5f00\u4e3a&#xff1a;P(W)<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[75,50,100,224,51],"topic":[],"class_list":["post-98545","post","type-post","status-publish","format-standard","hentry","category-server","tag-llm","tag-50","tag-100","tag-224","tag-51"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/98545.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001 \u5927\u8bed\u8a00\u6a21\u578b\u7684\u6570\u5b66\u672c\u8d28\u4e0e\u6f14\u8fdb\u673a\u74061.1 \u8bed\u8a00\u6a21\u578b\u7684\u5f62\u5f0f\u5316\u5b9a\u4e49\u4ece\u6982\u7387\u8bba\u4e0e\u7edf\u8ba1\u5b66\u89c6\u89d2\u6765\u770b&#xff0c;\u8bed\u8a00\u6a21\u578b&#xff08;Language Model, LM&#xff09;\u7684\u76ee\u6807\u662f\u5efa\u7acb\u4e00\u4e2a\u8ba1\u7b97\u81ea\u7136\u8bed\u8a00\u5e8f\u5217\u6982\u7387\u5206\u5e03\u7684\u6570\u5b66\u6a21\u578b\u3002\u8bbe\u4e00\u6bb5\u6587\u672c\u7531\u6309\u65f6\u5e8f\u6392\u5217\u7684\u8bcd\u5143&#xff08;Token&#xff09;\u5e8f\u5217\u7ec4\u6210&#xff1a;W (w_1, w_2, w_3, ..., w_n)\u3002\u6839\u636e\u6761\u4ef6\u6982\u7387\u7684\u94fe\u5f0f\u6cd5\u5219&#xff0c;\u8be5\u5e8f\u5217\u7684\u8054\u5408\u6982\u7387\u5206\u5e03\u53ef\u4ee5\u4e25\u683c\u5c55\u5f00\u4e3a&#xff1a;P(W)\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/98545.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-31T22:59:33+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/98545.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/98545.html\",\"name\":\"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-31T22:59:33+00:00\",\"dateModified\":\"2026-08-31T22:59:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/98545.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/98545.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/98545.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/98545.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u3001 \u5927\u8bed\u8a00\u6a21\u578b\u7684\u6570\u5b66\u672c\u8d28\u4e0e\u6f14\u8fdb\u673a\u74061.1 \u8bed\u8a00\u6a21\u578b\u7684\u5f62\u5f0f\u5316\u5b9a\u4e49\u4ece\u6982\u7387\u8bba\u4e0e\u7edf\u8ba1\u5b66\u89c6\u89d2\u6765\u770b&#xff0c;\u8bed\u8a00\u6a21\u578b&#xff08;Language Model, LM&#xff09;\u7684\u76ee\u6807\u662f\u5efa\u7acb\u4e00\u4e2a\u8ba1\u7b97\u81ea\u7136\u8bed\u8a00\u5e8f\u5217\u6982\u7387\u5206\u5e03\u7684\u6570\u5b66\u6a21\u578b\u3002\u8bbe\u4e00\u6bb5\u6587\u672c\u7531\u6309\u65f6\u5e8f\u6392\u5217\u7684\u8bcd\u5143&#xff08;Token&#xff09;\u5e8f\u5217\u7ec4\u6210&#xff1a;W (w_1, w_2, w_3, ..., w_n)\u3002\u6839\u636e\u6761\u4ef6\u6982\u7387\u7684\u94fe\u5f0f\u6cd5\u5219&#xff0c;\u8be5\u5e8f\u5217\u7684\u8054\u5408\u6982\u7387\u5206\u5e03\u53ef\u4ee5\u4e25\u683c\u5c55\u5f00\u4e3a&#xff1a;P(W)","og_url":"https:\/\/www.wsisp.com\/helps\/98545.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-31T22:59:33+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/98545.html","url":"https:\/\/www.wsisp.com\/helps\/98545.html","name":"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-31T22:59:33+00:00","dateModified":"2026-08-31T22:59:33+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/98545.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/98545.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/98545.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5927\u8bed\u8a00\u6a21\u578b\u57fa\u7840"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/98545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=98545"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/98545\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=98545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=98545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=98545"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=98545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}