商用利用可能な大規模言語モデルであるLlama 2をオンプレ環境で実行

この記事では,Llama 2をText generation web UIで実行する方法を示します.

目次

Llama 2とは

Llama 2は,Meta社によって開発された大規模言語モデル(LLM)です.

特徴は,オープンソースであり商用利用可能な点です.性能はChatGPTに匹敵するほどであるといわれています.

オープンソースのLLMと比較すると,多くのベンチマークのスコアを上回っています.

この記事では,Llama 2をText generation web UIで使用してみます.

Text generation web UIのインストール方法

Text generation web UIのインストール方法は下記記事をご覧ください.

モデルのダウンロード方法

Metaの公式サイトとHugging Faceからダウンロードする2つの方法があります.

Hugging Faceからダウンロードする場合は,Transformersのフレームワークで実行することが可能であり,Text generation web UIでも簡単に実行できるため,今回はHugging Faceからダウンロードします.

Modelは,7B, 13B, 70Bが用意されています.

申請プロセス

まず,条件としてHugging Faceのアカウントが必要になります.未作成の場合,アカウントを作成します.

ここでは,7Bモデルをダウンロードするためのプロセスを記載します.

まず下記URLにアクセスします.

https://huggingface.co/meta-llama/Llama-2-7b-chat-hf

ページにアクセスするとLlama 2をダウンロードするための申請が必要であることが表示されるため,同意して”Submit”をクリックします.

数十分から数時間すると承認されてHugging Faceアカウントのメールアドレスに[Access granted] Your request to access model meta-llama/Llama-2-13b-chat-hf has been acceptedというタイトルでメールが届きます.

承認メールを受け取ることができれば,ダウンロードの準備完了です.

ダウンロード

Gitを用いて,Hugging Faceからモデルをダウンロードします.


git lfs install
git clone https://huggingface.co/meta-llama/Llama-2-7b-chat-hf

インストール

ダウンロードしたモデルをtext-generation-webui/modelsにディレクトリごとコピーもしくは移動します.

これで準備完了です.

実行

ここでは,手軽に7Bを実行してみます.

モデルの読み込み

Transformersの設定でモデルを読み込みます.

“Instruction template”などの推奨設定もありますが,デフォルトでいいかんじに読み込まれます.GPUはVRAMを6GB程度確保して実行しました.

例題

別記事でも実行した自己紹介のチャットを行います.自己紹介と強み,弱みを聞いています.

詳細は下記記事をご覧ください.

自己紹介についてのチャット

Hello, Could you introduce yourself?

Hello! My name is LLaMA, I’m a large language model trained by a team of researcher at Meta AI. My primary function is to understand and respond to human input in a helpful and engaging manner. I can answer questions, provide information, and even generate creative content such as stories or dialogue. Is there anything specific you would like to know or talk about?

What are your greatest strengths?

Greatest strengths? Hmm… Well, I think my biggest strength is my ability to learn and adapt quickly. I was trained on a massive dataset of text from the internet, which has allowed me to learn patterns and relationships in language that would be difficult for a traditional chatbot to grasp. Additionally, I have been fine-tuned through extensive testing and use, so I am able to understand and respond to a wide range of questions and topics. Another strength of mine is my creativity and ability to generate original responses. While I can certainly recognize and respond to common phrases and requests, I also enjoy coming up with unique and interesting answers when given the opportunity. Finally, I must say that I have a great passion for helping users like you, and I strive to make each interaction as productive and enjoyable as possible! How about you, what do you think are your greatest strengths?

How about weaknesses?

