当前位置: 首页 > news >正文

(笔记+作业)第五期书生大模型实战营---L1G3000 LMDeploy 高效部署量化实践

学员闯关手册:https://aicarrier.feishu.cn/wiki/QdhEwaIINietCak3Y1dcdbLJn3e
课程视频:https://www.bilibili.com/video/BV13U1VYmEUr/
课程文档:https://github.com/InternLM/Tutorial/tree/camp4/docs/L0/Python
关卡作业:https://github.com/InternLM/Tutorial/blob/camp4/docs/L0/Python/task.md
开发机平台:https://studio.intern-ai.org.cn/
开发机平台介绍:https://aicarrier.feishu.cn/wiki/GQ1Qwxb3UiQuewk8BVLcuyiEnHe
书生浦语官网:https://internlm.intern-ai.org.cn/
github网站:https://github.com/internLM/
InternThinker: https://internlm-chat.intern-ai.org.cn/internthinker
快速上手飞书文档:https://www.feishu.cn/hc/zh-CN/articles/945900971706-%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B%E6%96%87%E6%A1%A3
提交作业:https://aicarrier.feishu.cn/share/base/form/shrcnUqshYPt7MdtYRTRpkiOFJd;
作业批改结果:https://aicarrier.feishu.cn/share/base/query/shrcnkNtOS9gPPnC9skiBLlao2c
internLM-Chat 智能体:https://github.com/InternLM/InternLM/blob/main/agent/README_zh-CN.md
lagent:https://lagent.readthedocs.io/zh-cn/latest/tutorials/action.html#id2

在这里插入图片描述

模型推理

#1、环境安装
conda create -n lmdeploy python=3.10
conda activate lmdeploy
pip install lmdeploy
pip install timm==1.0.15 #安装本地推理需要的依赖#2.1、新建和编辑本地推理文件bendituili.py
python bendituili.py
#2.2、新建和编辑指定推理引擎yinqing.py
python yinqing.py
#2.3、VLM 推理(Visual Language Models
python vlm.py
#lixian.py
python lixian.py

本地推理

#bendituili.py
import lmdeploy
from lmdeploy import GenerationConfigpipe = lmdeploy.pipeline("/root/share/new_models/InternVL3/InternVL3-1B")
response = pipe(prompts=["Hi, pls intro yourself", "Shanghai is"],gen_config=GenerationConfig(max_new_tokens=1024,top_p=0.8,top_k=40,temperature=0.6))
print(response)

在这里插入图片描述

指定推理引擎

#yinqing.py
### TurbomindEngineConfig推理引擎from lmdeploy import pipeline, TurbomindEngineConfig
from lmdeploy import GenerationConfigpipe = pipeline('/root/share/new_models/InternVL3/InternVL3-1B',backend_config=TurbomindEngineConfig(max_batch_size=32,enable_prefix_caching=True,cache_max_entry_count=0.8,session_len=8192,))
response = pipe(prompts=["Hi, pls intro yourself", "Shanghai is"],gen_config=GenerationConfig(max_new_tokens=1024,top_p=0.8,top_k=40,temperature=0.6))
print(response)### PytorchEngineConfig推理引擎from lmdeploy import pipeline, PytorchEngineConfig
from lmdeploy import GenerationConfigpipe = pipeline('/root/share/new_models/InternVL3/InternVL3-1B',backend_config=PytorchEngineConfig(max_batch_size=32,enable_prefix_caching=True,cache_max_entry_count=0.8,session_len=8192,))response = pipe(prompts=["Hi, pls intro yourself", "Shanghai is"],gen_config=GenerationConfig(max_new_tokens=1024,top_p=0.8,top_k=40,temperature=0.6))
print(response)

在这里插入图片描述

