1 of 24

RAGとLLM

そしてDebGPT

knok@debian.org

2 of 24

DebGPT

  • https://salsa.debian.org/deeplearning-team/debgpt
    • Mo Zhou (lumin at debian.org) の開発したツール
      • debian-ai, deeplearning team等で活動
      • 既にパッケージもある (unstable, testing)
    • Debianに関わる各種ドキュメントを参照してLLMに答えさせる
      • RAG (Retrieval-Augmented Generation)と呼ばれる手法の一種
        • Debian関連のリソースを容易にアクセスする手段の提供

3 of 24

DebGPTのユースケース

  • リソースを参照可能
    • BTS
    • buildd パッケージステータス
    • Policy, Developers Reference
    • man, tldr(tealdeer)
    • 任意のファイル
  • 実行アクション
    • 要約 (テーブル表示)
    • 差分説明
    • 言い換え、よりよい表現
    • 自由質問

4 of 24

利用可能なLLM (Large Language Model)

  • OpenAI API と互換API
    • OpenAI, Azure OpenAI API:トークン単位課金
    • text-generation-weui (後述)
  • ローカルで動作するLLM (zmq backend)
    • mistralai/Mistral-7B-Instruct-v0.2
      • 最低要件: VRAM 6GB
    • mistralai/Mixtral-8x7B-Instruct-v0.1
      • 最低要件: VRAM 23GB
        • RTX 3090/4090クラス
    • HuggingFace model hubで配布
    • 参考: LLMリーダーボード https://artificialanalysis.ai/

5 of 24

LLM (Large Language Model)

  • たくさんのコーパス(テキスト文書)を学習させたモデル
    • GPT シリーズ (OpenAI)
    • GPT-Neo, GPT-J 等 (コミュニティベースのモデル)
      • AIのべりすと (GPT-NeoXベース)
  • それらに instruction tuning を施したもの (チャットモデル)
    • ChatGPT (OpenAI)
    • LLaMA/LLaMA2 (Meta)
    • Mistral/Mixtral (Mistral AI)
    • HyperCLOVA (LINE)

6 of 24

RAG: Retrieval-Augmented Generation

  • 論文 Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
    • Patrick Lewis, Facebook AI Research, 2020
    • https://arxiv.org/abs/2005.11401
  • LLMに文脈として知識を与え、それに基づいてタスクを解かせる
    • Hallucination を起こしにくい
      • Wikipedia解説
    • 考案当初はもっと小さいモデルを使っていた
      • BART, T5等
      • Instruction LLMとの組み合わせが強力
  • Vector DBと組み合わせることが多い
    • 類似文ベクトルを求め文脈用テキストを得る
    • chunking, 階層化等いろいろなテクニック

7 of 24

準備

  • 設定ファイルの用意
    • debgpt genconfig > ~/.debgpt/config.toml
    • 項目
      • frontend: openai / zmq / dryrun
      • temperature: 0.5 (どれだけ多様な出力をするか: 0で決定的動作)
      • openai_base_url: (Azureや互換APIで利用)
      • openai_api_key:
      • openai_model: (gpt3.5-turbo 等)
      • zmq_backend: (debgpt対応LLMで使用)
  • バックエンド起動
    • debgpt backend --max_new_tokens=1024 --device cuda --precision 4bit
      • デフォルトでglobalにlisten
      • デフォルトLLMは Mistral 7B
      • 4bit精度で動作(量子化)

8 of 24

実行

  • debgpt -HQ --bts 1014469 -A :summary

  • debgpt -HQ --tldr curl -A 'GETパラメータを -d オプションで複数指定したい'

A Debian bug report was submitted regarding a vulnerability in the libsixel package, specifically in version 1.8.6. The vulnerability, identified as CVE-2021-46700, involves a double free issue in the function sixel_encoder_output_without_macro. This issue was reported to the Debian security team and the affected maintainers, and it is recommended that the vulnerability be addressed and the CVE ID be included in the changelog entry. The bug was reported by Moritz Mühlenhoff on July 6, 2022, and the last modification was made on January 27, 2024. Debian bug tracking system is free software licensed under the GNU Public License version 2.

To send multiple GET parameters with the `-d` (or `--data`) option in curl, you should encode the parameters as a string and pass it as a value to the `--data-urlencode` option. Here's an example for sending multiple parameters:

```bash

curl --data-urlencode "param1=value1" --data-urlencode "param2=value2" http://example.com

```

In this example, replace `param1`, `value1`, `param2`, and `value2` with your desired parameter names and values. The `--data-urlencode` option encodes each parameter as a URL-encoded string and sends it as part of the request.

9 of 24

