使用开源通义千问模型(Qwen)搭建自己的大模型服务

目标

1、使用开源的大模型服务搭建属于自己的模型服务;

2、调优自己的大模型;

选型

采用通义千问模型,https://github.com/QwenLM/Qwen

步骤

1、下载模型文件

开源模型库:https://www.modelscope.cn/models

bash 复制代码
mkdir -p /data/qwen
cd /data/qwen
git clone --depth 1 https://www.modelscope.cn/qwen/Qwen-14B-Chat.git
# 小内存机器下载1.8B参数的,14B需要几十内存
# git clone --depth 1 https://www.modelscope.cn/qwen/Qwen-1_8B-Chat.git

2、下载使用docker 镜像

bash 复制代码
docker pull qwenllm/qwen

3、启动脚本

https://github.com/QwenLM/Qwen/blob/main/docker/docker_web_demo.sh

bash 复制代码
# 修改如下内容
IMAGE_NAME=qwenllm/qwen
QWEN_CHECKPOINT_PATH=/data/qwen/Qwen-14B-Chat
PORT=8000
CONTAINER_NAME=qwen

4、运行

访问http://localhost:8080 即可

bash 复制代码
sh docker_web_demo.sh

输出如下,可以查看容器日志是否报错。

复制代码
Successfully started web demo. Open '...' to try!
Run `docker logs ...` to check demo status.
Run `docker rm -f ...` to stop and remove the demo.

效果

文档参考

https://github.com/QwenLM/Qwen/blob/main/README_CN.md

常见问题

1、运行报错

去掉docker_web_demo.sh中--gpus all

docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].

2、Error while deserializing header: HeaderTooLarge

先安装yum install git-lfs 在下载模型文件,模型是git大文件管理,需要git-lfs的支持。

Traceback (most recent call last):

File "web_demo.py", line 209, in <module>

main()

File "web_demo.py", line 203, in main

model, tokenizer, config = _load_model_tokenizer(args)

File "web_demo.py", line 50, in _load_model_tokenizer

model = AutoModelForCausalLM.from_pretrained(

File "/usr/local/lib/python3.8/dist-packages/transformers/models/auto/auto_factory.py", line 511, in from_pretrained

return model_class.from_pretrained(

File "/usr/local/lib/python3.8/dist-packages/transformers/modeling_utils.py", line 3091, in from_pretrained

) = cls._load_pretrained_model(

File "/usr/local/lib/python3.8/dist-packages/transformers/modeling_utils.py", line 3456, in _load_pretrained_model

state_dict = load_state_dict(shard_file)

File "/usr/local/lib/python3.8/dist-packages/transformers/modeling_utils.py", line 458, in load_state_dict

with safe_open(checkpoint_file, framework="pt") as f:

safetensors_rust.SafetensorError: Error while deserializing header: HeaderTooLarge

3、Cannot allocate memory

内存不足,可以尝试选择1_8B小参数的模型。

相关推荐
Shining05961 小时前
推理引擎方向(二)《大模型原理与结构》
人工智能·rnn·深度学习·学习·其他·大模型·infinitensor
HinsCoder6 小时前
【OpenClaw】——小龙虾极简接入Discord教程
ai·大模型·agent·discord·channel·openclaw·龙虾
python零基础入门小白7 小时前
多智能体强化学习:从基础到实战,掌握协作与竞争的艺术!
人工智能·学习·chatgpt·大模型·产品经理·ai大模型·大模型学习
xixixi777779 小时前
拥抱AI大模型时代:开发者如何利用智能编程工具提升效率
人工智能·python·ai·大模型·aigc·代码
xixixi7777710 小时前
2026网络安全新战场:AI对抗、勒索软件升级与防御实战
人工智能·安全·机器学习·信息安全·大模型
示申○言舌10 小时前
基于知识库(RAG)系统打造由大模型(LLM)驱动NPC游戏的技术设想
游戏·unity·大模型·知识库·rag·智能npc·npc记忆
CoderJia程序员甲13 小时前
GitHub 热榜项目 - 日榜(2026-03-13)
ai·大模型·llm·github·ai教程
WWZZ202513 小时前
具身智能入门Isaac Sim——机器人设置-初级设计轮式机器人3
机器人·大模型·具身智能·isaac
智海观潮14 小时前
只用一周时间通过AI工具重写Next.js,Cloudflare推出vinext重建前端开发边界
开发语言·javascript·人工智能·大模型·web
翔云12345615 小时前
OpenClaw与大模型通信过程:详细图文教程(2026最新)
ai·大模型·openclaw