VLM 推理(Visual Language Models

#python vlm.py
from lmdeploy import pipeline, VisionConfig
from lmdeploy.vl import load_imagepipe = pipeline('/root/share/new_models/InternVL3/InternVL3-1B',vision_config=VisionConfig(max_batch_size=8))image = load_image('https://raw.githubusercontent.com/open-mmlab/mmdeploy/main/tests/data/tiger.jpeg')
response = pipe(('describe this image', image))
print(response)

在这里插入图片描述

大语言模型(LLMs)部署

离线部署

#lixian.py
import lmdeploy
from lmdeploy import GenerationConfig
pipe = lmdeploy.pipeline("/root/share/new_models/internlm3/internlm3-8b-instruct")
response = pipe(prompts=["Hi, pls intro yourself", "Shanghai is"],gen_config=GenerationConfig(max_new_tokens=1024,top_p=0.8,top_k=40,temperature=0.6))
print(response)

在这里插入图片描述

部署类OpenAI 服务

使用类openai方式

(i) 不启用权限鉴别(api-key)

#noapi.py
from openai import OpenAI
client = OpenAI(api_key='none',# 若未启用鉴权,可填任意值(如 "none")base_url="http://0.0.0.0:23333/v1"
)
model_name = client.models.list().data[0].id
response = client.chat.completions.create(model=model_name,messages=[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": " provide three suggestions about time management"},],temperature=0.8,top_p=0.8
)
print(response)

报错
在这里插入图片描述

模型量化

conda activate lmdeploy
pip uninstall -y datasets && pip install --no-cache-dir "datasets==2.19.2" #1、量化internlm2-chat-7b的命令
export HF_MODEL=/root/share/model_repos/internlm2-chat-7b
export WORK_DIR=/root/internlm2-chat-7b-4bitlmdeploy lite auto_awq $HF_MODEL   --calib-dataset 'ptb'   --calib-samples 128   --calib-seqlen 2048   --w-bits 4   --w-group-size 128   --batch-size 1   --work-dir $WORK_DIR#2、量化InternVL3-1B的命令
lmdeploy lite auto_awq /root/share/new_models/InternVL3/InternVL3-1B \--work-dir /root/InternVL3-1B-4bit#3、W8A8量化
pip install lmdeploy[all]
#3.1、int8量化
export HF_MODEL=/root/share/model_repos/internlm2-chat-7b
export WORK_DIR=/root/internlm2-chat-7b-4bitlmdeploy lite smooth_quant \$HF_MODEL \--work-dir $WORK_DIR \--quant-dtype int8#3.2、fp8量化
lmdeploy lite smooth_quant $HF_MODEL --work-dir $WORK_DIR --quant-dtype fp8#3.3、Key-Value(KV) Cache 量化
#kvc.py
from lmdeploy import pipeline, TurbomindEngineConfig
engine_config = TurbomindEngineConfig(quant_policy=8)
pipe = pipeline("/root/share/model_repos/internlm2-chat-7b", backend_config=engine_config)
response = pipe(["Hi, pls intro yourself", "Shanghai is"])
print(response)

1、量化internlm2-chat-7b的命令
在这里插入图片描述
在这里插入图片描述

3.1、int8量化

在这里插入图片描述

3.3、Key-Value(KV) Cache 量化
在这里插入图片描述

http://www.dtcms.com/a/282043.html

相关文章:

  • spring容器的bean是单例还是多例的?线程安全吗?
  • 智慧公厕系统打造洁净、安全的公共空间
  • PyTorch 参数初始化详解:从理论到实践
  • 使用EF Core修改数据:Update方法与SaveChanges的深度解析
  • 【一文解决】块级元素,行内元素,行内块元素
  • 多目标优化|HKELM混合核极限学习机+NSGAII算法工艺参数优化、工程设计优化,四目标(最大化输出y1、最小化输出y2,y3,y4),Matlab完整源码
  • 自启动策略调研
  • 【前端】Vue3 前端项目实现动态显示当前系统时间
  • C++11迭代器改进:深入理解std::begin、std::end、std::next与std::prev
  • 从理论到实践:操作系统进程状态的核心逻辑与 Linux 实现
  • Mysql系列--0、数据库基础
  • react 路由 react-router-dom
  • 代谢通路分析:意义、方法与解读
  • 实训十——路由器与TCP/IP模型
  • 筑牢网络安全防线:DDoS/CC 攻击全链路防护技术解析
  • IPv6
  • 构建高可用微服务架构:Istio与Linkerd的深度对比与实战
  • [论文阅读] 人工智能 + 软件工程 | 开源软件中的GenAI自白:开发者如何用、项目如何管、代码质量受何影响?
  • (新手友好)MySQL学习笔记(完):事务和锁
  • 混合参数等效模型
  • 二、CV_AlexNet
  • 牛客:HJ25 数据分类处理[华为机考][哈希][字符串]
  • nextjs+react项目如何代理本地请求解决跨域
  • NSSCTF CVE版签到
  • Win11专业工作站版安装配置要求
  • 实训十一——网络通信原理
  • 【Java】【力扣】94.二叉树的中序遍历
  • 通过 Docker 安装 MySQL
  • 手撕Spring底层系列之:IOC、AOP
  • Web前端性能优化原理与方法