サイトのデザインが新しくなりました。

【StreamingLLM】トークン数400万、小説40冊を読み込める無限LLM

LLM StreamingLLM AIツール

皆さん、StreamingLLMというLLM用のアプリケーションをご存知ですか?

LLMで無限に入力ができることを可能にしたツールなんです!LLMを日々使い倒している弊社としては、衝撃のツールなんですよ。

GitHubでも4500超えのスターを獲得しており、徐々に注目が集まっています。AIオタクであれば、知らなかったなんてことないですよね。

このStreamingLLMを使えば、対話型でLLMを動かすことができ、モデルが質問の都度、リアルタイムで応答を生成してくれます。

というわけで、今回はStreamingLLMの使い方や、実際に使ってみた感想などをご紹介します。
この記事を最後まで読むと、StreamingLLMを使いこなすことができ、LLMとのリアルタイムの会話も可能になります!

ぜひ最後までご覧ください!

なお弊社では、生成AIツール開発についての無料相談を承っています。こちらからお気軽にご相談ください。

目次

StreamingLLMの概要

StreamingLLMは「400万以上のトークンという、ほぼ無限の入力を読み込める手法」を持つLLMです。

例えば、私たちがLLMと話すとき、長い会話が続くことがありますよね。その際、LLMは私たちが最初に言ったことを覚えておく必要があります。しかし、長い会話を覚えておくのはLLMは苦手なんです。そのため、効率的に会話を覚えておく方法が、求められていました。

StreamingLLMは、その答えの一つとして考えられました。この技術を使うと、LLMは長い会話の中でも、特に大切な部分だけを上手に覚えておくことができます。そして、それをもとに適切な返答を生成することができるのです。こうすることで、私たちとLLMとの会話がよりスムーズになります。

簡単に言えば、StreamingLLMは、LLMが長い会話を効率的に理解し、それに応じて返答するための技術です。

こちらの投稿でも詳しく解説されています。

StreamingLLMの料金体系

StreamingLLMはOSSであり、そのコードは無料で公開されています。

StreamingLLMの使い方

今回はGoogle Colab上で実行してみます。まずは、Colabを開いたら、以下のコードを実行して、インストールしてください。

!pip install torch torchvision torchaudio
!pip install transformers==4.33.0 accelerate datasets evaluate wandb scikit-learn scipy sentencepiece

次に、StreamingLLMのリポジトリ内の「setup.py」を実行する必要があります。その前に、必要なリポジトリをクローンする必要があります。以下のコマンドでリポジトリをクローンしましょう。

!git clone https://github.com/mit-han-lab/streaming-llm.git
%cd streaming-llm

その後、以下のコマンドでsetup.pyを実行しましょう。

!python setup.py develop

そして、以下のコードを実行すると、Llama Chatbotとの対話ができるようになります。

%cd examples/
!python run_streaming_llama.py --enable_streaming

これで、StreamingLLMを用いた、リアルタイムのチャットが可能になります。

長いトークンを読み込めるおすすめのLLMを知りたい方はこちらをご覧ください。

なお、長文を読み込めるLLMについて詳しく知りたい方は、下記の記事を合わせてご確認ください。
【Claude Pro】本1冊読み込める!?GPT4のライバル生成AIを使ってみた

StreamingLLMを実際に使ってみた

上記のコードを実行してみると、以下のようにモデルのロードが始まります。

モデルのロードが完了したら、以下のように「USER」「ASSISTANT」との会話が始まります。この「USER」が書いている文章が、プロンプトに当たります。ここでは、あらかじめプロンプトのテンプレートJSONファイルを用意して、それを読み込んでいるのだと思います。

また、リポジトリを見ると、GPUのCUDAメモリ不足によるエラーが起こるリスクが考えられるため、高性能なGPUを使用することが推奨されるでしょう。

自身のPCのスペックが乏しい方は、以下の記事を参考にして、軽量なLLMを動かしてみてください。
【phi-1.5】人気1位の超軽量、コスパ最強LLMを使ってみた

StreamingLLMの推しポイントである長い会話は本当なのか?

