現在、自社のGPUサーバーで 量子コンピューター向けの知識やプログラミングができるような大規模言語モデルを構築していますかより軽量な入門編のblueqat cloudを使ってLLMを実行してみました。
基本的にはHuggingFaceのモデルを利用することで簡単に実行ができます。
参考:HuggingFace での Llama 2 の使い方
https://note.com/npaka/n/n79eebc29366d
この記事は有料版の企業版クラウドを使っています。Google Colabのような物でも同じようにできます。
!pip install transformers accelerate
自社のクラウドで足りないのはこの二つでした。これでHuggingFaceが使えるようです。
下のtokenのところにHuggingFaceで登録したtokenを入れて完了です。
実装時間は準備に50秒程度、プロンプトの実行で40秒程度でした。
T4で動かすにはVRAMが足りないので、
torch_dtype=torch.float16,
とする必要があります。
from transformers import AutoTokenizer
import transformers
import torch
import time
model = "meta-llama/Llama-2-7b-hf"
#model ="huggyllama/llama-7b"
token = "ここにトークン"
tokenizer = AutoTokenizer.from_pretrained(model, token=token)
start2 = time.time()
pipeline = transformers.pipeline(
"text-generation",
model=model,
torch_dtype=torch.float16,
device_map="auto",
)
start3 = time.time()
print(start3 - start2)
sequences = pipeline(
'I like curry rice. Is there any receipet for good taste curry rice?',
do_sample=True,
top_k=10,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
max_length=200,
)
print(time.time() - start3)
for seq in sequences:
print(f"Result: {seq['generated_text']}")
使いかたがダメなのか変な返答になりました。
Result: I like curry rice. Is there any receipet for good taste curry rice?
I'm not sure what kind of curry you're looking for, but I'm sure it's possible to make it taste good. I think it's more about the seasoning than the actual curry.
What is the best way to make curry?
The best way to make curry is to start with a good base, like chicken or beef. Then, add in some vegetables and spices to make it more flavorful. Finally, add in some water or broth to help the curry cook evenly.
What is the best way to cook curry?
There is no one definitive answer to this question. Some people prefer to cook curry on the stove, while others prefer to cook it in the oven. Ultimately, it depends on what you are comfortable with and what you think will work
使い方がダメだったようです。Chatタイプを使ってみました。
model = "meta-llama/Llama-2-7b-chat-hf"
実行速度も速い気がします。
11.843833446502686
Result: 日本の一番高い山はなんですか?
A: The highest mountain in Japan is Mount Fuji, which stands at 3,776 meters (12,388 feet) above sea level.
こちらもやってみました。
38.52439999580383
Result: カレーはどうやって作るのですか?
- カレーの材料
* 麺
* 豚骨
* 豚肉
* 椎茸
* 塩
* 酒
* 胡椒
* 増量剤 - カレーの作り方
- 麺を沸騰させ、冷やす
- 豚骨を炒める
- 豚肉を炒める
- 椎茸を炒める
- 塩を加えて味
普通に楽しいですね。