挙動

  • BTSからデータを取得 (debian.py bts)
  • プロンプトを前後に付与しLLMに与える
    • コンテンツの説明
    • 指示文
  • LLMが応答を返す
    • それを表示

  • –frontend dryrunで確認可能

The following is a webpage from Debian's bug tracking system:

```

(本文)

```

Please summarize the above information

10 of 24

プロンプト

  • 説明文 (debian.py の各関数に直書き)
    • 'Here is the Arch Wiki about {identifier}:'
    • 'Here is the contents of {url}:'
    • 'The following is the build status of package {p}:'
    • "The following is a webpage from Debian's bug tracking system:"
    • …等
  • 指示文 (defaults.py QUESTIONS)
    • ':explain': 'Please explain the above information.'
    • :summary': 'Please summarize the above information.'
    • ':licensecheck': 'What is the license of this file? Just tell me the SPDX identifier, and answer in the shortest format.'
      • https://spdx.org/licenses/ Software Package Data Excange
    • …等

11 of 24

対応リソース

  • Debian固有
    • BTS
    • buildd
    • developers reference
    • policy
  • コマンド出力
    • man, tldr, 任意
  • その他一般的なもの
    • html
    • file, stdin
    • arch wiki, python what’s new

12 of 24

量子化

  • パラメータの精度を落としてサイズを削減する
    • 通常 32bit float が使われる
      • より小さな bit 数の float への変換
        • 16bit ~ 4bit
        • 指数部により多くを割り当てる bfloat
      • intへの変換
    • どれだけ精度低下を抑えつつ変換できるかが肝
      • 動的/静的変換
        • 実際に演算をさせてみてscale factorを決める (dynamic quantization)
      • 訓練時に量子化を考慮する手法もある
    • バックエンド起動オプション --precision 4bit は 4bit floatで動作させる指示
    • 参考

13 of 24

text-generation-webui

  • https://github.com/oobabooga/text-generation-webui
    • Python/Gradioで書かれたLLM向けUI
      • stable-diffusion-webuiのLLM版的位置づけ
    • マルチプラットフォーム
      • Linux/Windows/MacOS
        • CUDA対応 (Linux/Windows)
        • ROCm対応 (Linux/MacOS)
    • 複数のバックエンドに対応 (transformers, lamma.cpp 等)
    • OpenAI API互換
      • 起動オプション例
        • .\start_windows.bat --api --listen --api-port 5000
        • –public-api: cloudflare お試しURLが発行される

14 of 24

setup

  • unstableならROCmも動く

$ git clone

$ ./setup_linux.sh

(minicondaが入る)

What is your GPU?

A) NVIDIA

B) AMD (Linux/MacOS only. Requires ROCm SDK 5.6 on Linux)

C) Apple M Series

D) Intel Arc (IPEX)

N) None (I want to run models in CPU mode)

Input>

15 of 24

text-generation-webui APIと組み合わせ

  • config.toml
    • openai_base_url = 'http://127.0.0.1:5000/v1' # change host, port
    • 他はそのままで良い
  • サーバ側の起動
    • モデルを読み込んでおく
      • GGUFの利用 (llama.cpp)
      • ダウンロード
      • llama.cpp を利用
        • ITPもされている

16 of 24

実行例

$ debgpt --frontend openai -HQ --bts 1014469 -A :summary

[01:42:35] OpenAIFrontend> Starting conversation frontend.py:66

9b53bacd-9204-48c7-a764-d710f55be62f

LLM[2]> A report was submitted to Debian's bug tracking system regarding a vulnerability in the libsixel package. The vulnerability, identified as CVE-2021-46700, involves a double free issue in the sixel\_encoder\_output\_without\_macro function of the libsixel 1.8.6 version. The maintainer of the package is NOKUBI Takatsugu, and the report was filed by Moritz Mühlenhoff. The vulnerability was published on GitHub, and it is classified as important with the security tag. The Debian team at security.debian.org was notified, and it is recommended that the vulnerability be fixed and the CVE ID be included in the changelog entry. The last modification to the report was on January 26, 2024. Debbugs is free software and licensed under the GNU Public License version 2.

[01:42:56] OpenAIFrontend> Conversation saved at frontend.py:102

/home/knok/.debgpt/9b53bacd-9204-48c7-a764-d710f55be6

2f.json

17 of 24

temperatureの違い

  • temp = 0.01

  • temp = 0.7

