日期:2025/04/03 00:49来源:未知 人气:55
ChatGLM3是智谱AI和清华大学KEG实验室联合发布的新一代对话预训练模型。ChatGLM3-6B 是 ChatGLM3 系列中的开源模型 ,在填写问卷进行登记后亦允许免费商业使用 。
引用自:https://github.com/THUDM/ChatGLM3
请使用命令,将ChatGLM3-6B模型下载到本地(例如,保存到D盘):
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
**
**
BigDL-LLM是开源,遵循Apache 2.0许可证,专门用于在英特尔®的硬件平台上加速大语言模型(Large Language Model, LLM)推理计算的软件工具包。它是在原有的BigDL框架基础上,为了应对大语言模型在推理过程中对性能和资源的高要求而设计的。BigDL-LLM旨在通过优化和硬件加速技术来提高大语言模型的运行效率,减少推理延迟,并降低资源消耗。
GitHub:https://github.com/intel-analytics/BigDL
接下来将详细介绍基于BigDL-LLM在英特尔®独立显卡上量化和部署ChatGLM3-6B模型。
算力魔方 ®是一项创新的技术设备解决方案 ,搭配上英特尔最新开发的OpenVINO™ AI功能套件,算力魔方®可以为用户带来高性能的计算资源和强大的算法支持。
不仅如此,算力魔方®通过搭建积木的设计方式,在其小巧的外观下具备了高度的灵活性和可扩展性。这种设计能使用户轻松地开发和部署他们的算法和模型。无论是在人工智能领域还是计算机视觉领域等等,算力魔方®都能够为用户提供高效、可靠的计算支持。
128mm128mm97mm, 约1.7KG
可根据需求选择CPU模块并搭载Intel™ARC独立显卡,使用OpenVINO™优化和部署人工智能(AI)推理的开源工具平台,提高计算机视觉、自动语言识别、自然语言处理和其他常见任务的深度学习性能。
本次用到的部署平台为“算力魔方®X系列”。X系列支持一层计算模块与两层IO模块,还包含一个支持两个相互物理隔离的双机系统。可以通过更为丰富IO模块的变化来匹配不同的场景,而且支持GPU模块来加入独立显卡,目前支持的独立显卡如下图所示↓。
1,搭建开发环境:
****第一步 :请下载并安装Visual Studio 2022 Community Edition。安装时务必选择“使用C++的桌面开发”,并不要修改安装默认路径**** 。
下载链接:https://visualstudio.microsoft.com/zh-hans/downloads/
第二步 :请下载并安装英特尔独立显卡驱动程序。下载链接:https://www.intel.cn/content/www/cn/zh/download/785597/intel-arc-iris-xe-graphics-windows.html。
第三步 :请下载并安装Intel® oneAPI Base Toolkit。下载链接:https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html。
第四步 :请下载并安装Anaconda,然后用下面的命令创建名为“bigdl”的虚拟环境。
conda create -n bigdl python=3.9 libuv
conda activate bigdl
2,安装BigDL-LLM[xpu]:****
第一步 :用下载器(例如:迅雷)下载*.whl安装包到本地。下载链接:
第二步 :执行命令:
pip install torch-2.1.0a0+cxx11.abi-cp39-cp39-win_amd64.whl
pip install torchvision-0.16.0a0+cxx11.abi-cp39-cp39-win_amd64.whl
pip install intel_extension_for_pytorch-2.1.10+xpu-cp39-cp39-win_amd64.whl
pip install --pre --upgrade bigdl-llm[xpu] -i https://mirrors.aliyun.com/pypi/simple/
详情参考:
https://bigdl.readthedocs.io/en/latest/doc/LLM/Overview/install_gpu.html
3,运行范例程序 :
首先:执行命令,配置环境变量:
conda activate bigdl
call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
set SYCL_CACHE_PERSISTENT=1
set BIGDL_LLM_XMX_DISABLED=1
set ONEAPI_DEVICE_SELECTOR=level_zero:1
详情参考:https://github.com/intel-analytics/BigDL/issues/9768
然后,请下载范例程序并运行:https://gitee.com/Pauntech/chat-glm3/blob/master/chatglm3_infer_gpu.py
import time
from bigdl.llm.transformers import AutoModel
from transformers import AutoTokenizer
import intel_extension_for_pytorch as ipex
import torch
CHATGLM_V3_PROMPT_FORMAT="<|user|>\n{prompt}\n<|assistant|>"
model_path ="d:/chatglm3-6b"
model = AutoModel.from_pretrained(model_path,
load_in_4bit=True,
trust_remote_code=True)
model = model.to('xpu')
tokenizer = AutoTokenizer.from_pretrained(model_path,
trust_remote_code=True)
prompt =CHATGLM_V3_PROMPT_FORMAT.format(prompt="What is Intel?")
input_ids = tokenizer.encode(prompt, return_tensors="pt")
input_ids = input_ids.to('xpu')
st = time.time()
output = model.generate(input_ids,max_new_tokens=32)
end = time.time()
output_str = tokenizer.decode(output[0], skip_special_tokens=True)
print(f'Inference time: {end-st} s')
print('-'20, 'Prompt', '-'20)
print(prompt)
print('-'20, 'Output', '-'20)
print(output_str)
运行结果,如下所示:
4, 在集成显卡上运行ChatGLM3-6B WebUI demo:
首先,请先安装依赖软件包:
pip install gradio mdtex2html streamlit -i https://mirrors.aliyun.com/pypi/simple/
然后,运行命令,配置环境变量:
conda activate bigdl
call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
set SYCL_CACHE_PERSISTENT=1
set BIGDL_LLM_XMX_DISABLED=1
set ONEAPI_DEVICE_SELECTOR=level_zero:1
保证英特尔独立显卡是“xpu”指代的计算设备
streamlit run chatglm3_web_demo_gpu.py
运行结果如下:
00:39
BigDL-LLM工具包简单易用,仅需以上三步即可完成开发环境搭建、bigdl-llm[xpu]安装以及ChatGLM3-6B模型的INT4量化以及在英特尔®独立显卡上的部署。
算力魔方AIPC提供企业及与工业级温度支持,多种不同的配置可选,实现丰富的算力组合,同时提供整机的贴牌与模块定制服务。实现多种行业和场景解决方案!