01
ChatGLM3-6B 簡介
ChatGLM3 是智譜 AI 和清華大學(xué) KEG 實(shí)驗(yàn)室聯(lián)合發(fā)布的新一代對話預(yù)訓(xùn)練模型。ChatGLM3-6B 是 ChatGLM3 系列中的開源模型,在填寫問卷進(jìn)行登記后亦允許免費(fèi)商業(yè)使用。
問卷:
引用自:https://github.com/THUDM/ChatGLM3
請使用命令,將 ChatGLM3-6B 模型下載到本地 (例如,保存到 D 盤) :
git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
左滑查看更多
02
BigDL-LLM 簡介
BigDL-LLM 是開源,遵循 Apache 2.0許可證,專門用于在英特爾的硬件平臺(tái)上加速大語言模型(Large Language Model, LLM)推理計(jì)算的軟件工具包。它是在原有的 BigDL 框架基礎(chǔ)上,為了應(yīng)對大語言模型在推理過程中對性能和資源的高要求而設(shè)計(jì)的。BigDL-LLM 旨在通過優(yōu)化和硬件加速技術(shù)來提高大語言模型的運(yùn)行效率,減少推理延遲,并降低資源消耗。
本文將詳細(xì)介紹基于 BigDL-LLM 在英特爾獨(dú)立顯卡上量化和部署 ChatGLM3-6B 模型。
03
部署平臺(tái)簡介:
算力魔方是一款可以 DIY 的迷你主機(jī),采用了抽屜式設(shè)計(jì),后續(xù)組裝、升級、維護(hù)只需要拔插模塊。
通過選擇計(jì)算模塊的版本,再搭配不同額 IO 模塊可以組成豐富的配置,適應(yīng)不同場景。性能不夠時(shí),可以升級計(jì)算模塊提升算力, IO 接口不匹配時(shí),可以更換 IO 模塊調(diào)整功能,而無需重構(gòu)整個(gè)系統(tǒng)。本文在帶有 A380獨(dú)立顯卡的算力模方上完成驗(yàn)證。
04
在英特爾獨(dú)立顯卡上部署 ChatGLM3-6B
4.1
搭建開發(fā)環(huán)境
第一步:請下載并安裝 Visual Studio 2022 Community Edition。安裝時(shí)務(wù)必選擇“使用 C++的桌面開發(fā)”。注意:不要修改默認(rèn)安裝路徑!
下載鏈接:
第二步:請下載并安裝英特爾獨(dú)立顯卡驅(qū)動(dòng)程序。
下載鏈接:
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,然后用下面的命令創(chuàng)建名為“bigdl”的虛擬環(huán)境。
conda create -n bigdl python=3.9 libuv conda activate bigdl
4.2
安裝 BigDL-LLM[xpu]
第一步:用下載器 (例如:迅雷) 下載*.whl 安裝包到本地。
下載鏈接:
https://intel-extension-for-pytorch.s3.amazonaws.com/ipex_stable/xpu/torch-2.1.0a0%2Bcxx11.abi-cp39-cp39-win_amd64.whl
https://intel-extension-for-pytorch.s3.amazonaws.com/ipex_stable/xpu/torchvision-0.16.0a0%2Bcxx11.abi-cp39-cp39-win_amd64.whl
https://intel-extension-for-pytorch.s3.amazonaws.com/ipex_stable/xpu/intel_extension_for_pytorch-2.1.10%2Bxpu-cp39-cp39-win_amd64.whl
第二步:執(zhí)行命令:
# 從本地安裝已下載的.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 # 安裝支持英特爾顯卡的bigdl-llm 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
4.3
第三步:運(yùn)行范例程序
首先:執(zhí)行命令,配置環(huán)境變量:
conda activate bigdl call "C:Program Files (x86)InteloneAPIsetvars.bat" set SYCL_CACHE_PERSISTENT=1 set BIGDL_LLM_XMX_DISABLED=1
左滑查看更多
若系統(tǒng)中有集成顯卡,請執(zhí)行下面的命令,保證英特爾獨(dú)立顯卡是“xpu”指代的計(jì)算設(shè)備,
詳情參考:
https://github.com/intel-analytics/BigDL/issues/9768
set ONEAPI_DEVICE_SELECTOR=level_zero:1
左滑查看更多
然后,請下載范例程序并運(yùn)行:
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|> {prompt} <|assistant|>" # 請指定chatglm3-6b的本地路徑 model_path = "d:/chatglm3-6b" # 載入ChatGLM3-6B模型并實(shí)現(xiàn)INT4量化 model = AutoModel.from_pretrained(model_path, load_in_4bit=True, trust_remote_code=True) # run the optimized model on Intel GPU model = model.to('xpu') # 載入tokenizer tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True) # 制作ChatGLM3格式提示詞 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() # 執(zhí)行推理計(jì)算,生成Tokens output = model.generate(input_ids,max_new_tokens=32) end = time.time() # 對生成Tokens解碼并顯示 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)
運(yùn)行結(jié)果,如下所示:
4.4
運(yùn)行 ChatGLM3-6B WebUI demo
首先,請先安裝依賴軟件包:
pip install gradio mdtex2html streamlit -i https://mirrors.aliyun.com/pypi/simple/
然后,運(yùn)行命令,配置環(huán)境變量:
conda activate bigdl call "C:Program Files (x86)InteloneAPIsetvars.bat" set SYCL_CACHE_PERSISTENT=1 set BIGDL_LLM_XMX_DISABLED=1
若系統(tǒng)中有集成顯卡,請執(zhí)行下面的命令,保證英特爾獨(dú)立顯卡是“xpu”指代的計(jì)算設(shè)備。
詳情參考:
https://github.com/intel-analytics/BigDL/issues/9768
set ONEAPI_DEVICE_SELECTOR=level_zero:1
最后,請下載范例程序:
https://gitee.com/Pauntech/chat-glm3/blob/master/chatglm3_web_demo_gpu.py
并運(yùn)行:
streamlit run chatglm3_web_demo_gpu.py
左滑查看更多
運(yùn)行結(jié)果如下:
05
總結(jié)
BigDL-LLM 工具包簡單易用,僅需三步即可完成開發(fā)環(huán)境搭建、bigdl-llm[xpu]安裝以及 ChatGLM3-6B 模型的 INT4量化以及在英特爾獨(dú)立顯卡上的部署。
審核編輯:劉清
-
英特爾
+關(guān)注
關(guān)注
61文章
10009瀏覽量
172344 -
語言模型
+關(guān)注
關(guān)注
0文章
538瀏覽量
10342 -
LLM
+關(guān)注
關(guān)注
0文章
299瀏覽量
400
原文標(biāo)題:三步完成在英特爾獨(dú)立顯卡上量化和部署 ChatGLM3-6B 模型 | 開發(fā)者實(shí)戰(zhàn)
文章出處:【微信號(hào):英特爾物聯(lián)網(wǎng),微信公眾號(hào):英特爾物聯(lián)網(wǎng)】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
英特爾2025上半年將推24GB顯存銳炫B580顯卡
使用英特爾AI PC為YOLO模型訓(xùn)練加速
![使用<b class='flag-5'>英特爾</b>AI PC為YOLO<b class='flag-5'>模型</b>訓(xùn)練加速](https://file1.elecfans.com/web3/M00/01/9A/wKgZPGdWp1iASluyAAArjGvPk00572.png)
使用PyTorch在英特爾獨(dú)立顯卡上訓(xùn)練模型
![使用PyTorch<b class='flag-5'>在</b><b class='flag-5'>英特爾</b><b class='flag-5'>獨(dú)立</b><b class='flag-5'>顯卡</b><b class='flag-5'>上</b>訓(xùn)練<b class='flag-5'>模型</b>](https://file1.elecfans.com/web2/M00/0B/8F/wKgaomckc96AFGydAAAsWk7tVJg485.png)
英特爾聚焦AI座艙
chatglm2-6b在P40上做LORA微調(diào)
![<b class='flag-5'>chatglm2-6b</b><b class='flag-5'>在</b>P40<b class='flag-5'>上</b>做LORA微調(diào)](https://file1.elecfans.com//web2/M00/03/4B/wKgaoma7I3aASvk2AADHmpxfTLQ074.png)
支持140億參數(shù)AI模型,229TOPS!英特爾重磅發(fā)布第一代車載獨(dú)立顯卡
![支持140億參數(shù)AI<b class='flag-5'>模型</b>,229TOPS!<b class='flag-5'>英特爾</b>重磅發(fā)布第一代車載<b class='flag-5'>獨(dú)立</b><b class='flag-5'>顯卡</b>](https://file1.elecfans.com/web2/M00/02/77/wKgaoma15SGAa8DKAA7dPTHZvh8710.png)
英特爾發(fā)布第一代車載銳炫獨(dú)立顯卡
【AIBOX】裝在小盒子的AI足夠強(qiáng)嗎?
![【AIBOX】裝在小盒子的AI足夠強(qiáng)嗎?](https://file.elecfans.com/web2/M00/10/E9/pYYBAGEfInyAb9dQAABH4pzjonI981.jpg)
網(wǎng)友成功在Arm架構(gòu)平臺(tái)運(yùn)行英特爾銳炫A750顯卡
簡單三步使用OpenVINO?搞定ChatGLM3的本地部署
![簡單<b class='flag-5'>三步</b>使用OpenVINO?搞定<b class='flag-5'>ChatGLM3</b>的本地<b class='flag-5'>部署</b>](https://file1.elecfans.com/web2/M00/C6/E9/wKgZomYNLWyAPg4eAAAQkQ6glec616.png)
浪潮信息"源2.0"大模型YuanChat支持英特爾最新商用AI PC
![浪潮信息"源2.0"大<b class='flag-5'>模型</b>YuanChat支持<b class='flag-5'>英特爾</b>最新商用AI PC](https://file1.elecfans.com//web2/M00/C6/02/wKgZomYEMqWAGh5CAAGNLjfb0sc454.jpg)
評論