先ほどのコードをGoogle Colabで実行したところ、途中までは会話ができていますが、以下のようにメモリエラーが発生しました。

Loading model from lmsys/vicuna-13b-v1.3 ...
You are using the default legacy behaviour of the <class 'transformers.models.llama.tokenization_llama.LlamaTokenizer'>. If you see this, DO NOT PANIC! This is expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you. If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it means, and thouroughly read the reason why this was added as explained in https://github.com/huggingface/transformers/pull/24565
Downloading shards:   0%|                                                        | 0/3 [00:00<?, ?it/s]pytpytorch_model-00001-of-00003.bin: 100%|███████████████████████████| 9.95G/9.95G [45:39<00:00, 3.63MB/s]
pytorch_model-00002-of-00003.bin: 100%|██████████████████████████████| 9.90G/9.90G [40:07<00:00, 4.11MB/s]pytorch_model-00003-of-00003.bin: 100%|██████████████████████████████| 6.18G/6.18G [20:08<00:00, 5.11MB/s]Downloading shards: 100%|████████████████████████████████████████████| 3/3 [1:46:01<00:00, 2120.33s/it]/s]Loading checkpoint shards: 100%|████████████████████████████████████████████| 3/3 [00:19<00:00,  6.49s/it](…)v1.3/resolve/main/generation_config.json: 100%|███████████████████████| 132/132 [00:00<00:00, 12.3kB/s]Loading data from data/mt_bench.jsonl ...
StartRecentKVCache: 4, 2000

USER: Compose an engaging travel blog post about a recent trip to Hawaii, highlighting cultural experiences and must-see attractions.

ASSISTANT: 🌴🌺 Aloha from the beautiful islands of Hawaii! I recently had the opportunity to explore the diverse culture and stunning landscapes of this tropical paradise, and I can't wait to share my adventures with you.

🏝️ First things first, let's talk about the beaches. Hawaii is known for its pristine white sand and crystal clear waters, and I was lucky enough to visit some of the most breathtaking beaches on the islands. My favorite was Waimea Bay on the North Shore of Oahu. The waves were perfect for surfing, and the surrounding cliffs and lush greenery made for a postcard-worthy backdrop.

🌊 But Hawaii isn't just about the beaches. The culture of the islands is rich and vibrant, and I made it a point to immerse myself in it during my trip. I attended a traditional Hawaiian luau on the Big Island, where I learned about the history and customs of the native people. I also tried my hand at hula dancing and even got to sample some delicious Hawaiian cuisine, including poke bowls and shaved ice.

🏯 Another must-see attraction in Hawaii is the Hawaii Volcanoes National Park on the Big Island. The park is home to two active volcanoes, Kilauea and Mauna Loa, and offers a unique opportunity to see the power of nature up close. I hiked through the park and was amazed by the steam vents, lava tubes, and volcanic craters. It was truly a once-in-a-lifetime experience.

🌺 In addition to the natural wonders of Hawaii, the islands are also home to some of the most beautiful gardens and parks in the world. The Maui Tropical Plantation offered a glimpse into the island's agricultural history, while the Hilo Tropical Botanical Garden showcased the stunning flora and fauna of the area.

🏯 In conclusion, Hawaii is a destination that offers something for everyone. From the stunning beaches to the rich culture and unique attractions, there's no shortage of things to see and do on these beautiful islands. If you're planning a trip to Hawaii, be sure to add these must-see attractions to your itinerary. Mahalo for reading, and aloha!

USER: Rewrite your previous response. Start every sentence with the letter A.

ASSISTANT: 🌴🌺 Aloha from the beautiful islands of Hawaii! I recently had the opportunity to explore the diverse culture and stunning landscapes of this tropical paradise, and I can't wait to share my adventures with you.

🏝️ First things first, let's talk about the beaches. Hawaii is known for its pristine white sand and crystal clear waters, and I was lucky enough to visit some of the most breathtaking beaches on the islands. My favorite was Waimea Bay on the North Shore of Oahu. The waves were perfect for surfing, and the surrounding cliffs and lush greenery made for a postcard-worthy backdrop.

