[{"data":1,"prerenderedAt":297},["ShallowReactive",2],{"content-query-3v2b0BS7EG":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":291,"_id":292,"_source":293,"_file":294,"_stem":295,"_extension":296},"/technology-blogs/zh/3611","zh",false,"","人人都能上手部署DeepSeek-R1蒸馏模型：社区开发者应用昇思+香橙派 AI Pro实践优化心得","作者：陈新杰       郑州轻工业大学 梅科尔工作室","2025-02-19","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/95ec3a3db2e34660948f5a9d9540c445.png","technology-blogs","开发者分享",{"type":15,"children":16,"toc":286},"root",[17,25,35,43,48,53,69,74,82,87,98,106,114,119,127,135,140,147,155,163,168,182,189,194,204,209,217,222,229,236,241,248,253,260,265,272,281],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"人人都能上手部署deepseek-r1蒸馏模型社区开发者应用昇思香橙派-ai-pro实践优化心得",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":18,"tag":30,"props":31,"children":32},"strong",{},[33],{"type":24,"value":34},"作者：陈新杰 郑州轻工业大学 梅科尔工作室",{"type":18,"tag":26,"props":36,"children":37},{},[38],{"type":18,"tag":30,"props":39,"children":40},{},[41],{"type":24,"value":42},"前序",{"type":18,"tag":26,"props":44,"children":45},{},[46],{"type":24,"value":47},"2025年蛇年春节，DeepSeek强势出圈，以十分之一的训练成本比肩OpenAI GPT-4o的性能，重塑AI世界新秩序。DeepSeek向全世界开源，为全球的数据科学家、AI爱好者乃至中小开发者开辟了一条通往前沿技术的道路。",{"type":18,"tag":26,"props":49,"children":50},{},[51],{"type":24,"value":52},"而DeepSeek-R1-Distill-Qwen-1.5B 是DeepSeek-R1在 Qwen系列开源模型上进一步优化和蒸馏得到的轻量化语言模型，通过蒸馏技术实现效率与性能的平衡，适合于资源受限场景。",{"type":18,"tag":26,"props":54,"children":55},{},[56,58,67],{"type":24,"value":57},"笔者所在的团队之前就有尝试在开发板上部署DeepSeek相关蒸馏模型，但苦于一直没有成功，或者部署成功后仅利用了CPU的算力，导致执行性能很慢。在2月10日了解到DeepSeek-R1-Distill-Qwen-1.5B模型基于MindSpore可以跑在香橙派AI Pro了（文章详见：",{"type":18,"tag":59,"props":60,"children":64},"a",{"href":61,"rel":62},"https://mp.weixin.qq.com/s/l%5C_CcRJ7Yeirkom36RmizmQ%EF%BC%89%EF%BC%8C%E9%9D%9E%E5%B8%B8%E6%BF%80%E5%8A%A8%EF%BC%8C%E5%BD%93%E5%A4%A9%E6%99%9A%E4%B8%8A%E4%BE%BF%E5%9C%A8%E9%A6%99%E6%A9%99%E6%B4%BEAI",[63],"nofollow",[65],{"type":24,"value":66},"https://mp.weixin.qq.com/s/l\\_CcRJ7Yeirkom36RmizmQ），非常激动，当天晚上便在香橙派AI",{"type":24,"value":68}," Pro（20T）24G开发板上把模型部署起来了。",{"type":18,"tag":26,"props":70,"children":71},{},[72],{"type":24,"value":73},"但笔者在运行过程中也发现了一些问题和可优化点，所以在原代码基础上又进行了修改和优化，在此也分享下自己的心得：",{"type":18,"tag":26,"props":75,"children":76},{},[77],{"type":18,"tag":30,"props":78,"children":79},{},[80],{"type":24,"value":81},"开源链接",{"type":18,"tag":26,"props":83,"children":84},{},[85],{"type":24,"value":86},"DeepSeek-R1-Distill-Qwen-1.5B部署代码：",{"type":18,"tag":26,"props":88,"children":89},{},[90,96],{"type":18,"tag":59,"props":91,"children":94},{"href":92,"rel":93},"https://github.com/mindspore-courses/orange-pi-mindspore/tree/master/Online/17-DeepSeek-R1-Distill-Qwen-1.5B",[63],[95],{"type":24,"value":92},{"type":24,"value":97},")",{"type":18,"tag":26,"props":99,"children":100},{},[101],{"type":18,"tag":30,"props":102,"children":103},{},[104],{"type":24,"value":105},"问题描述",{"type":18,"tag":26,"props":107,"children":108},{},[109],{"type":18,"tag":30,"props":110,"children":111},{},[112],{"type":24,"value":113},"问题一：模型权重下载过慢或者不成功",{"type":18,"tag":26,"props":115,"children":116},{},[117],{"type":24,"value":118},"原代码是从默认从HuggingFace上下载权重，有时会因为一些“你懂得”的问题下载权重过慢或者直接下载不成功。",{"type":18,"tag":26,"props":120,"children":121},{},[122],{"type":18,"tag":123,"props":124,"children":126},"img",{"alt":7,"src":125},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/688c528be5dd48eb88902cc821b3a0f5.png",[],{"type":18,"tag":26,"props":128,"children":129},{},[130],{"type":18,"tag":30,"props":131,"children":132},{},[133],{"type":24,"value":134},"问题二：重复回答",{"type":18,"tag":26,"props":136,"children":137},{},[138],{"type":24,"value":139},"在进行长文本输出的过程当中，输出回答到一定长度后模型会输出重复内容，如图所示：",{"type":18,"tag":26,"props":141,"children":142},{},[143],{"type":18,"tag":123,"props":144,"children":146},{"alt":7,"src":145},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/28685e21895c4215987e3f65b31909da.png",[],{"type":18,"tag":26,"props":148,"children":149},{},[150],{"type":18,"tag":30,"props":151,"children":152},{},[153],{"type":24,"value":154},"解决方案",{"type":18,"tag":26,"props":156,"children":157},{},[158],{"type":18,"tag":30,"props":159,"children":160},{},[161],{"type":24,"value":162},"问题一：模型权重下载过慢或不成功",{"type":18,"tag":26,"props":164,"children":165},{},[166],{"type":24,"value":167},"咨询了MindSpore工程师后发现，MindSpore NLP是支持选择镜像的，可以选择国内的镜像网站（如modelers、modelscope）下载权重，这里以modelers上下载权重为例。",{"type":18,"tag":26,"props":169,"children":170},{},[171,173,180],{"type":24,"value":172},"我们发现魔乐社区（",{"type":18,"tag":59,"props":174,"children":177},{"href":175,"rel":176},"https://modelers.cn/%EF%BC%89",[63],[178],{"type":24,"value":179},"https://modelers.cn/）",{"type":24,"value":181}," 上已经有了DeepSeek-R1-Distill-Qwen-1.5B的权重，我们点击图中红框部分，将model id复制下来。",{"type":18,"tag":26,"props":183,"children":184},{},[185],{"type":18,"tag":123,"props":186,"children":188},{"alt":7,"src":187},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/ab6932f41b084afda400f43a12531282.png",[],{"type":18,"tag":26,"props":190,"children":191},{},[192],{"type":24,"value":193},"并将代码中实例化tokenizer和模型的代码改成如下：",{"type":18,"tag":195,"props":196,"children":198},"pre",{"code":197},"\ntokenizer = AutoTokenizer.from_pretrained(\"MindSpore-Lab/DeepSeek-R1-Distill-Qwen-1.5B\", mirror=\"modelers\", ms_dtype=mindspore.float16)\nmodel = AutoModelForCausalLM.from_pretrained(\"MindSpore-Lab/DeepSeek-R1-Distill-Qwen-1.5B\", mirror=\"modelers\", ms_dtype=mindspore.float16)\n",[199],{"type":18,"tag":200,"props":201,"children":202},"code",{"__ignoreMap":7},[203],{"type":24,"value":197},{"type":18,"tag":26,"props":205,"children":206},{},[207],{"type":24,"value":208},"注意：目前MindSpore NLP master分支可支持从modelers下载镜像，需要在终端执行如下命令。",{"type":18,"tag":195,"props":210,"children":212},{"code":211},"pip install git+https://github.com/mindspore-lab/mindnlp.git\n",[213],{"type":18,"tag":200,"props":214,"children":215},{"__ignoreMap":7},[216],{"type":24,"value":211},{"type":18,"tag":26,"props":218,"children":219},{},[220],{"type":24,"value":221},"安装后再执行DeepSeek-R1-Distill-Qwen-1.5B的案例python脚本，就可以下载权重了。",{"type":18,"tag":26,"props":223,"children":224},{},[225],{"type":18,"tag":123,"props":226,"children":228},{"alt":7,"src":227},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/87fc1c7ec85f47179e4edf652560966b.png",[],{"type":18,"tag":26,"props":230,"children":231},{},[232],{"type":18,"tag":30,"props":233,"children":234},{},[235],{"type":24,"value":134},{"type":18,"tag":26,"props":237,"children":238},{},[239],{"type":24,"value":240},"这个在第二天与MindSpore社区工作人员讨论过后，确定是由于部分参数未进行设置，比如惩罚系数的参数设置，原程序设置为None：",{"type":18,"tag":26,"props":242,"children":243},{},[244],{"type":18,"tag":123,"props":245,"children":247},{"alt":7,"src":246},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/38f573f694c544f29e011fc146a4ef9d.png",[],{"type":18,"tag":26,"props":249,"children":250},{},[251],{"type":24,"value":252},"需要将generate_kwargs（第34行）中添加repetition_penalty=1.2，即可解决长文本输出重复问题：",{"type":18,"tag":26,"props":254,"children":255},{},[256],{"type":18,"tag":123,"props":257,"children":259},{"alt":7,"src":258},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/192d9848ff9543cd9768c2f55c8116e7.png",[],{"type":18,"tag":26,"props":261,"children":262},{},[263],{"type":24,"value":264},"再次运行，长文本回答便不再出现重复内容，可以正常输出：",{"type":18,"tag":26,"props":266,"children":267},{},[268],{"type":18,"tag":123,"props":269,"children":271},{"alt":7,"src":270},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2025/02/20/27ddff874cdd44f69f0492c8acc9fc84.png",[],{"type":18,"tag":273,"props":274,"children":276},"h3",{"id":275},"写在最后",[277],{"type":18,"tag":30,"props":278,"children":279},{},[280],{"type":24,"value":275},{"type":18,"tag":26,"props":282,"children":283},{},[284],{"type":24,"value":285},"感谢MindSpore开源社区开发专家的热情支持，专家们不仅耐心解答了我关于香橙派AI Pro硬件适配和DeepSeek模型部署流程中的各种疑难问题，还通过分享实际案例和优化技巧，让我对香橙派AI Pro的性能优势以及DeepSeek模型的高效部署有了更深入的理解，更加积极地参与开源社区、拥抱开源。",{"title":7,"searchDepth":287,"depth":287,"links":288},4,[289],{"id":275,"depth":290,"text":275},3,"markdown","content:technology-blogs:zh:3611.md","content","technology-blogs/zh/3611.md","technology-blogs/zh/3611","md",1776506132256]