LoginSignup
0
0

Ubuntu 22.04LTS serverにtext-generation-webuiをcondaでインストールする

Last updated at Posted at 2023-08-09

LLM(大規模言語モデル)を自宅PCで動かせるようにしたときのメモです。OSはUbuntu 22.04 LTS serverで、この環境にtext-generation-webuiをインストールします。

なお、text-generation-webuiのインストールは「Manual installation using Conda」の手順を使ってインストールを行います。
ただし、事前にcudaのセットアップが済んでいるものとします。

公式サイトには「One-click installers」という、zipアーカイブを解凍してインストールする手順も用意されていますが、こちらの手順の説明は行いません。(すでにこの手順は、様々な方々が説明されているのでそちらを参照してください。)

環境

種類 -
CPU AMD Ryzen 5 5600G
GPU Geforce 3090
OS Ubuntu 22.04 LTS server
その他 cudaインストール済み

準備

text-generation-webuiの公式サイトの手順には記載ありませんが、事前にtextgenユーザーの作成を行います。

本ユーザーを作成せずに公式サイトの手順を実施しても問題はありませんが、ホームディレクトリ配下にPythonの各種ライブラリがインストールされるので、環境を汚さないためにtextgenユーザーを作成し、そこにtext-generation-webuiのインストールを行います。

$  sudo adduser textgen
[sudo] password for XXXXX:
Adding user `textgen' ...
Adding new group `textgen' (1001) ...
Adding new user `textgen' (1001) with group `textgen' ...
Creating home directory `/home/textgen' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for textgen
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y

本手順では以降、textgenユーザーでインストール作業を行います。

$ su - textgen
Password:
$ whoami
textgen

text-generation-webuiインストール

以下、公式サイトの「Manual installation using Conda」に従いインストールを行います。

conda(Miniconda)のインストール

Minicondのインストールを行います。
Minicondaは、PythonまたはR言語用の環境管理システムです。

$ curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" > "Miniconda3.sh"
$ bash Miniconda3.sh

~ ライセンス条項は割愛 ~

Do you accept the license terms? [yes|no]
[no] >>> yes

Miniconda3のインストール場所を訊かれる。
デフォルト(ホームディレクトリ直下)から変更する必要がなければEnterキーを押下。

Miniconda3 will now be installed into this location:
/home/textgen/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/textgen/miniconda3] >>>

Miniconda3の初期化を実行するか訊かれる。
yesを入力しEnterキーを押下。
この初期化時に、.bashrcにパス追加などの設定が行われる模様。

Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes

Miniconda3のインストールが完了する。
先ほどの初期化で.bashrcに設定が追加されるので、シェルを再起動するよう注意が表示される。

==> For changes to take effect, close and re-open your current shell. <==

If you'd prefer that conda's base environment not be activated on startup,
   set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Miniconda3!

指示に従いシェルを再起動すると、プロンプトの表示が変わり頭に「(base)」というプレフィックスがつくようになる。

インストール前: textgen@localhost:~$
インストール後: (base) textgen@localhost:~$

text-generation-webuiのインストール

text-generation-webui 用の環境を構築する

condaを使い、text-generation-webui 用のPython環境を構築する。

$ conda create -n textgen python=3.10.9

~中略~

  xz                 pkgs/main/linux-64::xz-5.4.2-h5eee18b_0
  zlib               pkgs/main/linux-64::zlib-1.2.13-h5eee18b_0


Proceed ([y]/n)? y

condaにより環境構築が完了すると、下記のようにtextgen用の環境をactivateすることができるようになる。
activateするとプロンプトのプレフィックスが(base)から(textgen)と、activate先の名称がセットされる。

(base) textgen@localhost:~$ conda activate textgen
(textgen) textgen@localhost:~$

以降、textgen環境がactivateされていることを明示するため、実行例にプロンプトを表示する。(今まで $ のみだったが (textgen) textgen@localhost:~$と記述する。)

続いて、Pytorchのインストールを行う。以下のコマンドはnVidia環境用のコマンドになる。
nVidia以外の環境については、公式サイトの本テーブルを参照。

(textgen) textgen@localhost:~$ pip3 install torch torchvision torchaudio

text-generation-webuiをインストール(gitクローン)する。

(textgen) textgen@localhost:~$ git clone https://github.com/oobabooga/text-generation-webui
(textgen) textgen@localhost:~$ cd text-generation-webui
(textgen) textgen@localhost:~$ pip install -r requirements.txt

以上で、text-generation-webuiのインストールが完了。

text-generation-webuiのインストールディレクトリへ移動し、サーバーを実行する。なお、デフォルトだとlocalhost(127.0.0.1)しかアクセスできないため、--listenオプションを追加し他ホストからもアクセスできるようオプションを追加している。

(textgen) textgen@localhost:~$ cd ~/text-generation-webui
(textgen) textgen@localhost:~$ python server.py --listen

実行直後の画面

text-generation-webuiを起動し、ブラウザでアクセスすると以下の画面が表示される。
なお、LLMがインストールされていないため、チャットすることは出来ない。

image.png

画面上部のメニューから「Model」をクリックし、「Download custom model or LoRA」のテキストフィールドに、HuggingFaceのモデル名を入力し「Download」ボタンをクリックすると、指定したモデルがダウンロードされる。

image.png

再起動について注意

text-generation-webuiを再起動するときは、conda activate textgenを実行しtextgen環境がactivateされてから起動コマンドを実行するように要注意。

(base) textgen@localhost:~$ conda activate textgen
(textgen) textgen@localhost:~$ cd ~/text-generation-webui
(textgen) textgen@localhost:~$ python server.py --listen

参考HP

0
0
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
0