🌊 But Hawaii isn't just about the beaches. The culture of the islands is rich and vibrant, and I made it a point to immerse myself in it during my trip. I attended a traditional Hawaiian luau on the Big Island, where I learned about the history and customs of the native people. I also tried my hand at hula dancing and even got to sample some delicious Hawaiian cuisine, including poke bowls and shaved ice.

🌺 In addition to the natural wonders of Hawaii, the islands are also home to some of the most stunning gardens and parks in the world. The Maui Tropical Plantation offered a glimpse into the island's agricultural history, while the Hilo Tropical Botanical Garden showcased the stunning flora and fauna of the area.

🏯 In conclusion, Hawaii is a destination that offers something for everyone. From the stunning beaches to the rich culture and unique attractions, there's no shortage of things to see and do on these beautiful islands. If you're planning a trip to Hawaii, be sure to add these must-see attractions to your itinerary. Mahalo for reading, and aloha!

USER: Draft a professional email seeking your supervisor's feedback on the 'Quarterly Financial Report' you prepared. Ask specifically about the data analysis, presentation style, and the clarity of conclusions drawn. Keep the email short and to the point.

ASSISTANT: 💼 Dear [Supervisor's Name],

I hope this email finds you well. I am writing to seek your feedback on the Quarterly Financial Report that I Traceback (most recent call last):

(省略)

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 136.00 MiB. GPU 0 has a total capacty of 15.99 GiB of which 0 bytes is free. Including non-PyTorch memory, this process has 17179869184.00 GiB memory in use. Of the allocated memory 14.50 GiB is allocated by PyTorch, and 536.37 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

もしStreamingLLMを導入したい場合は、十分なメモリを確保する必要があるでしょう。そのため、そのようなハードウェアを用意できない方にとっては、あまり実用的ではないかもしれません。

まとめ

StreamingLLMは、「LLMが言葉を理解し、それに応じて返答する技術」の一つです。この技術を使うと、LLMは長い会話の中でも、特に大切な部分だけを上手に覚えておくことができます。そして、それをもとに適切な返答を生成することができるのです。こうすることで、私たちとLLMとの会話がよりスムーズになります。

StreamingLLMはOSSであるため、使用料金は無料です。そして、Google Colab上で本記事の「使い方」見出しの通りにコードを実行していくと、StreamingLLMを簡単に試すことができます。

ただし、ローカル環境で実行したところ、途中までは会話ができていますが、メモリエラーが発生しました。StreamingLLMの利用には十分なメモリを確保する必要があるため、そのようなハードウェアを用意できない方にとっては、あまり実用的ではないかもしれません。

サービス紹介資料

生成系AIの業務活用なら!

・生成系AIを活用したPoC開発

・生成系AIのコンサルティング

・システム間API連携

最後に

いかがだったでしょうか?

弊社では

・マーケティングやエンジニアリングなどの専門知識を学習させたAI社員の開発
・要件定義・業務フロー作成を80%自動化できる自律型AIエージェントの開発
・生成AIとRPAを組み合わせた業務自動化ツールの開発
・社内人事業務を99%自動化できるAIツールの開発
ハルシネーション対策AIツールの開発
自社専用のAIチャットボットの開発

などの開発実績がございます。

まずは、「無料相談」にてご相談を承っておりますので、ご興味がある方はぜひご連絡ください。

➡︎生成AIを使った業務効率化、生成AIツールの開発について相談をしてみる。

生成AIを社内で活用していきたい方へ

「生成AIを社内で活用したい」「生成AIの事業をやっていきたい」という方に向けて、生成AI社内セミナー・勉強会をさせていただいております。

セミナー内容や料金については、ご相談ください。

また、弊社紹介資料もご用意しておりますので、併せてご確認ください。

投稿者

  • Hiromi Sai

    ChatGPTメディア運営 / テクニカルライター リベラルアーツ専攻。大学休学中は、Webマーケティング会社のマネージャーとしてライター、ディレクター100名のマネジメントをする。南米のチリとタイでの長期居住歴を持つ。

  • URLをコピーしました!
  • URLをコピーしました!
目次