01
ChatGLM3-6B 簡介
ChatGLM3 是智譜 AI 和清華大學 KEG 實驗室聯合發布的新一代對話預訓練模型。ChatGLM3-6B 是 ChatGLM3 系列中的開源模型,在填寫問卷進行登記后亦允許免費商業使用。
問卷:
引用自: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許可證,專門用于在英特爾的硬件平臺上加速大語言模型(Large Language Model, LLM)推理計算的軟件工具包。它是在原有的 BigDL 框架基礎上,為了應對大語言模型在推理過程中對性能和資源的高要求而設計的。BigDL-LLM 旨在通過優化和硬件加速技術來提高大語言模型的運行效率,減少推理延遲,并降低資源消耗。
本文將詳細介紹基于 BigDL-LLM 在英特爾獨立顯卡上量化和部署 ChatGLM3-6B 模型。
03
部署平臺簡介:
算力魔方是一款可以 DIY 的迷你主機,采用了抽屜式設計,后續組裝、升級、維護只需要拔插模塊。
通過選擇計算模塊的版本,再搭配不同額 IO 模塊可以組成豐富的配置,適應不同場景。性能不夠時,可以升級計算模塊提升算力, IO 接口不匹配時,可以更換 IO 模塊調整功能,而無需重構整個系統。本文在帶有 A380獨立顯卡的算力模方上完成驗證。
04
在英特爾獨立顯卡上部署 ChatGLM3-6B
4.1
搭建開發環境
第一步:請下載并安裝 Visual Studio 2022 Community Edition。安裝時務必選擇“使用 C++的桌面開發”。注意:不要修改默認安裝路徑!
下載鏈接:
第二步:請下載并安裝英特爾獨立顯卡驅動程序。
下載鏈接:
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
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
第二步:執行命令:
# 從本地安裝已下載的.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
第三步:運行范例程序
首先:執行命令,配置環境變量:
conda activate bigdl call "C:Program Files (x86)InteloneAPIsetvars.bat" set SYCL_CACHE_PERSISTENT=1 set BIGDL_LLM_XMX_DISABLED=1
左滑查看更多
若系統中有集成顯卡,請執行下面的命令,保證英特爾獨立顯卡是“xpu”指代的計算設備,
詳情參考:
https://github.com/intel-analytics/BigDL/issues/9768
set ONEAPI_DEVICE_SELECTOR=level_zero:1
左滑查看更多
然后,請下載范例程序并運行:
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模型并實現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() # 執行推理計算,生成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)
運行結果,如下所示:
4.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)InteloneAPIsetvars.bat" set SYCL_CACHE_PERSISTENT=1 set BIGDL_LLM_XMX_DISABLED=1
若系統中有集成顯卡,請執行下面的命令,保證英特爾獨立顯卡是“xpu”指代的計算設備。
詳情參考:
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
并運行:
streamlit run chatglm3_web_demo_gpu.py
左滑查看更多
運行結果如下:
05
總結
BigDL-LLM 工具包簡單易用,僅需三步即可完成開發環境搭建、bigdl-llm[xpu]安裝以及 ChatGLM3-6B 模型的 INT4量化以及在英特爾獨立顯卡上的部署。
審核編輯:劉清
-
英特爾
+關注
關注
61文章
10149瀏覽量
173714 -
語言模型
+關注
關注
0文章
558瀏覽量
10624 -
LLM
+關注
關注
1文章
317瀏覽量
657
原文標題:三步完成在英特爾獨立顯卡上量化和部署 ChatGLM3-6B 模型 | 開發者實戰
文章出處:【微信號:英特爾物聯網,微信公眾號:英特爾物聯網】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
英特爾賦能DeepSeek本地運行,助力汽車升級“最強大腦”
英特爾2025上半年將推24GB顯存銳炫B580顯卡
英特爾聚焦AI座艙
IBM Cloud將部署英特爾Gaudi 3 AI芯片
支持140億參數AI模型,229TOPS!英特爾重磅發布第一代車載獨立顯卡

評論