微信扫码
添加专属顾问
我要投稿
Apache Dubbo携手DeepSeek R1,释放AI大模型的无限潜力。 核心内容: 1. DeepSeek R1大模型发布及其开源模型权重 2. Apache Dubbo多语言SDK助力DeepSeek R1企业级部署 3. 本地部署DeepSeek R1的优势及原生部署实践指南
2025年1月20日,国产大模型公司深度求索(DeepSeek)正式发布了大语言模型 DeepSeek-R1,并同步开源其模型权重。通过大规模强化学习技术,DeepSeek-R1 显著提升了推理能力,性能媲美顶尖闭源产品,迅速引发全球关注。用户量以惊人的速度飙升,DeepSeek App 在苹果应用商店中美、英等 157 个国家登顶下载榜,日活量快速突破 2000 万,成为全球增长最快的 APP。
Apache Dubbo 作为一款易用且高性能的分布式服务框架,被广泛应用于构建企业级微服务架构,拥有庞大的用户群体。Dubbo 的多语言生态也十分丰富,支持 Java、Golang、Python、Rust、Node.js 等多种编程语言,为开发者提供了极大的灵活性。
为什么选择本地部署 DeepSeek R1?
Cloud Native
目前 DeepSeek 日活量巨大,时常出现“服务器繁忙”的情况。本地部署可以有效避免因服务器负载过高导致的响应延迟或服务中断,确保业务连续性。
为什么要原生部署 DeepSeek R1?
Cloud Native
在目前关于 DeepSeek 部署的热门文章中,ollama 被广泛推荐为一种快速、轻量的部署工具。对于个人开发者或尝鲜者而言,ollama 的便捷性确实足够。然而,对于大模型开发人员和企业用户来说,ollama 的灵活性和性能存在明显不足。原生部署的核心优势如下:
全精度模型支持:ollama 目前尚不支持全精度的 DeepSeek R1 模型,这可能导致模型性能的损失。而原生部署无此限制,能够充分发挥模型的全部潜力,确保推理精度和效果。
原生部署 DeepSeek R1
Cloud Native
显卡:NVIDIA Corporation GA102GL [A10] (rev a1)
----------操作系统:Ubuntu 22.04.5Python 版本:3.11.10PyTorch 版本:2.5.1----------
使用 modelscope 提供的 snapshot_download 函数下载模型。其中,第一个参数为模型名称,cache_dir 参数指定模型的下载路径。
from modelscope import snapshot_downloadmodel_dir = snapshot_download('deepseek-ai/DeepSeek-R1-Distill-Qwen-7B', cache_dir='/home/dubbo/model', revision='master')
# the path of a model. It could be one of the following options:# 1. A local directory path of a turbomind model# 2. The model_id of a lmdeploy-quantized model# 3. The model_id of a model hosted inside a model repositorymodel = 'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B'backend_config = TurbomindEngineConfig(cache_max_entry_count=0.2,max_context_token_num=20544,session_len=20544)gen_config = GenerationConfig(top_p=0.95,temperature=0.6,max_new_tokens=8192,stop_token_ids=[151329, 151336, 151338],do_sample=True# enable sampling)class DeepSeekAiServicer:def __init__(self, model: str, backend_config: TurbomindEngineConfig, gen_config: GenerationConfig):self.llm = pipeline(model, backend_config=backend_config)self.gen_config = gen_configdef chat(self, content):# According to DeepSeek's official recommendations,# Each prompt needs to end with <think>\n# If it is a mathematical reasoning content, it is recommended to include (in both Chinese and English):# Please reason step by step, and put your final answer within \boxed{}.prompts = [{"role": "user","content": "What is the meaning of life?<think>\n"}]# Response Example:# "<think> The meaning of life is to be happy. </think> I think the meaning of life is to be happy."response = self.llm(prompts, gen_config=self.gen_config)return response
这样一来,我们就能快速构建、部署和运行 DeepSeek R1,并且还能根据需求灵活地进行二次开发!
利用 Dubbo 多语言 SDK 无成本接入现有业务
Cloud Native
近期,Dubbo-Python 发布了 3.0.0b1[4]版本,支持 Dubbo 3 的核心基础功能。更重要的是,Dubbo-Python 实现了与 Dubbo-Java 的跨语言调用。此功能有效解决了 AI 服务接入现有业务系统的难题。
此外,使用 Dubbo 进行 AI 开发还有以下优点:
流式 RPC 调用,支持流式推理:Dubbo 提供丰富且灵活的 RPC 调用方式,包括请求-响应和流式调用。通过流式 RPC 调用结合推理框架的流式推理功能,用户可以在推理过程中实时接收部分结果,避免等待完整推理完成后的长时间延迟,同时规避大文本响应可能引发的一系列风险和问题。
使用 Dubbo-Python 为 DeepSeek R1 提供服务暴露能力,其模型部署和调用方式与前述代码基本相同,只是将模型推理改为了流式推理,以更好地支持实时响应和大文本输出。
具体代码如下:
"""The code related to the configuration is the same as above."""class DeepSeekAiServicer:def __init__(self, model: str, backend_config: TurbomindEngineConfig, gen_config: GenerationConfig):self.llm = pipeline(model, backend_config=backend_config)self.gen_config = gen_configdef chat(self, stream):# read request from streamrequest = stream.read()print(f"Received request: {request}")# prepare promptsprompts = [{"role": request.role,"content": request.content + "<think>\n"}]is_think = False# perform streaming inferencefor item in self.llm.stream_infer(prompts, gen_config=gen_config):# update think statusif item.text == "<think>":is_think = Truecontinueelif item.text == "</think>":is_think = Falsecontinue# According to the state of thought, decide the content of the reply.if is_think:# send thoughtstream.write(chat_pb2.ChatReply(think=item.text, answer=""))else:# send answerstream.write(chat_pb2.ChatReply(think="", answer=item.text))stream.done_writing()def build_server_handler():# build a method handlerdeepseek_ai_servicer = DeepSeekAiServicer(model, backend_config, gen_config)method_handler = RpcMethodHandler.server_stream(deepseek_ai_servicer.chat,method_name="chat",request_deserializer=chat_pb2.ChatRequest.FromString,response_serializer=chat_pb2.ChatReply.SerializeToString,)# build a service handlerservice_handler = RpcServiceHandler(service_name="org.apache.dubbo.samples.llm.api.DeepSeekAiService",method_handlers=[method_handler],)return service_handlerif __name__ == '__main__':# build a service handlerservice_handler = build_server_handler()service_config = ServiceConfig(service_handler=service_handler)# Configure the Zookeeper registryregistry_config = RegistryConfig.from_url("zookeeper://zookeeper:2181")bootstrap = Dubbo(registry_config=registry_config)# Create and start the serverbootstrap.create_server(service_config).start()# 30dayssleep(30 * 24 * 60 * 60)
对于现有的业务平台,无需进行复杂的改动,只需构建一个 Consumer 即可完成服务调用,实现无缝对接。
public class Consumer implements CommandLineRunner {private DeepSeekAiService deepSeekAiService;public void run(String... args) throws Exception {ChatRequest request = ChatRequest.newBuilder().setRole("user").setContent("你好,你是谁?你能帮我制定一个dubbo学习计划嘛?").build();deepSeekAiService.chat(request, new StreamObserver<ChatReply>() {private boolean isThinkPrinted = false;private boolean isAnswerPrinted = false;public void onNext(ChatReply value) {printSection("Think", value.getThink(), isThinkPrinted);printSection("Answer", value.getAnswer(), isAnswerPrinted);}public void onError(Throwable t) {System.err.println("Error received: " + t.getMessage());t.printStackTrace();}public void onCompleted() {System.out.println("------------ Chat Completed ------------");}private void printSection(String label, String content, boolean isPrinted) {if (!content.isEmpty()) {if (!isPrinted) {System.out.println("------------- " + label + " -------------");if (Objects.equals("Think", label)){isThinkPrinted = true;} else {isAnswerPrinted = true;}}System.out.print(content);}}});}}
总结
Cloud Native
通过本地部署和原生部署 DeepSeek R1,开发者能够根据业务需求灵活进行模型微调和二次开发,确保业务连续性,同时降低数据泄露风险。
通过 Dubbo 的多语言支持,开发者可以轻松将 DeepSeek R1 接入现有业务系统,实现无缝对接。Dubbo 的流式 RPC 调用功能进一步提升了推理过程的实时响应能力,避免了长时间延迟和大文本响应带来的问题。
总的来说,结合 Dubbo 的多语言 SDK 和 DeepSeek R1 的强大推理能力,开发者可以在保证高性能和高安全性的同时,灵活地进行模型定制和业务集成,为 AI 开发的高效落地提供了强有力的支持。
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-08-07
2025-08-25
2025-10-12
2025-08-23
2025-08-11
2025-09-07
2025-10-14
2025-09-04
2025-09-09
2025-08-18