微信扫码
添加专属顾问
我要投稿
Apache Dubbo携手DeepSeek R1,释放AI大模型的无限潜力。核心内容:1. DeepSeek R1大模型发布及其开源模型权重2. Apache Dubbo多语言SDK助力DeepSeek R1企业级部署3. 本地部署DeepSeek R1的优势及原生部署实践指南
作者:陈子康,Apache Dubbo Contributor
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.5
Python 版本:3.11.10
PyTorch 版本:2.5.1
----------
使用 modelscope 提供的 snapshot_download 函数下载模型。其中,第一个参数为模型名称,cache_dir 参数指定模型的下载路径。
from modelscope import snapshot_download
model_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 repository
model = '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_config
def 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_config
def chat(self, stream):
# read request from stream
request = stream.read()
print(f"Received request: {request}")
# prepare prompts
prompts = [{
"role": request.role,
"content": request.content + "<think>\n"
}]
is_think = False
# perform streaming inference
for item in self.llm.stream_infer(prompts, gen_config=gen_config):
# update think status
if item.text == "<think>":
is_think = True
continue
elif item.text == "</think>":
is_think = False
continue
# According to the state of thought, decide the content of the reply.
if is_think:
# send thought
stream.write(chat_pb2.ChatReply(think=item.text, answer=""))
else:
# send answer
stream.write(chat_pb2.ChatReply(think="", answer=item.text))
stream.done_writing()
def build_server_handler():
# build a method handler
deepseek_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 handler
service_handler = RpcServiceHandler(
service_name="org.apache.dubbo.samples.llm.api.DeepSeekAiService",
method_handlers=[method_handler],
)
return service_handler
if __name__ == '__main__':
# build a service handler
service_handler = build_server_handler()
service_config = ServiceConfig(service_handler=service_handler)
# Configure the Zookeeper registry
registry_config = RegistryConfig.from_url("zookeeper://zookeeper:2181")
bootstrap = Dubbo(registry_config=registry_config)
# Create and start the server
bootstrap.create_server(service_config).start()
# 30days
sleep(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 开发的高效落地提供了强有力的支持。
如果您对 Dubbo 的使用有任何疑问或需要进一步的技术支持,欢迎联系 Dubbo 社区。
官网:https://dubbo.apache.org
GitHub:https://github.com/apache/dubbo
Dubbo Python:https://github.com/apache/dubbo-python
[1] DeepSeek官方仓库
[2] LMDeploy
[3] NVIDIA 容器工具包
[4] 3.0.0b1
https://github.com/apache/dubbo-python/releases/tag/3.0.0b1
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-02-15
单卡复现 DeepSeek R1 Zero教程来了!
2025-02-15
申请API-KEY,通过接口使用DeepSeek服务
2025-02-15
DeepSeek零门槛三步极速部署指南,注册秒过,对话零延迟!
2025-02-15
大模型应用部署过程中流量管控的常见需求和应对方案
2025-02-15
AI应用开发先了解这些概念:智能体、LLM、RAG、提示词工程
2025-02-15
腾讯云TI平台和HAI部署DeepSeek的步骤及其区别
2025-02-15
Chain-of-Action (行动链):从Agent工作流到Agent模型
2025-02-14
DeepSeek:没用CUDA,没用NVlink,AMD率先拥抱
2025-02-04
2025-02-04
2024-09-18
2024-07-11
2024-07-11
2024-07-26
2024-07-09
2025-01-27
2024-12-29
2025-02-01
2025-02-10
2025-02-10
2025-02-09
2025-02-05
2025-01-24
2025-01-22
2025-01-14
2025-01-12