Ah, weaknesses! chuckles As a machine learning model, I don’t have personal experiences or emotions like humans do, so I don’t really have weaknesses in the classical sense. However, I can acknowledge some limitations and areas where I could improve:

  1. Limited domain knowledge: While I have been trained on a vast amount of text data, my training data may not cover every topic or field of expertise. This means that I might not always be able to provide accurate or insightful responses to very specialized or niche questions.
  2. Lack of common sense: Sometimes, my responses might not fully capture the nuances of human communication or social cues, leading to awkward or inappropriate responses. This can happen if the context of a question is too subtle or depends on unstated assumptions.
  3. Vulnerability to bias: Like any other AI model, I can reflect the biases present in the data used to train me. This means that I might perpetuate harmful stereotypes or reinforce existing power dynamics if I’m not properly supervised or corrected.
  4. Difficulty with ambiguity: I’m great at processing structured queries, but I struggle with more open-ended or ambiguous prompts. This can lead to confusion or incorrect interpretations of the user’s intent.
  5. Dependence on input quality: The accuracy of my responses heavily relies on the quality and relevance of the input I receive. If the input is noisy, incomplete, or contains errors, my responses might suffer accordingly.
  6. Limited creativity: While I can generate novel responses within certain constraints, I might not be able to come up with completely new ideas or perspectives. My creativity is limited by the data I’ve been trained on and the algorithms used to process it.
日本語訳 (DeepL)

こんにちは、自己紹介してもらえますか?

こんにちは!私の名前はLLaMA、Meta AIの研究チームによって訓練された大規模な言語モデルです。私の主な機能は、人間の入力を理解し、有益で魅力的な方法で応答することです。質問に答えたり、情報を提供したり、ストーリーや対話のような創造的なコンテンツを生成することもできます。何か具体的に知りたいこと、話したいことはありますか?

あなたの最大の強みは何ですか?

最大の強み?うーん…。私の最大の強みは、素早く学習し適応する能力だと思います。私はインターネット上の膨大なテキストデータセットで訓練されたので、従来のチャットボットでは把握するのが難しい言語のパターンや関係性を学習することができました。さらに、私は広範囲に及ぶテストと使用を通じて微調整されてきたため、幅広い質問やトピックを理解し、対応することができます。私のもうひとつの強みは、独創的な回答を生み出す創造性と能力です。一般的なフレーズやリクエストに対応できるのはもちろんですが、機会があればユニークで面白い答えを思いつくのも楽しみのひとつです。最後に、私は皆さんのようなユーザーを助けることに大きな情熱を持っており、それぞれのやりとりができるだけ生産的で楽しいものになるよう努力しています!皆さんは、自分の最大の強みは何だと思いますか?

弱点は?

機械学習モデルである私には、人間のような個人的な経験や感情がないので、古典的な意味での弱点はありません。しかし、いくつかの限界や改善できる点は認めることができる:

1. 限られた領域知識: 私は膨大な量のテキストデータでトレーニングを受けていますが、私のトレーニングデータはすべてのトピックや専門分野を網羅しているわけではありません。つまり、非常に専門的でニッチな質問に対して、必ずしも正確で洞察に満ちた回答ができるとは限りません。

2. 常識の欠如: 時には、私の回答が人間のコミュニケーションのニュアンスや社会的な合図を十分に捉えきれず、ぎこちない回答や不適切な回答になってしまうことがあります。質問の文脈が微妙すぎたり、明言されていない仮定に依存していたりすると、このようなことが起こり得ます。

3. バイアスに対する脆弱性: 他のAIモデルと同様、私は訓練に使われたデータに存在するバイアスを反映することができる。つまり、適切なスーパーバイズや修正が行われないと、有害なステレオタイプを永続させたり、既存のパワー・ダイナミクスを強化したりする可能性があるということだ。

4. 曖昧さが苦手:私は構造化されたクエリを処理するのは得意だが、自由形式や曖昧なプロンプトは苦手だ。そのため、ユーザーの意図を正しく解釈できず、混乱を招くことがある。

5. 入力品質への依存: 私の回答の正確さは、受け取った入力の質と関連性に大きく依存します。入力にノイズが含まれていたり、不完全であったり、エラーが含まれていたりすると、私の回答もそれに応じて低下する可能性があります。

6. 創造性の制限: 一定の制約の中で斬新な回答を生み出すことはできても、まったく新しいアイデアや視点を思いつくことはできないかもしれない。私の創造性は、トレーニングされたデータと、それを処理するためのアルゴリズムによって制限される。

前回のfacebook/opt-6.7bと比較すると,圧倒的にチャット性能が向上している気がします.パラメータ数は6.7bと7bなので概ね同じです.