このデビアンバグレポートは、libsixelパッケージでのCVE-2021-46700の脆弱性報告である。この脆弱性は、libsixel 1.8.6のsixel\_encoder\_output\_without\_macro(encoder.cのsixel\_encoder\_encode\_frameから呼ばれている)において、ダブルフリーが存在するという問題である。CVE-2021-46700に関する詳細は、https://security-tracker.debian.org/tracker/CVE-2021-46700やhttps://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-46700を参照できる。この脆弱性を修正する場合、CVE IDも changelog エントリに含めることをお勧めしている。このバグレポートには、Debianバグトラッキングシステムの管理者(owner@bugs.debian.org)についても書かれている。

Debianバグトラッキングシステムは、GPLバージョン2のライセンス下で開源ソフトウェアである。詳細なバージョンは、https://bugs.debian.org/debbugs-source/ から確認できる。

このバグレポートは、1999年 Darren O. Benham、1997年 nCipher Corporation Ltd、1994-97年 Ian Jackson、2005-2017年 Don Armstrong以及多数の他の開発者による作成とな っている。

このディベィアンのバグトラッキングシステムのログは、libsixelパッケージに影響するCVE-2021-46700の脆弱性報告であるという内容です。 Reported by Moritz Mühlenhoffから、セキュリティの影響を与え、CVE-2021-46700[0]に記載されているlibsixelの1.8.6バージョンで、sixel_encoder_output_without_macro(encoder.cのsixel_encoder_encode_frameから呼び出されている)にdouble freeが存在するという脆弱性が発見さ れました。 CVE-2021-46700に関する詳細情報は、https://security-tracker.debian.org/tracker/CVE-2021-46700とhttps://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-46700を参照してください。 Moritz Mühlenhoffは、修正される場合、CVE-IDを changelog エントリに含めることをお勧めしています。 Debianバグトラッキングシステム管理 者(owner@bugs.debian.org)に影響を及ぼすバージョンを調整してください。 Debbugs はGPLライセンス2版のフリーソフトウェアで、詳細はhttps://bugs.debian.org/debbugs-source/を参照できます。 著作権は1999年 Darren O. Benham、1997年、2003年 nCipher Corporation Ltd、1994-1997年 Ian Jackson、2

18 of 24

temperature とは

  • トークン生成時にどれだけランダムに採択するかを決めるパラメータ
    • 大きいほど多様な出力をする
    • 正しさもあやしくなる
      • 「デビアン」->「ディベィアン」
  • その他のパラメータ
    • top_n: 上位 n 件から採択する
    • top_p: nucleus sampling
      • 単語の採択確率により強い傾斜をつける
      • 同じフレーズが連続する現象を低減できる

19 of 24

混合メモリ対応

  • GPUメモリの不足分をメインメモリで補う
  • 複数のプラットフォームで対応
    • transformers + acceralate
    • llama.cpp
      • CUDA, ROCm対応
      • 元はApplieシリコン向けとして開発

20 of 24

どれくらいのメモリで動くか?

  • マシン: GPD Win Max 2
    • Ryzen 7 6800U
    • Radeon 680M
      • VRAM 3GB割り当て
    • メインメモリ 32GB
  • TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF
    • mixtral-8x7b-instruct-v0.1.Q2_K.gguf (15GB)
    • llama.cpp n-gpu-layers: 1
      • ぎりぎり動く
      • 速度は実用レベル
        • GPT-4の応答速度と同程度

21 of 24

Mistral AI以外のモデルはどうか

  • LLaMA 2ベース
    • elyza/ELYZA-japanese-Llama-2-13b-instruct
      • 割と実用そう
    • tokyotech-llm/Swallow-13b-hf
      • ちょっとダメそう
      • LLaMAで学習した英語の情報が残っているので期待したけど…
  • その他
    • rinna/japanese-gpt-neox-3.6b-instruction-ppo
      • ダメそう
    • stabilityai/japanese-stablelm-instruct-alpha-7b
    • stockmark/stockmark-13b-instruct

22 of 24

ROCm

  • unstableで動作
    • linux 6.5.13 で確認
      • amdgpu
    • ROCm 関連パッケージ
      • hipcc, rocm-device-libs, rocminfo, rocm-smi
      • ROCmチームによる管理

23 of 24

その他の話題

  • モデルのマージ
  • LoRA (Low-Rank Adaptation)
    • パラメータ効率の良いfine tuning, PEFT
      • 元のパラメータはそのままに、低ランク行列をアダプタとして追加し学習
      • 訓練パラメータが少ないため高速に訓練可能
      • 画像生成モデルが有名だがもっと一般的な技術
    • 訓練の例

24 of 24

その他の話題

  • allenai/OLMo-7B
    • Allen Institute for AI によるデータセットも含めて公開されたLLM
      • ML Policy に準拠
        • https://salsa.debian.org/deeplearning-team/ml-policy
          • (Debian で正式に採択されたわけではない)