LoginSignup
1
0

More than 1 year has passed since last update.

NVIDIA GTX2枚刺しでDollyV2-7bとチャットしてみた。

Last updated at Posted at 2023-04-15

はじめに

Dollyさんである。大規模言語モデル。Transformerモデル。
今回のお話は、前半が、GPUを2枚刺しにするまでのお話。マシンがXeon2発でC612チップセットだから2枚刺しは電源容量さえ気をつければ大丈夫なはず。
後半のお話は、Dollyさんとのチャットをしてみた感想。

昨日までGPUのVRAMが8GBのGTX1080を1枚搭載したマシンで、手元で動かしたい系の機械学習モデルをいくつか動かしてみたが、まずGTX1080ごときでは会話したくなるようなスピードではもはや動作しない。話しかける文章を書き込んだ後、トイレに立って帰ってきたらなにかもそもそとPCが画面に表示し始める、という感じだったりする。そして8GBメモリに収まるようなパラメタの少ない奴らでは、会話にならない。こちらのコトバが通じていない感、聞いてない感が半端ない。ChatGPTの一人勝ち間違いない現状だが、自分の手元でそれに近い動きができるものならやってみたい。ロマンである。

VRAMか新世代GPUか

ロマンを追うには、まずはどうあがいてもマシンのハードウェアの改訂が必要だ。GTX1080一枚ではだめなことはわかった。8GBのVRAMも心許ない時代になっている。GoogleColabのPro契約という離れ業もあるが、数時間もクラウドサービスにアクセスしたままにして辛抱するほどの肝っ玉を持っていない。機械学習がものすごくゆっくり進行しているように見えて、もし自分のコードが間違っていて無限ループしているだけだったら?終わるまで待っていたら破産しそうだ。
ハードウェアを買い換える。VRAMを増やしたい。が、VRAMが16GB以上あるRTXシリーズとかTESLAとかって・・・。高価。
と諦めかけていたのだが、ヤフオクを見ていて見つけてしまった「例のグラボ」。なんと1枚6000円。性能はGTX1080と同等、VRAM8GBとな。これを追加して動かせば、数字のうえではCUDAコア2倍、VRAM2倍である。しかし、それで性能まで2倍になるとは思えない。(というか、何の時間を持って速度比較すればいいのかわからない。)GTX1080を買うよりも確実に安い、そして、RTX3000番台でも8GBより多いメモリを積んだ製品はワタシが購入できるようなお値段ではない。
そういうわけで、ワタシはメモリ容量増強を優先し、しかもその増強をPytorchのMultiGPU処理に頼ることとして「例のグラボ」を落札したのだった。「例のグラボ」とは、MSI社性 NVIDIA P104-100 である。数年前、マイニング用として登場し、公の仕様ではグラッフィックの出力ポートがなくメモリも4GBとされていたものの、実は裏の金具を外すとHDMIポートがついていたり、BIOSを書き換えることでメモリが8GB使えるようになっていたりした変わり者だ。

PCに追加

落札したP104-100が今日届いた。開封して驚いたことにゃ、8ピン電源と6ピン電源の両方の口がある、ってこたぁ全部で14ピン・・・っていうか電気くうなぁとか思いながらとにかく増設する(以前から電源は確保できるようなものを使っている。)。
Ubuntu22.04 で認識。ドライババージョンは 525。 だがどうせ、CuNNは6.1でしか動かない。もとからGTX1080刺さってるましんだから、導入は難しくなかった。

いよいよ、プログラムを動作させる

早速だが、例によって例のごとく、先達の力を借りる。巨人の肩に乗りまくり。

こちらのQiitaでは、なんとAWSでTeslaT4x4のインスタンスで12b(=12Billion = 120億)パラメータのモデルを動かしたそうだ。この場合、28GB程度のVRAMが必要らしい。いったん、ここで紹介されているコードのまま手元のマシンで実行したが、当然のごとくOutOfMemoryとなって何もできない。
だが、Dollyさんには、7b(=7Billion = 70億)パラメータモデルも誕生していた。

