2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルでllmを動かしてみた

Last updated at Posted at 2025-03-11

目次

  • モデルについて
  • 仮想環境の作成
  • 環境構築(インストール)
    • Pytorch
    • accelerate
    • transformer
  • モデルの実行
    • 実行時のエラーと対策
      • 1.ValueError: You are trying to offload the whole model to the disk. Please use the disk_offload function instead

使用したモデルについて

使用したのは「Llama-3-ELYZA-JP-8B」というモデル
詳しくはこちら...
https://huggingface.co/elyza/Llama-3-ELYZA-JP-8B
こちらのサイトの Usage を用いる

仮想環境の作成

vscodeで仮想環境の作成を行う
詳しくはこちら...https://qiita.com/hk8640/items/82e12b628caaf40594e5

環境構築

Pytorch

Pythonの機械学習ライブラリの一つ

pip install torch

accelerate

様々な環境でPyTorchを実行するためのライブラリ

  • CPU、GPU、TPUのどのデバイスでPyTorchを動かすのか?
  • 並列処理を行うのか?
  • マシンは複数台利用するのか?

こういった内容をプログラムの実行環境をコード修正なしで変更できる

pip install accelerate

transformer

機械翻訳の深層学習モデル

pip install transformers

モデルの実行

環境構築が完了したらモデルを動かしてみる

うまくいけば完了
image.png
この「DEFAULT_SYSTEM_PROMPT」と「text」の引数を変えれば望む回答を得ることができるだろう

エラー

1.ValueError: You are trying to offload the whole model to the disk. Please use the disk_offload function instead
対処法

model = AutoModelForCausalLM.from_pretrained("HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.float16, low_cpu_mem_usage = True).cpu() 

disk_offload(model=model, offload_dir="offload")

こちらの2行をimport文の後ろに追加する

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?