0
1

LocalAIにおけるモデルの推論速度調査

Last updated at Posted at 2024-02-04

はじめに

LangChainのバックエンドとしてローカルでLLMを動かしたいと思っています. OpenAIのREST APIと互換で動作してくれると嬉しいです.
LocalAIは, OpenAIのREST APIサーバをローカルで再現しようとするプロジェクトです. あらゆるLLMをOpenAIのAPIで使いたいというプロジェクトです.

環境は次のコンピュータで, WSL2上でLocalAIを動かしています.

CPU Ryzen 7 7700
Memory DDR5-5200MHz 64GB
GPU Geforce RTX 4070

モデル選択

LocalAIでは, 例えば次のようなgpt-3.5-turbo.yamlファイルを, デフォルトではmodelsディレクトリに作成しておくと, luna-ai-llama2-uncensored.ggmlv3.q5_K_M.bingpt-3.5-turboモデルとして処理します. OpenAI APIのmodelパラメータに対応します.

gpt-3.5-turbo.yaml
gpt-3.5-turbo.yaml
name: gpt-3.5-turbo
# Default model parameters
parameters:
  # Relative to the models path
  model: luna-ai-llama2-uncensored.ggmlv3.q5_K_M.bin
  # temperature
  temperature: 0.3
  # all the OpenAI request options here..

# Default context size
context_size: 512
threads: 10
# Define a backend (optional). By default it will try to guess the backend the first time the model is interacted with.
backend: llama-stable # available: llama, stablelm, gpt2, gptj rwkv

テスト方法

Windowsのcurlを使って簡単なテストをしてみます.

curl -X "POST" -H "Content-Type: application/json" http://localhost:9090/v1/chat/completions -d "{\"model\": \"mixtral-8x7b-instruct\", \"messages\": [{\"role\": \"user\", \"content\": \"Could you introduce yourself?\"}]}"

結果

モデル名のあとに量子化ビット数をVRAMにロードする層数を記載します. あくまで設定値ですので, llama2系だと全層VRAMにロードします.

promt eval (ms/token) eval time (ms/token) total time (ms) VRAM use
mixtral-8x7b-instruct 2bit GPU 16 layers 503.55 108.30 15930.48 8Gb
mixtral-8x7b-instruct 4bit GPU 8 layers 856.37 251.04 27553.77 7Gb
codellama-7b-instruct 4bit GPU 32 layers 4.23 21.94 2070.06 5Gb
elyza-code-7b-instruct 4bit GPU 32 layers 2.52 20.80 2257.07 4.5Gb
mistral-7b-instruct 4bit GPU 32 layers 6.41 21.84 475.33 4.1Gb

まとめ

LangChainを駆動できるほどのLLMをローカルPCで動かしたいと思っています. なかなか難しそうです.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1