そこで、 main.py の 13行目にある、モデルの指定を変えてみる。

model_name = "databricks/dolly-v2-7b"

これだと、モデルサイズが11GB程度なので、なんとかメモリに載るはず・・・。よし、起動した。
ちょっとした挨拶をしましたら、なんとか返事がありました。

よし、ちょっと長めの文章を書いてやれ、と意地悪をすると・・・
image.png

あれ?なんでしょう?コンソールを見てみると
image.png

え?メモリ不足でスカイ?モデルはVRAMに乗り切っているけど、そこにさらに入力データを載せようとすると割当てがもらえない、ってことかな?というわkで、エラーにかいてあるアドバイスのとおり、max_split_size_mb について調べ、さらにStable Diffusion Web UI で似たような現象の対処記事も参考にガベージコレクションの設定もしてみることにした。。

いったん、Ctrl+c でdOlly-chat( main.py )を停止して、次の通り環境変数をセットして再実行。

$ PYTORCH_CUDA_ALLOC_CONF="garbage_collection_threshold:0.6, max_split_size_mb:64"
$ python3 main.py

これで、さっきと同じ長文英語を入力したところ、1回目は勝手にサマライズして返事してくれた。(サマライズしてほしい、とは書いてない)。2回目はオウム返しだった。
image.png

元の文章: スペースこみ 1079文字
The Report reinforces the scientific view that CO2 is the primary GHG that needs to be drastically reduced to achieve the global temperature goal as agreed in the Paris Agreement. Addressing the Plenary Session at G7 Ministers' Meeting on Climate, Energy and Environment in Sapporo, Japan he said the global goal of reaching net zero by 2050 requires enhanced descaling of emissions by the Developed Countries. Shri Yadav said to save our planet from the challenges of climate change, pollution, loss of biodiversity, we need collective action guided by the founding principles of the Rio Conventions. He said we do hope that the Developed Countries will make good their commitments on finance for combatting climate change and provide for the same for dealing with the environmental degradation and biodiversity loss. Shri Yadav said reaching targets on carbon neutrality and increased ambition will not fly unless they are made keeping Equity and CBDR-RC consideration in view as well as unless the Developed Countries meet their commitments to provide means of implementation.

DollyV2-7bの返答 1回目: スペースこみ 547文字
Addressing the Plenary Session at G7 Ministers' Meeting on Climate, Energy and Environment in Sapporo, Japan, Mr. Yadav pointed out that the global goal of reaching net zero by 2050 requires enhanced descaling of emissions by the Developed Countries. He also underscored the importance of solidarity and partnership in this cause. He said we do hope that the Developed Countries will make good their commitments on finance for combatting climate change and provide for the same for dealing with the environmental degradation and biodiversity loss.

DollyV2-7bの返答 2回目: スペースこみ 1079文字
The Report reinforces the scientific view that CO2 is the primary GHG that needs to be drastically reduced to achieve the global temperature goal as agreed in the Paris Agreement. Addressing the Plenary Session at G7 Ministers' Meeting on Climate, Energy and Environment in Sapporo, Japan he said the global goal of reaching net zero by 2050 requires enhanced descaling of emissions by the Developed Countries. Shri Yadav said to save our planet from the challenges of climate change, pollution, loss of biodiversity, we need collective action guided by the founding principles of the Rio Conventions. He said we do hope that the Developed Countries will make good their commitments on finance for combatting climate change and provide for the same for dealing with the environmental degradation and biodiversity loss. Shri Yadav said reaching targets on carbon neutrality and increased ambition will not fly unless they are made keeping Equity and CBDR-RC consideration in view as well as unless the Developed Countries meet their commitments to provide means of implementation.

