
redpajama.cppを試す
「redpajama.cpp」を試したのでまとめました。macOSで動作確認しました。
・RedPajama-INCITE-3B
・macOS 13.3.1
1. redpajama.cpp
「redpajama.cpp」は、「llama.cpp」の「RedPajama」対応版です。
2. redpajama.cppの実行
「redpajama.cpp」の実行手順は、次のとおりです。
(1) redpajama.cppのリポジトリをクローン。
$ git clone https://github.com/togethercomputer/redpajama.cpp.git
$ cd redpajama.cpp
(2) ビルド。
$ make redpajama-chat quantize-gptneox
(3) Pythonの仮想環境を準備して以下のパッケージをインストール。
次に実行するスクリプトで要求されたのでインストールしました。macOS以外のPyTorchのインストールコマンドは公式サイトを参照。
$ pip install torch torchvision torchaudio
$ pip install transformers
(4) モデルの取得。
提供されているスクリプトを実行するだけで、HuggingFaceからモデル (BaseとChatとInstruct) をダウンロードし、ggml.cppフレームワークの形式に変換できます。
Chatモデルの取得するコマンドは、次のとおりです。
$ bash ./examples/redpajama/scripts/install-RedPajama-INCITE-Chat-3B-v1.sh
(5) 実行。
「RedPajama-INCITE-Chat-3B-v1」とチャットできます。
$ ./redpajama-chat -m ./examples/redpajama/models/pythia/ggml-RedPajama-INCITE-Chat-3B-v1-f16.bin \
-c 2048 \
-b 128 \
-n 1 \
-t 8 \
--instruct \
--color \
--top_k 30 \
--top_p 0.95 \
--temp 0.8 \
--repeat_last_n 3 \
--repeat_penalty 1.1 \
--seed 0

3. 量子化
ggml.cppフレームワークには、q4_0、q4_1、q4_2、q5_0、q5_1、q8_0などの量子化メソッドがあり、RedPajama-INCITEモデルでも、これらを使用してより効率的に動作させることができます。
RedPajamaチャットボットのq4_1を実行する手順は、次のとおりです。
(1) ggml.cppの量子化形式の生成。
$ python ./examples/redpajama/scripts/quantize-gptneox.py \
--quantize-output-type q4_1 \
./examples/redpajama/models/pythia/ggml-RedPajama-INCITE-Chat-3B-v1-f16.bin
「ggml-RedPajama-INCITE-Chat-3B-v1-q4_1.bin」が生成されます。
(2) 実行。
$ ./redpajama-chat -m ./examples/redpajama/models/pythia/ggml-RedPajama-INCITE-Chat-3B-v1-q4_1.bin \
-c 2048 \
-b 128 \
-n 1 \
-t 8 \
--instruct \
--color \
--top_k 30 \
--top_p 0.95 \
--temp 0.8 \
--repeat_last_n 3 \
--repeat_penalty 1.1 \
--seed 0