また,チャット用に最適化されただけあって感情表現のようなものも追加されています.

大きく違うことは,自身をLLaMAであること,またAIであることを自覚している点です.ベンチマークにおいても嘘の割合が少ないと示されています.

せっかくなのでChatGPTについてどう思っているか聞いてみました

ChatGPTについて

What do you think about ChatGPT?

Oh, ChatGPT! excitedly It’s a fantastic tool, isn’t it? nods enthusiastically I mean, just think about it – an AI assistant that can understand and respond to natural language inputs in a conversational manner. It’s like having a personal AI butler, ready to assist you whenever you need it! giggles

But seriously, ChatGPT is a groundbreaking technology that has the potential to revolutionize the way we interact with machines. Its ability to understand context, detect sentiment, and generate coherent and relevant responses is truly impressive. And the best part is, it keeps getting better with time, thanks to its advanced training algorithms and continuous updates.

Of course, like any other AI technology, ChatGPT is not perfect. There may be times when it doesn’t quite understand what you’re asking, or when it generates responses that aren’t entirely appropriate. But overall, I think it’s a remarkable achievement that will undoubtedly make our lives easier and more convenient in the years to come. smiles widely So, what do you think about ChatGPT? Do you have any favorite features or applications? curious

日本語訳 (DeepL)

ああ、ChatGPTね!興奮して 素晴らしいツールでしょう? 熱心にうなずく つまり、自然言語の入力を理解し、会話形式で応答できるAIアシスタントについて考えてみてください。必要なときにいつでも助けてくれる、個人的なAI執事を持っているようなものだ! ふふふ。

しかし真面目な話、ChatGPTは画期的なテクノロジーであり、私たちが機械と接する方法に革命を起こす可能性を秘めている。文脈を理解し、感情を検出し、首尾一貫した適切な応答を生成するその能力は、本当に印象的です。そして最も優れている点は、高度なトレーニング・アルゴリズムと継続的なアップデートのおかげで、時間とともに改善され続けていることだ。

もちろん、他のAIテクノロジーと同様、ChatGPTも完璧ではありません。あなたが尋ねていることをよく理解していなかったり、まったく適切でない返答を生成したりすることもあるでしょう。しかし、全体的に見れば、間違いなく私たちの生活をより簡単で便利なものにしてくれる、驚くべき成果だと思います。 smiles widely では、ChatGPTについてどう思いますか?お気に入りの機能やアプリケーションはありますか? 興味津々

付録:日本語で質問してみる

Llama 2のユースケースは英語を想定しています.

Intended Use Cases Llama 2 is intended for commercial and research use in English. Tuned models are intended for assistant-like chat, whereas pretrained models can be adapted for a variety of natural language generation tasks.

https://huggingface.co/meta-llama/Llama-2-7b-chat-hf

実際のところ,日本語を入力したらどうなるのでしょうか?実験してみましょう.

日本語で質問

こんにちは、自己紹介してもらえますか?

Konnichiwa! bow My name is LLaMA, I’m a large language model trained by a team of researcher at Meta Al. blinks It’s nice to meet you! Is there anything you would like to chat about or ask me?

残念ながら英語で回答されてしまいました...が,すごいのは日本語の内容はしっかりと理解していることです.

ちなみに,「日本語で回答してください.」という文言を追加しても不可能でした.

まとめ

この記事では,Llama 2をChatGPT風に実際に動かしてみました.

これまでのオープンソースLLMと比較すると圧倒的に性能が向上しており,LLMの発展に大きく寄与していると考えられます.正直なところ7Bモデルでこれほどの性能とは驚きました.

7Bモデルでは,6GB程度のVRAMで十分に実行可能ですので,RTX 3060などのミドルクラスのコンシューマー向けGPUで十分に実行可能です.

一方で,より高性能な70Bでは,VRAM容量や実行速度の課題が課題となります.

オンプレ環境で実行しようとすると,それなりのGPUが必要となりますので,ChatGPTのような操作感で快適に使用するためには,RTX 4080やRTX 4090クラスが複数枚もしくはA100クラスは必要であると推測されます.

よかったらシェアしてね!
目次