DollyV2-7bの返答 3回目: スペースこみ 697文字
The G7 Minister’s statement reinforces the scientific view that CO2 is the primary GHG that needs to be drastically reduced to achieve the global temperature goal as agreed in the Paris Agreement. It also recognizes that to reach net zero emissions by 2050 the Developed Countries will have to enhance their descaling of emissions. The statement also recognizes that to save our planet from the challenges of climate change, pollution, loss of biodiversity, we need to have collective action guided by the principles of the Rio Conventions. It also hopes that the Developed Countries will take collective action to combat climate change and address environmental degradation and biodiversity loss.

この要約の返事が帰ってくるまでに約100秒。サマライズは微妙。元の文章は、Mr. Yadavが会議で発言したことを伝える文章である。だが、3回目のようなMr.Yadavの名称を出さないサマライズは、ちょっと物足りなく感じる。固有名詞にアテンションが効いてないのか?

さて、ここで「What does Mr Yadav mean?」と聞いてみたが・・・
image.png

残念ながら、Mr.Yadavはそんなことは言っていない。前段で話していたことと脈絡のない情報を出力してしまうのは、チャットとしてはあまりかしこいとは言えない。ここは、前段までの会話をメモリにとどめておいて何らか紐付けながら会話を続けるような仕組みを実装する必要がありそうだ。

次に一般知識を聞いてみた。

元の文章:
Can you morphologically analyze the input text?

DollyV2-7bの返答:
You can try some basic morphological analysis using spaCy. For example, you can ask spaCy to generate part-of-speech tags, look up the detected parts of speech, and then search for the most frequent parent forms of those parts of speech.

Here is an example:

from spacy importDocManager, MorphLemma, NER, CorpusReader, CorpusProcessor, Puzzle, LEX, JunkensteinMorphologicalAnalysis

corpus = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vehicula fermentum leo. Sed et tellus ipsum. Morbi euismod tempor risus, eget gravida tellus interdum sollicitudin. Phasellus consectetur, ipsum vitae euismod sodales, metus nibh blandit lacus, eu euismod. Fusce et metus quis tortor elementum congue at velit. Fusce id arcu quam, sit amet vestibulum tortor fermentum. Donec vel urna vel arcu bibendum sodales. Fusce condimentum element

最終段落で、corpus の定義を書き始めたのがなんだかよくわからないが、spaCyを使えば?と提案しているように読み取れなくもない。「Can you?」で質問しているのに、YesともNoとも答えないところが会話っぽくない。しかし、 morphologically anaryze についての知識は持っているようだ。

その他、次のように同じ質問を繰り返したりしてみた。質問を2度繰り返したが、都度回答は異なり、それぞれ3秒程度で返ってきた。
image.png
なるほど、これは嘘ではないらしい。

ちなみに動作中の nvidia-smi
image.png

2枚のメモリを使い切っていて、2枚刺しの恩恵はありそうだ。

考察

ChatGPTは、チャットに合わせてさまざまなタスクを依頼することができるが、Dollyにはそんな機能はない。また、質問に対して主体性を持って答えるような言い回しや、連続したチャットの処理(時系列的会話処理とでもいおう)ができない。チャットをする、会話しているというような感じはあまりしない。
参考にしたサイトの会話サンプルやここで試した文章から、今回利用したDollyのモデルは、短文で質問をし、モデルが格納している知識情報を引き出すことを楽しむいわば辞書型の道具のようなもの、という印象をうけた。チャットとして使うには、モデルの改善の他に会話を続けさせるための工夫が必要だと思われる。

まとめ

GTX1080とP104-100の2枚刺しでは、それぞれのグラボで7GB以上のメモリをPytorchが確保し、11GBの今回のモデルを読み込んで使えたものの、1000文字程度の長文に対して2分以上回答が来なかった。いっぽう、短い文章で知識を問うような質問にはDollyV2モデルは答えてくれている。ただし、チャットボットとして連続した会話をするためには工夫が必要そうだ、ということがわかった。

おまけ。

Autobot, Transform! とは叫ばない。そんなオプティマスな機能はいまのところ感じられない。Transformerで何をどう学習させたら良いのだろうか・・・。

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