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

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

      24小時家電維修熱線:

      400—1558638

      當前位置:主頁 > 空氣能 > 維修資訊 >

      LangChain開發環境準備-AI大模型私有部署的技術指南

      發布日期:2023-09-21 21:14:37 瀏覽:
      LangChain開發環境準備AI大模型私有部署的技術指南

      今天開始小智將開啟系列AI應用開發課程,主要基于LangChain框架基于實戰項目手把手教大家如何將AI這一新時代的基礎設施應用到自己開發應用中來。歡迎大家持續關注

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

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

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

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

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

      3. linux系統可以直接通過以下腳本下載

      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
      基礎依賴安裝

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

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

      這樣就完成了基礎依賴庫的安裝。

      模型測試

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

      基于官方示例,創建模型對象,并調用對話方法
      1. 在當前目錄即/aidev中創建一個名為app.py的文件,并輸入以下內容:
      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創建模型訪問接口示例

      測試好模型后,我們已經掌握了與大模型對話的入口,可以進一步基于FastAPI創建一個模型訪問接口,這樣就可以讓外部的應用或者用戶通過網絡來調用我們部署在LangChain開發環境中的AI大模型。我們可以通過以下步驟來創建:

      1. 安裝uvicorn
      pip install uvicorn
      1. 在當前目錄即/aidev中創建一個名為api.py的文件,并輸入以下內容:
      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. 使用測試如下圖所示

      總結

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

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

      下一節課我將講解如何基于Baichuan213BChat4bits,提供符合langchain接入標準的openaiapi接口,請大家持續關注。

      主站蜘蛛池模板: 中文在线а√在线天堂中文| 免费福利在线| 秋霞鲁丝片av无码少妇| av第一福利网站| 白嫩白嫩国产精品| 黄色三级视屏| 污视频在线| 五月婷网| 日日碰狠狠丁香久燥| 日韩亚洲产在线观看| 国产乱码精品| 亚洲线精品一区二区三区| 3d动漫精品啪啪一区二区免费| 国产成人免费97在线观看| 99久久久久久久久| 在线欧美中文字幕农村电影| 思思久婷婷五月综合色啪| 国产xxxx孕妇| 97麻豆| 亚洲中文字幕无码中文字在线| 国产成人无码18禁午夜福利免费| 在线资源站| 伊人影院在线播放| 日韩精品无码一区二区三区| 乱码精品一卡二卡无卡| 天堂在线中文网| 国产精品一区二区久久不卡| 久艾草久久综合精品无码| 精品久久亚洲| 色婷婷久久综合中文久久一本| 91视频网址入口| 久久久精品一区二区涩爱| 久久久久人妻一区视色| 超碰www| 亚洲欧美精品一中文字幕| 老色鬼在线精品视频| 亚洲国内精品自在线影院| 国产91精品一区二区绿帽| 在线国产毛片| 欧美日本国产va高清cabal| 亚洲伊人成综合人影院青青青|