文章首發(fā)及后續(xù)更新:https://mwhls.top/4500.html,無(wú)圖/無(wú)目錄/格式錯(cuò)誤/更多相關(guān)請(qǐng)至首發(fā)頁(yè)查看。
新的更新內(nèi)容請(qǐng)到mwhls.top查看。
歡迎提出任何疑問(wèn)及批評(píng),非常感謝!
服務(wù)部署匯總
本來(lái)這篇是為了打比賽寫的,寫著寫著發(fā)現(xiàn)兩個(gè)問(wèn)題,AI部署連續(xù)幾篇,等我比賽打完再發(fā)模型都不知道更新到哪個(gè)版本了。所以就直接發(fā)了。題圖隨便放個(gè),我之后部屬個(gè)文生圖讓它生成個(gè)。嘻嘻,蹭個(gè)熱度
有問(wèn)題推薦去 GitHub Issue,當(dāng)然評(píng)論問(wèn)我也行。2023/05/06更新:增加 API 調(diào)用及
ChatGLM
清華開源大模型-ChatGLM-2023/04/29
- ChatGLM_GitHub:THUDM/GLM: GLM (General Language Model)
- ChatGLM-6B_GitHub:THUDM/ChatGLM-6B: ChatGLM-6B: An Open Bilingual Dialogue Language Model | 開源雙語(yǔ)對(duì)話語(yǔ)言模型
- 聯(lián)系作者或可商用:關(guān)于ChatGLM模型的商用 · Issue #799 · THUDM/ChatGLM-6B
ChatGLM-6B 環(huán)境配置及啟動(dòng)-2023/04/29
- GitHub 官方教程
- 創(chuàng)建虛擬環(huán)境:
conda create --name ChatGLM python=3.8
- 進(jìn)入虛擬環(huán)境:
conda activate ChatGLM
- 下載源碼:https://github.com/THUDM/ChatGLM-6B/archive/refs/heads/main.zip
- 進(jìn)入該目錄,安裝依賴:
pip install -r requirements.txt
- 安裝 Torch:
conda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch
- 這是我環(huán)境可以用的,不會(huì)的可以百度 PyTorch 安裝。
- 下載模型
- 注:我下載的是int8量化的。
-
清華云
- 這里會(huì)缺少文件,下載后還要在HuggingFace里下載除了最大文件以外的所有文件(有一個(gè)重復(fù),無(wú)需下載)。
- HuggingFace
- 文件修改:修改 web_demo.py 文件的開頭幾行如下,
pretrain_path
指的是模型文件夾的絕對(duì)路徑。 - 運(yùn)行 web_demo.py,成功
pretrain_path = r"F:\0_DATA\1_DATA\CODE\PYTHON\202304_RJB_C4\ChatGLM\chatglm-6b-int8"
tokenizer = AutoTokenizer.from_pretrained(pretrain_path, trust_remote_code=True)
model = AutoModel.from_pretrained(pretrain_path, trust_remote_code=True).half().cuda()
ChatGLM Web demo 源碼閱讀-2023/04/30
- 涉及猜想,因?yàn)榭梢栽囧e(cuò),所以有的地方可能不準(zhǔn)確。
- 小加了兩個(gè)模式,一個(gè)精準(zhǔn)一個(gè)創(chuàng)造性,類似New Bing。
from transformers import AutoModel, AutoTokenizer
import gradio as gr
import mdtex2html
import os
pretrain_path = "chatglm-6b-int8"
pretrain_path = os.path.abspath(pretrain_path)
tokenizer = AutoTokenizer.from_pretrained(pretrain_path, trust_remote_code=True)
model = AutoModel.from_pretrained(pretrain_path, trust_remote_code=True).half().cuda()
model = model.eval()
"""Override Chatbot.postprocess"""
# 原來(lái)self還可以這樣用,學(xué)習(xí)了
def postprocess(self, y):
if y is None:
return []
for i, (message, response) in enumerate(y):
y[i] = (
None if message is None else mdtex2html.convert((message)),
None if response is None else mdtex2html.convert(response),
)
return y
gr.Chatbot.postprocess = postprocess
def parse_text(text):
# markdown代碼轉(zhuǎn)html,我猜我博客的插件也是這樣
"""copy from https://github.com/GaiZhenbiao/ChuanhuChatGPT/"""
lines = text.split("\n")
lines = [line for line in lines if line != ""]
count = 0
for i, line in enumerate(lines):
if "```" in line:
count += 1
items = line.split('`')
if count % 2 == 1:
lines[i] = f'<pre><code class="language-{items[-1]}">'
else:
lines[i] = f'<br></code></pre>'
else:
if i > 0:
if count % 2 == 1:
line = line.replace("`", "\`")
line = line.replace("<", "<")
line = line.replace(">", ">")
line = line.replace(" ", " ")
line = line.replace("*", "*")
line = line.replace("_", "_")
line = line.replace("-", "-")
line = line.replace(".", ".")
line = line.replace("!", "!")
line = line.replace("(", "(")
line = line.replace(")", ")")
line = line.replace("$", "$")
lines[i] = "<br>"+line
text = "".join(lines)
return text
# def set_mode(temperatrue_value, top_p_value):
# return gr.Slider.update(value=temperatrue_value), gr.update(value=top_p_value)
def set_mode(radio_mode):
# 不理解,為什么點(diǎn)擊按鈕就不能傳過(guò)去,用這玩意就可以傳
mode = {"創(chuàng)造性": [0.95, 0.7],
"精準(zhǔn)": [0.01, 0.01]}
return gr.Slider.update(value=mode[radio_mode][0]), gr.update(value=mode[radio_mode][1])
def predict(input, chatbot, max_length, top_p, temperature, history):
# 新增一項(xiàng)
chatbot.append((parse_text(input), ""))
for response, history in model.stream_chat(tokenizer, input, history, max_length=max_length, top_p=top_p,
temperature=temperature):
# 新增的那項(xiàng)修改為推理結(jié)果
chatbot[-1] = (parse_text(input), parse_text(response))
yield chatbot, history
def reset_user_input():
return gr.update(value='')
def reset_state():
return [], []
with gr.Blocks() as demo:
gr.HTML("""<h1 align="center">ChatGLM</h1>""")
# 聊天記錄器
chatbot = gr.Chatbot()
# 同一行內(nèi),第一行
with gr.Row():
# 第一列
with gr.Column(scale=4):
# 第一列第一行,輸入框
with gr.Column(scale=12):
user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=10).style(
container=False)
# 第一列第二行,提交按鈕
with gr.Column(min_width=32, scale=1):
submitBtn = gr.Button("Submit", variant="primary")
# 第二列
with gr.Column(scale=1):
with gr.Row():
# with gr.Column():
# button_accuracy_mode = gr.Button("精準(zhǔn)")
# with gr.Column():
# button_creative_mode = gr.Button("創(chuàng)造性")
radio_mode = gr.Radio(label="對(duì)話模式", choices=["精準(zhǔn)", "創(chuàng)造性"], show_label=False)
# 靠右的四個(gè)輸入
emptyBtn = gr.Button("清除歷史")
max_length = gr.Slider(0, 4096, value=2048, step=1.0, label="Maximum length", interactive=True)
top_p = gr.Slider(0, 1, value=0.7, step=0.01, label="Top P", interactive=True)
temperature = gr.Slider(0, 1, value=0.95, step=0.01, label="Temperature", interactive=True)
# 歷史記錄
history = gr.State([])
# 按鈕點(diǎn)擊后,執(zhí)行predict,并將第二個(gè)參數(shù)[...]傳給predict,將predict結(jié)果傳給第三個(gè)參數(shù)[...]
submitBtn.click(predict, [user_input, chatbot, max_length, top_p, temperature, history], [chatbot, history], show_progress=True)
submitBtn.click(reset_user_input, [], [user_input])
# 將reset_state的結(jié)果傳給outputs
emptyBtn.click(reset_state, outputs=[chatbot, history], show_progress=True)
radio_mode.change(set_mode, radio_mode, [temperature, top_p])
# button_accuracy_mode.click(set_mode, [0.95, 0.7], outputs=[temperature, top_p])
# button_creative_mode.click(set_mode, [0.01, 0.01], outputs=[temperature, top_p])
# 這玩意debug不會(huì)用啊
demo.queue().launch(share=False, inbrowser=False)
ChatGLM API 調(diào)用-2023/05/05
- 官方文檔:THUDM/ChatGLM-6B: ChatGLM-6B: An Open Bilingual Dialogue Language Model | 開源雙語(yǔ)對(duì)話語(yǔ)言模型
- 修改 ChatGLM/api.py :
- 模型存儲(chǔ)位置。
- 主機(jī)地址。
- 最后一行
host='0.0.0.0'
為host='localhost'
。 - 即
uvicorn.run(app, host='localhost', port=8000, workers=1)
- 最后一行
if __name__ == '__main__':
pretrain_path = "chatglm-6b-int8"
pretrain_path = os.path.abspath(pretrain_path)
tokenizer = AutoTokenizer.from_pretrained(pretrain_path, trust_remote_code=True)
model = AutoModel.from_pretrained(pretrain_path, trust_remote_code=True).half().cuda()
model.eval()
uvicorn.run(app, host='localhost', port=8000, workers=1)
- 使用 python requests 包的調(diào)用示例
import requests
url = "http://localhost:8000"
data = {"prompt": "你好", "history": []}
headers = {'Content-Type': 'application/json'}
response = requests.post(url, json=data, headers=headers)
print(response.text)
- 實(shí)際上我還寫了一個(gè)專門的類,不過(guò)還沒(méi)開源到 GitHub 上,可能過(guò)幾天會(huì)更新:asd123pwj/asdTools: Simple tools for simple goals
聞達(dá)
- 不會(huì)用,下面可以不用看。
介紹-2023/05/02
- l15y/wenda: 聞達(dá):一個(gè)LLM調(diào)用平臺(tái)。為小模型外掛知識(shí)庫(kù)查找和設(shè)計(jì)自動(dòng)執(zhí)行動(dòng)作,實(shí)現(xiàn)不亞于于大模型的生成能力
- 昨晚看視頻的時(shí)候發(fā)現(xiàn) GPT 讀取本地文檔的,發(fā)現(xiàn)了 fess 的方案,進(jìn)而發(fā)現(xiàn)了這個(gè)聞達(dá)庫(kù),NB。
懶人包-2023/05/02
- 作者有提供懶人包,B站也有人做教程,我沒(méi)用過(guò),沒(méi)流量,流量全用來(lái)下游戲刪游戲下游戲刪游戲下游戲刪游戲下游戲刪游戲了。
部署-2023/05/02
- 考慮到作者都搞懶人包了,手動(dòng)部署的應(yīng)該都是自己會(huì)的,我就簡(jiǎn)單說(shuō)下我的部署操作。
- 復(fù)制example.config.xml作為config.xml,并對(duì)應(yīng)修改。
- 修改envirment.bat,注釋掉懶人包路徑,修改自己的python路徑,如下,注釋掉的我就不放出來(lái)了
chcp 65001
title 聞達(dá)
set "PYTHON=F:\0_DATA\2_CODE\Anaconda\envs\ChatGLM\python.exe "
:end
我是廢物,改用懶人包-2023/05/02
- 不知道怎么用本地文檔搜索和網(wǎng)絡(luò)搜索,搞不懂搞不懂,又去下了懶人包。
- 可是為什么還是沒(méi)有哇。
fess安裝-2023/05/02
-
聞達(dá)要安裝 fess,但是懶人包好像沒(méi)有?
-
codelibs/fess: Fess is very powerful and easily deployable Enterprise Search Server. - https://github.com/codelibs/fess - https://github.com/codelibs/fess/releases/tag/fess-14.7.0 - https://github.com/codelibs/fess文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-437393.html
-
安裝:Elasticsearch文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-437393.html
- 這玩意好像商用要收費(fèi),算了,咱不用聞達(dá)了,看看它源碼怎么寫的算了。心好累。我是廢物。
到了這里,關(guān)于AI模型部署記錄(一)-ChatGLM:清華開源本地部署(2023/05/06更新)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!