欧洲精品久久久av无码电影,日日噜噜夜夜爽爽,精品无码国产自产拍在线观看蜜,人妻少妇被粗大爽9797pw,羞国产在线拍揄自揄视频,国产白嫩漂亮美女在线观看,天码欧美日本一道免费,av大片在线无码免费

      歡迎來到同城快修-附近家電維修、家電清洗、家電安裝服務(wù)平臺

      24小時家電維修熱線:

      400—1558638

      當(dāng)前位置:主頁 > 空氣能 > 維修資訊 >

      LangChain開發(fā)環(huán)境準(zhǔn)備-AI大模型私有部署的技術(shù)指南

      發(fā)布日期:2023-09-21 21:14:37 瀏覽:
      LangChain開發(fā)環(huán)境準(zhǔn)備AI大模型私有部署的技術(shù)指南

      今天開始小智將開啟系列AI應(yīng)用開發(fā)課程,主要基于LangChain框架基于實戰(zhàn)項目手把手教大家如何將AI這一新時代的基礎(chǔ)設(shè)施應(yīng)用到自己開發(fā)應(yīng)用中來。歡迎大家持續(xù)關(guān)注

      當(dāng)下在AI應(yīng)用開發(fā)領(lǐng)域,LangChain框架可以說是唯一選擇。然而,上手學(xué)習(xí)的小伙伴們大多被攔在了第一步,沒有可供使用的AI大模型底座,沒有可供實驗的環(huán)境進行實操。而各大廠商比如OpenAI提供的API需要付費不說,從注冊、開通到使用都有諸多的不便和限制。

      因此,如何在本地或者私有網(wǎng)絡(luò)中部署和使用AI大模型,成為了一個亟待解決的挑戰(zhàn)。本文將以Baichuan213BChat4bits為例,介紹如何進行AI大模型私有部署,用于LangChain開發(fā)實驗實操。本次課程提綱如下,今天主要降大模型部署的部分。

      基礎(chǔ)環(huán)境
      環(huán)境配置與安裝1.python 3.8及以上版本,官網(wǎng)安裝即可  地址:https://www.python.org/2.pytorch 1.12及以上版本,推薦2.0及以上版本,官網(wǎng)安裝即可  地址:https://pytorch.org/getstarted/locally/3.建議使用CUDA 11.4及以上,根據(jù)顯卡匹配英偉達推薦驅(qū)動進行暗轉(zhuǎn)  地址:https://developer.nvidia.com/cuda1140downloadarchive4.建議使用linux環(huán)境安裝,本文示例基于linux環(huán)境演示5.假定以下動作執(zhí)行的當(dāng)前目錄為/aidev
      模型下載

      要在LangChain開發(fā)環(huán)境中部署AI大模型,首先需要下載模型文件和配置文件。Baichuan213BChat4bits模型已經(jīng)上傳到了huggingface這個知名的AI模型庫中,我們可以通過以下步驟來下載它:

      從huggingface上下載模型及配置文件
      1. 模型下載鏈接如下
      https://huggingface.co/baichuaninc/Baichuan213BChat4bits
      1. 在模型頁面中,點擊右上角的Download按鈕,選擇Download files選項。

      3. linux系統(tǒng)可以直接通過以下腳本下載

      aptget y install qq aria2aria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/config.json d /content/baichuaninc/Baichuan213BChat4bits o config.jsonaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/configuration_baichuan.py d /content/baichuaninc/Baichuan213BChat4bits o configuration_baichuan.pyaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/generation_config.json d /content/baichuaninc/Baichuan213BChat4bits o generation_config.jsonaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/generation_utils.py d /content/baichuaninc/Baichuan213BChat4bits o generation_utils.pyaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/handler.py d /content/baichuaninc/Baichuan213BChat4bits o handler.pyaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/modeling_baichuan.py d /content/baichuaninc/Baichuan213BChat4bits o modeling_baichuan.pyaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/resolve/main/pytorch_model.bin d /content/baichuaninc/Baichuan213BChat4bits o pytorch_model.binaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/quantizer.py d /content/baichuaninc/Baichuan213BChat4bits o quantizer.pyaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/requirements.txt d /content/baichuaninc/Baichuan213BChat4bits o requirements.txtaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/special_tokens_map.json d /content/baichuaninc/Baichuan213BChat4bits o special_tokens_map.jsonaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/tokenization_baichuan.py d /content/baichuaninc/Baichuan213BChat4bits o tokenization_baichuan.pyaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/resolve/main/tokenizer.model d /content/baichuaninc/Baichuan213BChat4bits o tokenizer.modelaria2c consoleloglevel=error c x 16 s 16 k 1M https://huggingface.co/baichuaninc/Baichuan213BChat4bits/raw/main/tokenizer_config.json d /content/baichuaninc/Baichuan213BChat4bits o tokenizer_config.json
      基礎(chǔ)依賴安裝

      下載好模型文件和配置文件后,主目錄為/aidev,文件目錄為baichuaninc/Baichuan213BChat4bits(備注后續(xù)啟動模型會默認(rèn)加載此目錄,請按此命名),我們還需要安裝一些基礎(chǔ)的依賴庫,以便于在LangChain開發(fā)環(huán)境中運行模型。我們可以通過以下步驟來安裝:

      pip安裝模型運行的依賴,requirment.txt文件pip install r baichuaninc/Baichuan213BChat4bits/requirements.txt

      這樣就完成了基礎(chǔ)依賴庫的安裝。

      模型測試

      安裝好基礎(chǔ)依賴庫后,我們可以先測試一下模型是否能夠正常運行。我們可以通過以下步驟來測試:

      基于官方示例,創(chuàng)建模型對象,并調(diào)用對話方法
      1. 在當(dāng)前目錄即/aidev中創(chuàng)建一個名為app.py的文件,并輸入以下內(nèi)容:
      import torchfrom transformers import AutoModelForCausalLM, AutoTokenizerfrom transformers.generation.utils import GenerationConfigtokenizer = AutoTokenizer.from_pretrained(&34;baichuaninc/Baichuan213BChat4bits&34;, use_fast=False, trust_remote_code=True)model = AutoModelForCausalLM.from_pretrained(&34;baichuaninc/Baichuan213BChat4bits&34;, device_map=&34;auto&34;, torch_dtype=torch.bfloat16, trust_remote_code=True)model.generation_config = GenerationConfig.from_pretrained(&34;baichuaninc/Baichuan213BChat4bits&34;)messages = []messages.append({&34;role&34;: &34;user&34;, &34;content&34;: &34;解釋一下“溫故而知新”&34;})response = model.chat(tokenizer, messages)print(response)
      1. 啟用測試
      python app.py

      運行效果如下圖所示

      基于FastAPI創(chuàng)建模型訪問接口示例

      測試好模型后,我們已經(jīng)掌握了與大模型對話的入口,可以進一步基于FastAPI創(chuàng)建一個模型訪問接口,這樣就可以讓外部的應(yīng)用或者用戶通過網(wǎng)絡(luò)來調(diào)用我們部署在LangChain開發(fā)環(huán)境中的AI大模型。我們可以通過以下步驟來創(chuàng)建:

      1. 安裝uvicorn
      pip install uvicorn
      1. 在當(dāng)前目錄即/aidev中創(chuàng)建一個名為api.py的文件,并輸入以下內(nèi)容:
      from fastapi import FastAPIfrom fastapi import HTTPExceptionfrom pydantic import BaseModelimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizerfrom transformers.generation.utils import GenerationConfigtokenizer = AutoTokenizer.from_pretrained(&34;baichuaninc/Baichuan213BChat4bits&34;, use_fast=False, trust_remote_code=True)model = AutoModelForCausalLM.from_pretrained(&34;baichuaninc/Baichuan213BChat4bits&34;, device_map=&34;auto&34;, torch_dtype=torch.bfloat16, trust_remote_code=True)model.generation_config = GenerationConfig.from_pretrained(&34;baichuaninc/Baichuan213BChat4bits&34;)app = FastAPI() This defines the data json format expected for the endpoint, change as neededclass RequestItem(BaseModel):    message: str@app.post(&34;/generate/&34;)async def generate_text(request_item: RequestItem):    try:         在這里處理接收到的 JSON 請求        reqStr = request_item.message        messages = []        messages.append({&34;role&34;: &34;user&34;, &34;content&34;: reqStr})        response = model.chat(tokenizer,messages)        return {&34;generated_text&34;: response}    except Exception as e:        raise HTTPException(status_code=500, detail=str(e))
      1. 啟動接口
      uvicorn app:app host 0.0.0.0 port 8000 > server.log 2>&1 &
      1. 使用測試如下圖所示

      總結(jié)

      本文介紹了如何在LangChain開發(fā)環(huán)境中準(zhǔn)備AI大模型私有部署的技術(shù)指南,以Baichuan213BChat4bits為例,分別介紹了模型下載、基礎(chǔ)依賴安裝、模型測試和基于FastAPI創(chuàng)建模型訪問接口的步驟和代碼。當(dāng)然只是簡單的提供對話接口的話,還無法將大模型接入langchain的開發(fā)流程中。

      點擊鏈接獲取一份GPT至強筆記:「鏈接」

      下一節(jié)課我將講解如何基于Baichuan213BChat4bits,提供符合langchain接入標(biāo)準(zhǔn)的openaiapi接口,請大家持續(xù)關(guān)注。

      主站蜘蛛池模板: 国产精品午夜片在线观看| 成人午夜在线播放| 美女露出奶头扒开尿口视频直播| 免费黄色网址大全| 国产精品青青草| 国产99久久九九精品无码| 久久久久久国产精品| 亚洲综合成人av| 六月丁香婷婷色狠狠久久| 国产偷国产偷高清精品| 国产精品v欧美精品v日韩| 精品久久久无码人妻字幂| 中文字幕漂亮人妻熟睡中被公侵犯 | 久久久久久久久毛片精品| 免费在线毛片| 欧洲三级在线| 欧洲肉欲k8播放毛片| 日韩一区二区三区三四区视频在线观看| 一级黄色性片| 国产成人精品午夜2022| 国产免费无遮挡吸乳视频app| 中文字幕精品三区| 亚洲人成电影在线天堂色| 精品国产一区二区av麻豆不卡| 日韩午夜激情| 97视频总站| 色妞www精品免费视频| 色婷婷国产精品高潮呻吟av久久| 香蕉色视频| 国产精品午夜福利片国产| 日本高清一二三区视频在线| 超碰啪啪| 精品小视频在线观看| 97久久久精品综合88久久| 久久精品99久久久久久| 激情久久五月| 两性色午夜免费视频| 国产精品线在线精品| 中国黄色小视频| 亚洲中文字幕一区精品自| 欧美在线观看免费做受视频|