{"id":20909,"date":"2025-02-12T20:00:02","date_gmt":"2025-02-12T12:00:02","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=20909"},"modified":"2025-02-12T20:00:02","modified_gmt":"2025-02-12T12:00:02","slug":"jingweidiaoxiao-deepsee","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/ja\/jingweidiaoxiao-deepsee\/","title":{"rendered":"\u7cbe\u5fae\u8c03\u6821 DeepSeek R1 \u6a21\u578b\uff0c\u8d4b\u80fd\u533b\u7597\u7cbe\u51c6\u95ee\u7b54\uff1a\u5f00\u6e90 AI \u7684\u6f5c\u529b\u91ca\u653e"},"content":{"rendered":"<p><a href=\"https:\/\/www.kdjingpai.com\/deepseek-chatshena\/\">DeepSeek<\/a> \u63a8\u51fa\u4e00\u7cfb\u5217\u5148\u8fdb\u63a8\u7406\u6a21\u578b\uff0c\u6311\u6218 OpenAI \u884c\u4e1a\u5730\u4f4d\uff0c\u4e14<strong>\u5b8c\u5168\u514d\u8d39\u3001\u65e0\u4f7f\u7528\u9650\u5236<\/strong>\uff0c\u60e0\u53ca\u6240\u6709\u7528\u6237\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Hugging Face \u7684\u533b\u5b66\u601d\u7ef4\u94fe\u6570\u636e\u96c6\uff0c\u5bf9 DeepSeek-R1-Distill-Llama-8B \u6a21\u578b\u8fdb\u884c\u5fae\u8c03\u3002\u8fd9\u6b3e\u7cbe\u7b80\u7248 <a href=\"https:\/\/www.kdjingpai.com\/deepseek-r1nenglixiang\/\">DeepSeek-R1<\/a> \u6a21\u578b\uff0c\u901a\u8fc7\u5728 DeepSeek-R1 \u751f\u6210\u7684\u6570\u636e\u4e0a\u5fae\u8c03 Llama 3 8B \u6a21\u578b\u800c\u5f97\uff0c\u5c55\u73b0\u51fa\u4e0e\u539f\u6a21\u578b\u76f8\u8fd1\u7684\u5353\u8d8a\u63a8\u7406\u80fd\u529b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/1aa506b5a954192.jpeg\" alt=\"\" \/><\/p>\n<h2>DeepSeek R1 \u89e3\u5bc6<\/h2>\n<p>DeepSeek-R1 \u4e0e DeepSeek-R1-Zero \u5728\u6570\u5b66\u3001\u7f16\u7a0b\u53ca\u903b\u8f91\u63a8\u7406\u4efb\u52a1\u4e2d\uff0c\u6027\u80fd\u5747\u53ef\u6bd4\u80a9 OpenAI \u7684 o1 \u6a21\u578b\u3002<strong>\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0cR1 \u548c R1-Zero \u5747\u4e3a\u5f00\u6e90\u6a21\u578b<\/strong>\u3002<\/p>\n<h3>DeepSeek-R1-Zero<\/h3>\n<p>DeepSeek-R1-Zero \u4f5c\u4e3a\u9996\u4e2a\u5b8c\u5168\u91c7\u7528\u5927\u89c4\u6a21\u5f3a\u5316\u5b66\u4e60 (RL, Reinforcement Learning) \u8bad\u7ec3\u7684\u5f00\u6e90\u6a21\u578b\uff0c\u6709\u522b\u4e8e\u4f20\u7edf\u4ee5\u76d1\u7763\u5fae\u8c03 (SFT, Supervised Fine-Tuning) \u4e3a\u521d\u59cb\u6b65\u9aa4\u7684\u6a21\u578b\u3002\u8fd9\u79cd\u521b\u65b0\u65b9\u6cd5\u8d4b\u4e88\u4e86\u6a21\u578b\u72ec\u7acb\u63a2\u7d22\u601d\u7ef4\u94fe (CoT, Chain-of-Thought) \u63a8\u7406\u7684\u80fd\u529b\uff0c\u4f7f\u5176\u80fd\u591f\u89e3\u51b3\u590d\u6742\u95ee\u9898\u5e76\u8fed\u4ee3\u4f18\u5316\u8f93\u51fa\u7ed3\u679c\u3002\u7136\u800c\uff0c\u6b64\u65b9\u6cd5\u4e5f\u5e26\u6765\u4e86\u4e00\u4e9b\u6311\u6218\uff0c\u4f8b\u5982\u63a8\u7406\u6b65\u9aa4\u53ef\u80fd\u51fa\u73b0\u91cd\u590d\u3001\u53ef\u8bfb\u6027\u964d\u4f4e\u4ee5\u53ca\u8bed\u8a00\u98ce\u683c\u4e0d\u7edf\u4e00\u7b49\u95ee\u9898\uff0c\u8fdb\u800c\u5f71\u54cd\u6a21\u578b\u7684\u6e05\u6670\u5ea6\u548c\u5b9e\u7528\u6027\u3002<\/p>\n<h3>DeepSeek-R1<\/h3>\n<p>DeepSeek-R1 \u7684\u53d1\u5e03\u65e8\u5728\u514b\u670d DeepSeek-R1-Zero \u7684\u4e0d\u8db3\u3002\u901a\u8fc7\u5728\u5f3a\u5316\u5b66\u4e60\u4e4b\u524d\u5f15\u5165\u51b7\u542f\u52a8\u6570\u636e\uff0cDeepSeek-R1 \u4e3a\u63a8\u7406\u548c\u975e\u63a8\u7406\u4efb\u52a1\u5960\u5b9a\u4e86\u66f4\u575a\u5b9e\u7684\u57fa\u7840\u3002\u8fd9\u79cd\u591a\u9636\u6bb5\u8bad\u7ec3\u7b56\u7565\u4f7f\u5f97 DeepSeek-R1 \u5728\u6570\u5b66\u3001\u7f16\u7a0b\u548c\u63a8\u7406\u57fa\u51c6\u6d4b\u8bd5\u4e2d\uff0c\u80fd\u591f\u8fbe\u5230\u4e0e OpenAI-o1 \u5339\u654c\u7684\u9886\u5148\u6c34\u5e73\uff0c\u5e76\u663e\u8457\u63d0\u5347\u4e86\u8f93\u51fa\u5185\u5bb9\u7684\u53ef\u8bfb\u6027\u4e0e\u8fde\u8d2f\u6027\u3002<\/p>\n<h3>DeepSeek \u84b8\u998f\u6a21\u578b<\/h3>\n<p>DeepSeek \u8fd8\u63a8\u51fa\u4e86\u84b8\u998f\u6a21\u578b\u7cfb\u5217\u3002\u8fd9\u4e9b\u6a21\u578b\u5728\u4fdd\u6301\u5353\u8d8a\u63a8\u7406\u6027\u80fd\u7684\u540c\u65f6\uff0c\u4f53\u79ef\u66f4\u5c0f\u3001\u6548\u7387\u66f4\u9ad8\u3002\u867d\u7136\u53c2\u6570\u89c4\u6a21\u4ece 1.5B \u5230 70B \u4e0d\u7b49\uff0c\u4f46\u8fd9\u4e9b\u6a21\u578b\u5747\u4fdd\u7559\u4e86\u5f3a\u5927\u7684\u63a8\u7406\u80fd\u529b\u3002\u5176\u4e2d\uff0cDeepSeek-R1-Distill-Qwen-32B \u5728\u591a\u9879\u57fa\u51c6\u6d4b\u8bd5\u4e2d\uff0c\u6027\u80fd\u8d85\u8d8a\u4e86 OpenAI-o1-mini \u6a21\u578b\u3002\u66f4\u5c0f\u89c4\u6a21\u7684\u6a21\u578b\u7ee7\u627f\u4e86\u5927\u578b\u6a21\u578b\u7684\u63a8\u7406\u6a21\u5f0f\uff0c\u5145\u5206\u8bc1\u660e\u4e86\u84b8\u998f\u6280\u672f\u7684\u6709\u6548\u6027\u3002<\/p>\n<p><img decoding=\"async\" title=\"\u4e00\u6b65\u6b65\u5c06DeepSeek R1\u5fae\u8c03\u6210\u4e00\u4e2aDeepDoctor\uff08\u8d44\u6df1\u533b\u751f\uff09-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/cd9a56d472df760.jpg\" alt=\"\u4e00\u6b65\u6b65\u5c06DeepSeek R1\u5fae\u8c03\u6210\u4e00\u4e2aDeepDoctor\uff08\u8d44\u6df1\u533b\u751f\uff09-1\" \/><\/p>\n<h2>DeepSeek R1 \u5fae\u8c03\u5b9e\u6218<\/h2>\n<h3>1. \u73af\u5883\u914d\u7f6e<\/h3>\n<p>\u5728\u672c\u6b21\u6a21\u578b\u5fae\u8c03\u5b9e\u8df5\u4e2d\uff0c\u9009\u7528 Kaggle \u4f5c\u4e3a\u4e91\u7aef IDE\uff0c\u539f\u56e0\u5728\u4e8e Kaggle \u63d0\u4f9b\u4e86\u514d\u8d39\u7684 GPU \u8d44\u6e90\u3002\u6700\u521d\u9009\u62e9\u4e86\u4e24\u5757 T4 GPU\uff0c\u4f46\u6700\u7ec8\u4ec5\u4f7f\u7528\u4e86\u4e00\u5757\u3002\u82e5\u7528\u6237\u5e0c\u671b\u5728\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u6a21\u578b\u5fae\u8c03\uff0c\u5219\u81f3\u5c11\u9700\u8981\u914d\u5907<strong>\u4e00\u5757\u5177\u5907 16GB \u663e\u5b58\u7684 RTX 3090 \u663e\u5361<\/strong>\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/c59d92df5e0457a.png\" alt=\"\" \/><\/p>\n<p>\u9996\u5148\uff0c\u542f\u52a8\u4e00\u4e2a\u65b0\u7684 Kaggle notebook\uff0c\u5e76\u5c06\u7528\u6237\u7684 Hugging Face <a href=\"https:\/\/www.kdjingpai.com\/tokenization\/\">token<\/a> \u548c <a href=\"https:\/\/www.kdjingpai.com\/weights\/\">Weights<\/a> &amp; Biases token \u6dfb\u52a0\u4e3a\u5bc6\u94a5\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/4f55328b286bacd.png\" alt=\"\" \/><\/p>\n<p>\u5b8c\u6210\u5bc6\u94a5\u8bbe\u7f6e\u540e\uff0c\u5b89\u88c5\u00a0<strong>unsloth<\/strong>\u00a0Python \u5305\u3002Unsloth \u662f\u4e00\u6b3e\u5f00\u6e90\u6846\u67b6\uff0c\u65e8\u5728\u5c06\u5927\u578b\u8bed\u8a00\u6a21\u578b (LLM) \u7684\u5fae\u8c03\u901f\u5ea6\u63d0\u5347\u4e00\u500d\uff0c\u5e76\u663e\u8457\u63d0\u9ad8\u5185\u5b58\u6548\u7387\u3002<\/p>\n<pre><code>%%capture\r\n!pip install <a href=\"https:\/\/www.kdjingpai.com\/unsloth\/\">unsloth<\/a>\r\n!pip install --force-reinstall --no-cache-dir --no-deps git+https:\/\/github.com\/unslothai\/unsloth.git\r\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u767b\u5f55 Hugging Face CLI\u3002\u6b64\u6b65\u9aa4\u5bf9\u4e8e\u540e\u7eed\u4e0b\u8f7d\u6570\u636e\u96c6\u4ee5\u53ca\u4e0a\u4f20\u5fae\u8c03\u540e\u7684\u6a21\u578b\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<pre><code>from huggingface_hub import login\r\nfrom kaggle_secrets import UserSecretsClient\r\nuser_secrets = UserSecretsClient()\r\nhf_token = user_secrets.get_secret(\"HUGGINGFACE_TOKEN\")\r\nlogin(hf_token)\r\n<\/code><\/pre>\n<p>\u7136\u540e\uff0c\u767b\u5f55 Weights &amp; Biases (wandb)\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee\uff0c\u4ee5\u4fbf\u8ddf\u8e2a\u5b9e\u9a8c\u8fc7\u7a0b\u548c\u5fae\u8c03\u8fdb\u5ea6\u3002<\/p>\n<pre><code>import wandb\r\nwb_token = user_secrets.get_secret(\"wandb\")\r\nwandb.login(key=wb_token)\r\nrun = wandb.init(\r\nproject='Fine-tune-DeepSeek-R1-Distill-Llama-8B on Medical COT Dataset',\r\njob_type=\"training\",\r\nanonymous=\"allow\"\r\n)\r\n<\/code><\/pre>\n<h3>2. \u6a21\u578b\u4e0e tokenizer \u52a0\u8f7d<\/h3>\n<p>\u5728\u672c\u6587\u7684\u5b9e\u8df5\u4e2d\uff0c\u52a0\u8f7d\u4e86 Unsloth \u7248\u672c\u7684 DeepSeek-R1-Distill-Llama-8B \u6a21\u578b\u3002<\/p>\n<p>https:\/\/huggingface.co\/unsloth\/DeepSeek-R1-Distill-Llama-8B<\/p>\n<p>\u4e3a\u4e86\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u548c\u63d0\u5347\u6027\u80fd\uff0c\u9009\u62e9\u4e86\u4ee5 4-bit \u91cf\u5316\u7684\u65b9\u5f0f\u52a0\u8f7d\u6a21\u578b\u3002<\/p>\n<pre><code>from unsloth import FastLanguageModel\r\nmax_seq_length = 2048\r\ndtype = None\r\nload_in_4bit = True\r\nmodel, tokenizer = FastLanguageModel.from_pretrained(\r\nmodel_name=\"unsloth\/DeepSeek-R1-Distill-Llama-8B\",\r\nmax_seq_length=max_seq_length,\r\ndtype=dtype,\r\nload_in_4bit=load_in_4bit,\r\ntoken=hf_token,\r\n)\r\n<\/code><\/pre>\n<h3>3. \u5fae\u8c03\u524d\u6a21\u578b\u63a8\u7406\u80fd\u529b\u521d\u63a2<\/h3>\n<p>\u4e3a\u4e86\u6784\u5efa\u6a21\u578b\u7684\u63d0\u793a\u6a21\u677f\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7cfb\u7edf\u63d0\u793a\uff0c\u5e76\u5728\u5176\u4e2d\u52a0\u5165\u4e86\u95ee\u9898\u548c\u7b54\u6848\u751f\u6210\u7684\u5360\u4f4d\u7b26\u3002\u6b64\u63d0\u793a\u65e8\u5728\u5f15\u5bfc\u6a21\u578b\u9010\u6b65\u601d\u8003\uff0c\u5e76\u6700\u7ec8\u751f\u6210\u903b\u8f91\u4e25\u8c28\u4e14\u51c6\u786e\u7684\u56de\u7b54\u3002<\/p>\n<pre><code>prompt_style = \"\"\"Below is an instruction that describes a task, paired with an input that provides further context.\r\nWrite a response that appropriately completes the request.\r\nBefore answering, think carefully about the question and create a step-by-step chain of thoughts to ensure a logical and accurate response.\r\n### Instruction:\r\nYou are a medical expert with advanced knowledge in clinical reasoning, diagnostics, and treatment planning.\r\nPlease answer the following medical question.\r\n### Question:\r\n{}\r\n### Response:\r\n&lt;think&gt;{}\"\"\"\r\n<\/code><\/pre>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u5411\u00a0<code>prompt_style<\/code>\u00a0\u63d0\u4f9b\u4e86\u4e00\u4e2a\u533b\u5b66\u95ee\u9898\uff0c\u5e76\u5c06\u5176\u8f6c\u5316\u4e3a tokens\uff0c\u968f\u540e\u5c06\u8fd9\u4e9b <a href=\"https:\/\/www.kdjingpai.com\/tokenization\/\">tokens<\/a> \u4f20\u9012\u7ed9\u6a21\u578b\u4ee5\u751f\u6210\u7b54\u6848\u3002<\/p>\n<pre><code>question = \"A 61-year-old woman with a long history of involuntary urine loss during activities like coughing or sneezing but no leakage at night undergoes a gynecological exam and Q-tip test. Based on these findings, what would cystometry most likely reveal about her residual volume and detrusor contractions?\"\r\nFastLanguageModel.for_inference(model)\r\ninputs = tokenizer([prompt_style.format(question, \"\")], return_tensors=\"pt\").to(\"cuda\")\r\noutputs = model.generate(\r\ninput_ids=inputs.input_ids,\r\nattention_mask=inputs.attention_mask,\r\nmax_new_tokens=1200,\r\nuse_cache=True,\r\n)\r\nresponse = tokenizer.batch_decode(outputs)\r\nprint(response[0].split(\"### Response:\")[1])\r\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u533b\u5b66\u95ee\u9898\u7684\u6838\u5fc3\u5185\u5bb9\u662f\uff1a<\/p>\n<p><em>\u4e00\u4f4d 61 \u5c81\u5973\u6027\uff0c\u957f\u671f\u5728\u54b3\u55fd\u6216\u6253\u55b7\u568f\u7b49\u6d3b\u52a8\u4e2d\u51fa\u73b0\u975e\u81ea\u613f\u6027\u6f0f\u5c3f\uff0c\u4f46\u591c\u95f4\u65e0\u6f0f\u5c3f\u73b0\u8c61\u3002\u5979\u63a5\u53d7\u4e86\u5987\u79d1\u68c0\u67e5\u548c Q-tip \u6d4b\u8bd5\u3002\u57fa\u4e8e\u8fd9\u4e9b\u68c0\u67e5\u7ed3\u679c\uff0c\u8180\u80f1\u6d4b\u538b\u6700\u53ef\u80fd\u63ed\u793a\u5176\u6b8b\u4f59\u5c3f\u91cf\u548c\u903c\u5c3f\u808c\u6536\u7f29\u72b6\u6001\u7684\u54ea\u4e9b\u4fe1\u606f\uff1f<\/em><\/p>\n<p>\u5373\u4f7f\u5728\u672a\u7ecf\u5fae\u8c03\u7684\u60c5\u51b5\u4e0b\uff0c\u8be5\u6a21\u578b\u4e5f\u6210\u529f\u751f\u6210\u4e86\u601d\u7ef4\u94fe\uff0c\u5e76\u5728\u7ed9\u51fa\u6700\u7ec8\u7b54\u6848\u524d\u8fdb\u884c\u4e86\u4e25\u8c28\u7684\u63a8\u7406\uff0c\u6574\u4e2a\u63a8\u7406\u8fc7\u7a0b\u88ab\u5c01\u88c5\u5728\u00a0<code>&lt;think&gt;&lt;\/think&gt;<\/code>\u00a0\u6807\u7b7e\u5185\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u4e3a\u4f55\u4ecd\u9700\u8fdb\u884c\u5fae\u8c03\uff1f\u5c3d\u7ba1\u6a21\u578b\u5c55\u73b0\u51fa\u4e86\u8be6\u7ec6\u7684\u63a8\u7406\u8fc7\u7a0b\uff0c\u4f46\u5176\u8868\u8fbe\u7565\u663e\u5197\u957f\uff0c\u4e0d\u591f\u7b80\u6d01\u3002\u6b64\u5916\uff0c\u6700\u7ec8\u7b54\u6848\u4ee5\u9879\u76ee\u7b26\u53f7\u5217\u8868\u7684\u5f62\u5f0f\u5448\u73b0\uff0c\u8fd9\u4e0e\u671f\u671b\u5fae\u8c03\u7684\u6570\u636e\u96c6\u7684\u7ed3\u6784\u548c\u98ce\u683c\u5b58\u5728\u504f\u5dee\u3002<\/p>\n<h3>4. \u6570\u636e\u96c6\u52a0\u8f7d\u4e0e\u9884\u5904\u7406<\/h3>\n<p>\u5bf9\u63d0\u793a\u6a21\u677f\u8fdb\u884c\u4e86\u5fae\u8c03\uff0c\u4ee5\u9002\u5e94\u6570\u636e\u96c6\u7684\u5904\u7406\u9700\u6c42\uff0c\u5177\u4f53\u65b9\u6cd5\u662f\u5728\u63d0\u793a\u6a21\u677f\u4e2d\u4e3a\u590d\u6742\u7684\u601d\u7ef4\u94fe (Complex Chain-of-Thought) \u5217\u6dfb\u52a0\u4e86\u7b2c\u4e09\u4e2a\u5360\u4f4d\u7b26\u3002<\/p>\n<pre><code>train_prompt_style = \"\"\"Below is an instruction that describes a task, paired with an input that provides further context.\r\nWrite a response that appropriately completes the request.\r\nBefore answering, think carefully about the question and create a step-by-step chain of thoughts to ensure a logical and accurate response.\r\n### Instruction:\r\nYou are a medical expert with advanced knowledge in clinical reasoning, diagnostics, and treatment planning.\r\nPlease answer the following medical question.\r\n### Question:\r\n{}\r\n### Response:\r\n&lt;think&gt;\r\n{}\r\n&lt;\/think&gt;\r\n{}\"\"\"\r\n<\/code><\/pre>\n<p>\u7f16\u5199\u4e86\u4e00\u4e2a Python \u51fd\u6570\uff0c\u7528\u4e8e\u5728\u6570\u636e\u96c6\u4e2d\u521b\u5efa \u201ctext\u201d \u5217\u3002\u8be5\u5217\u7684\u5185\u5bb9\u7531\u8bad\u7ec3\u63d0\u793a\u6a21\u677f\u6784\u6210\uff0c\u5e76\u5c06\u5360\u4f4d\u7b26\u5206\u522b\u586b\u5145\u4e3a\u95ee\u9898\u3001\u601d\u7ef4\u94fe\u548c\u7b54\u6848\u3002<\/p>\n<pre><code>EOS_TOKEN = tokenizer.eos_token  # Must add EOS_TOKEN\r\ndef formatting_prompts_func(examples):\r\ninputs = examples[\"Question\"]\r\ncots = examples[\"Complex_CoT\"]\r\noutputs = examples[\"Response\"]\r\ntexts = []\r\nfor input, cot, output in zip(inputs, cots, outputs):\r\ntext = train_prompt_style.format(input, cot, output) + EOS_TOKEN\r\ntexts.append(text)\r\nreturn {\r\n\"text\": texts,\r\n}\r\n<\/code><\/pre>\n<p>\u4ece Hugging Face Hub \u52a0\u8f7d\u4e86 FreedomIntelligence\/medical-o1-reasoning-SFT \u6570\u636e\u96c6\u7684\u524d 500 \u4e2a\u6837\u672c\u3002<\/p>\n<p>https:\/\/huggingface.co\/datasets\/FreedomIntelligence\/medical-o1-reasoning-SFT?row=46<\/p>\n<p>\u968f\u540e\uff0c\u4f7f\u7528\u00a0<code>formatting_prompts_func<\/code>\u00a0\u51fd\u6570\u5bf9\u6570\u636e\u96c6\u7684 \u201ctext\u201d \u5217\u8fdb\u884c\u4e86\u6620\u5c04\u5904\u7406\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/490586c8f3b5f79.png\" alt=\"\" \/><\/p>\n<p>\u5982\u4e0a\u56fe\u6240\u793a\uff0c&#8221;text&#8221; \u5217\u5df2\u6210\u529f\u6574\u5408\u4e86\u7cfb\u7edf\u63d0\u793a\u3001\u6307\u4ee4\u3001\u601d\u7ef4\u94fe\u4ee5\u53ca\u6700\u7ec8\u7b54\u6848\u3002<\/p>\n<h3>5. \u6a21\u578b\u914d\u7f6e<\/h3>\n<p>\u901a\u8fc7\u8bbe\u5b9a\u76ee\u6807\u6a21\u5757\uff0c\u91c7\u7528\u4f4e\u79e9\u9002\u914d\u5668 (Low-Rank Adapter) \u6280\u672f\u5bf9\u6a21\u578b\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<pre><code>model = FastLanguageModel.get_peft_model(\r\nmodel,\r\nr=16,\r\ntarget_modules=[\r\n\"q_proj\",\r\n\"k_proj\",\r\n\"v_proj\",\r\n\"o_proj\",\r\n\"gate_proj\",\r\n\"up_proj\",\r\n\"down_proj\",\r\n],\r\nlora_alpha=16,\r\nlora_dropout=0,\r\nbias=\"none\",\r\nuse_gradient_checkpointing=\"unsloth\",  # True or \"unsloth\" for very long context\r\nrandom_state=3407,\r\nuse_rslora=False,\r\nloftq_config=None,\r\n)\r\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u6765\uff0c\u914d\u7f6e\u4e86\u8bad\u7ec3\u53c2\u6570\u548c\u8bad\u7ec3\u5668 (Trainer)\u3002\u901a\u8fc7\u5411\u8bad\u7ec3\u5668\u63d0\u4f9b\u6a21\u578b\u3001tokenizer\u3001\u6570\u636e\u96c6\u4ee5\u53ca\u5176\u4ed6\u5173\u952e\u8bad\u7ec3\u53c2\u6570\uff0c\u4ee5\u4f18\u5316\u6a21\u578b\u7684\u5fae\u8c03\u8fc7\u7a0b\u3002<\/p>\n<pre><code>from trl import SFTTrainer\r\nfrom transformers import TrainingArguments\r\nfrom unsloth import is_bfloat16_supported\r\ntrainer = SFTTrainer(\r\nmodel=model,\r\ntokenizer=tokenizer,\r\ntrain_dataset=dataset,\r\ndataset_text_field=\"text\",\r\nmax_seq_length=max_seq_length,\r\ndataset_num_proc=2,\r\nargs=TrainingArguments(\r\nper_device_train_batch_size=2,\r\ngradient_accumulation_steps=4,\r\n# Use num_train_epochs = 1, warmup_ratio for full training runs!\r\nwarmup_steps=5,\r\nmax_steps=60,\r\nlearning_rate=2e-4,\r\nfp16=not is_bfloat16_supported(),\r\nbf16=is_bfloat16_supported(),\r\nlogging_steps=10,\r\noptim=\"adamw_8bit\",\r\nweight_decay=0.01,\r\nlr_scheduler_type=\"linear\",\r\nseed=3407,\r\noutput_dir=\"outputs\",\r\n),\r\n)\r\n<\/code><\/pre>\n<h3>6. \u6a21\u578b\u8bad\u7ec3<\/h3>\n<pre><code>trainer_stats = trainer.train()\r\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/6c1e317f7381084.png\" alt=\"\" \/><\/p>\n<p>\u6a21\u578b\u8bad\u7ec3\u8fc7\u7a0b\u8017\u65f6 22 \u5206\u949f\u3002\u8bad\u7ec3\u635f\u5931 (loss) \u9010\u6e10\u964d\u4f4e\uff0c\u8868\u660e\u6a21\u578b\u6027\u80fd\u6709\u6240\u63d0\u5347\uff0c\u8fd9\u662f\u4e00\u4e2a\u79ef\u6781\u7684\u4fe1\u53f7\u3002<\/p>\n<p>\u7528\u6237\u53ef\u4ee5\u767b\u5f55 Weights &amp; Biases \u7f51\u7ad9\uff0c\u67e5\u770b\u5b8c\u6574\u7684\u6a21\u578b\u8bc4\u4f30\u62a5\u544a\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/547f48c8720573e.png\" alt=\"\" \/><\/p>\n<h3>7. \u5fae\u8c03\u540e\u6a21\u578b\u63a8\u7406\u80fd\u529b\u8bc4\u4f30<\/h3>\n<p>\u4e3a\u4e86\u8fdb\u884c\u5bf9\u6bd4\u5206\u6790\uff0c\u518d\u6b21\u5411\u5fae\u8c03\u540e\u7684\u6a21\u578b\u63d0\u51fa\u4e86\u4e0e\u5fae\u8c03\u524d\u76f8\u540c\u7684\u95ee\u9898\uff0c\u4ee5\u89c2\u5bdf\u6a21\u578b\u6027\u80fd\u7684\u53d8\u5316\u3002<\/p>\n<pre><code>question = \"A 61-year-old woman with a long history of involuntary urine loss during activities like coughing or sneezing but no leakage at night undergoes a gynecological exam and Q-tip test. Based on these findings, what would cystometry most likely reveal about her residual volume and detrusor contractions?\"\r\nFastLanguageModel.for_inference(model)  # Unsloth has 2x faster inference!\r\ninputs = tokenizer([prompt_style.format(question, \"\")], return_tensors=\"pt\").to(\"cuda\")\r\noutputs = model.generate(\r\ninput_ids=inputs.input_ids,\r\nattention_mask=inputs.attention_mask,\r\nmax_new_tokens=1200,\r\nuse_cache=True,\r\n)\r\nresponse = tokenizer.batch_decode(outputs)\r\nprint(response[0].split(\"### Response:\")[1])\r\n<\/code><\/pre>\n<p>\u5b9e\u9a8c\u7ed3\u679c\u8868\u660e\uff0c\u5fae\u8c03\u540e\u6a21\u578b\u7684\u8f93\u51fa\u8d28\u91cf\u5f97\u5230\u4e86\u663e\u8457\u63d0\u5347\uff0c\u7b54\u6848\u66f4\u52a0\u7cbe\u51c6\u3002\u601d\u7ef4\u94fe\u7684\u5448\u73b0\u66f4\u4e3a\u7b80\u6d01\u660e\u4e86\uff0c\u6700\u7ec8\u7b54\u6848\u4e5f\u66f4\u52a0\u76f4\u63a5\uff0c\u4ec5\u7528\u4e00\u6bb5\u8bdd\u4fbf\u6e05\u6670\u4f5c\u7b54\uff0c\u8868\u660e\u6b64\u6b21\u6a21\u578b\u5fae\u8c03\u53d6\u5f97\u4e86\u6210\u529f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/c4138e94b0db37e.png\" alt=\"\" \/><\/p>\n<h3>8. \u6a21\u578b\u672c\u5730\u5b58\u50a8<\/h3>\n<p>\u73b0\u5728\uff0c\u5c06\u9002\u914d\u5668 (adapter)\u3001\u5b8c\u6574\u6a21\u578b\u4ee5\u53ca tokenizer \u4fdd\u5b58\u81f3\u672c\u5730\uff0c\u4ee5\u4fbf\u5728\u5176\u4ed6\u9879\u76ee\u4e2d\u4f7f\u7528\u3002<\/p>\n<pre><code>new_model_local = \"DeepSeek-R1-Medical-COT\"\r\nmodel.save_pretrained(new_model_local)\r\ntokenizer.save_pretrained(new_model_local)\r\nmodel.save_pretrained_merged(new_model_local, tokenizer, save_method=\"merged_16bit\")\r\n<\/code><\/pre>\n<h3>9. \u6a21\u578b\u4e0a\u4f20\u81f3 Hugging Face Hub<\/h3>\n<p>\u8fd8\u5c06\u9002\u914d\u5668\u3001tokenizer \u548c\u5b8c\u6574\u6a21\u578b\u63a8\u9001\u81f3 Hugging Face Hub\uff0c\u65e8\u5728\u4f7f AI \u793e\u533a\u80fd\u591f\u5145\u5206\u5229\u7528\u8fd9\u4e00\u5fae\u8c03\u6a21\u578b\uff0c\u5e76\u5c06\u5176\u4fbf\u6377\u5730\u96c6\u6210\u5230\u5404\u81ea\u7684\u7cfb\u7edf\u4e2d\u3002<\/p>\n<pre><code>new_model_online = \"realyinchen\/DeepSeek-R1-Medical-COT\"\r\nmodel.push_to_hub(new_model_online)\r\ntokenizer.push_to_hub(new_model_online)\r\nmodel.push_to_hub_merged(new_model_online, tokenizer, save_method=\"merged_16bit\")\r\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2025\/02\/7c420cb1553634f.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p><strong>\u4eba\u5de5\u667a\u80fd (AI) \u9886\u57df\u6b63\u7ecf\u5386\u7740\u65e5\u65b0\u6708\u5f02\u7684\u53d8\u9769\u3002\u5f00\u6e90\u793e\u533a\u7684\u5d1b\u8d77\uff0c\u5bf9\u8fc7\u53bb\u4e09\u5e74\u7531\u4e13\u6709\u6a21\u578b\u4e3b\u5bfc\u7684 AI \u683c\u5c40\u63d0\u51fa\u4e86\u6709\u529b\u6311\u6218\u3002<\/strong>\u00a0\u5f00\u6e90\u5927\u578b\u8bed\u8a00\u6a21\u578b (LLM) \u7684\u6027\u80fd\u65e5\u76ca\u63d0\u5347\uff0c\u901f\u5ea6\u66f4\u5feb\uff0c\u6548\u7387\u66f4\u9ad8\uff0c\u4f7f\u5f97\u5728\u8f83\u4f4e\u7684\u8ba1\u7b97\u548c\u5185\u5b58\u8d44\u6e90\u6761\u4ef6\u4e0b\u5bf9\u5176\u8fdb\u884c\u5fae\u8c03\uff0c\u53d8\u5f97\u524d\u6240\u672a\u6709\u7684\u4fbf\u6377\u3002<\/p>\n<p>\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u4e86 <a href=\"https:\/\/www.kdjingpai.com\/deepseek-r1nenglixiang\/\">DeepSeek R1<\/a> \u63a8\u7406\u6a21\u578b\uff0c\u5e76\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u5bf9\u5176\u7cbe\u7b80\u7248\u672c\u8fdb\u884c\u5fae\u8c03\uff0c\u4ee5\u5e94\u7528\u4e8e\u533b\u5b66\u95ee\u7b54\u573a\u666f\u3002\u5fae\u8c03\u540e\u7684\u63a8\u7406\u6a21\u578b\u4e0d\u4ec5\u6027\u80fd\u663e\u8457\u63d0\u5347\uff0c\u66f4\u4f7f\u5176\u5728\u533b\u5b66\u3001\u6025\u6551\u670d\u52a1\u548c\u533b\u7597\u4fdd\u5065\u7b49\u5173\u952e\u9886\u57df\u5177\u5907\u4e86\u5b9e\u9645\u5e94\u7528\u4ef7\u503c\u3002<\/p>\n<p>\u4e3a\u79ef\u6781\u5e94\u5bf9 DeepSeek R1 \u7684\u53d1\u5e03\uff0cOpenAI \u4ea6\u8fc5\u901f\u63a8\u51fa\u4e86\u4e24\u9879\u91cd\u8981\u5de5\u5177\uff1a\u66f4\u5148\u8fdb\u7684\u63a8\u7406\u6a21\u578b o3\uff0c\u4ee5\u53ca <a href=\"https:\/\/www.kdjingpai.com\/openai-tuichushougel\/\">Operator<\/a> AI Agent\u3002\u540e\u8005\u4f9d\u6258\u4e8e\u5168\u65b0\u7684\u8ba1\u7b97\u673a\u4f7f\u7528 Agent (CUA, <a href=\"https:\/\/www.kdjingpai.com\/tldraw-computer\/\">Computer<\/a> Use Agent) \u6a21\u578b\uff0c\u5c55\u73b0\u51fa\u81ea\u4e3b\u6d4f\u89c8\u7f51\u7ad9\u5e76\u6267\u884c\u590d\u6742\u4efb\u52a1\u7684\u80fd\u529b\u3002<\/p>\n<p><strong>\u6e90\u4ee3\u7801\uff1a<\/strong><br \/>\n<iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" title=\"DeepSeek-R1-Medical-COT\" src=\"https:\/\/www.kaggle.com\/embed\/realyinchen\/deepseek-r1-medical-cot?kernelSessionId=221976321#?secret=baoCKqBHvQ\" data-secret=\"baoCKqBHvQ\" height=\"750\" frameborder=\"0\" scrolling=\"auto\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DeepSeek \u63a8\u51fa\u4e00\u7cfb\u5217\u5148\u8fdb\u63a8\u7406\u6a21\u578b\uff0c\u6311\u6218 OpenAI \u884c\u4e1a\u5730\u4f4d\uff0c\u4e14\u5b8c\u5168\u514d\u8d39\u3001\u65e0\u4f7f\u7528\u9650\u5236\uff0c\u60e0\u53ca\u6240\u6709\u7528\u6237\u3002 \u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Hugging Face \u7684\u533b\u5b66\u601d\u7ef4\u94fe\u6570\u636e\u96c6\uff0c\u5bf9 DeepSeek-R1-Distill-Llama-8B &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182],"tags":[],"class_list":["post-20909","post","type-post","status-publish","format-standard","hentry","category-shicao"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/20909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/comments?post=20909"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/posts\/20909\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/media?parent=20909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/categories?post=20909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/ja\/wp-json\/wp\/v2\/tags?post=20909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}