Closed KateSawada closed 10 months ago
huggingface transformersで使える日本語モデルのまとめ https://tech.yellowback.net/posts/transformers-japanese-models
追加で,Azureのリソースも調べてほしい
Azure Machine Learningのいろは https://qiita.com/gnbrganchan/items/43e6c44754cb83220db5 データとモデルをセットして学習させられるAzureのサービス。 学習から始めるのでハッカソン向きではないかも
Azure AI Language(旧 Azure Cognitive Services) https://www.softbanktech.co.jp/special/blog/dx_station/2022/0003/ AIチャット、固有表現抽出などの機能をAPIで呼び出せる。 ただし似たようなサービスがgoolab api (スポンサード)で提供されていそう? 機能一覧
(Azure Virtual Machine)クラウドリソースgpu
中間発表の時点で結論を出す
↑stormy,用意したサーバーでうごかんかった… rinna使えるようにしとこうと思います
結論,これ使う
rinnaの使い方(「rinna/bilingual-gpt-neox-4b-instruction-ppo」を8bit量子化) https://note.com/npaka/n/na4eb6bad2246 VRAM 6.1GB
↓ldサーバーで動かしたやつ.動かすために, $ pip install sentencepiece==0.1.99 accelerate==0.24.0 bitsandbytes==0.41.1 scipy==1.11.3
が必要だった.このあたりを,requirements.txtに追記する必要あり.
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# トークナイザーとモデルの準備
tokenizer = AutoTokenizer.from_pretrained(
"rinna/bilingual-gpt-neox-4b-instruction-ppo",
use_fast=False
)
print("tokenizer OK")
model = AutoModelForCausalLM.from_pretrained(
"rinna/bilingual-gpt-neox-4b-instruction-ppo",
load_in_8bit=True,
torch_dtype=torch.float16,
device_map="auto",
)
print("model OK")
print(model.device)
# プロンプトの準備
prompt = """ユーザー: まどか☆マギカでは誰が一番かわいい?その理由も説明して。
システム: """
# 推論の実行
token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
with torch.no_grad():
output_ids = model.generate(
token_ids.to(model.device),
max_new_tokens=512,
do_sample=True,
temperature=1.0,
top_p=0.85,
pad_token_id=tokenizer.pad_token_id,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id
)
output = tokenizer.decode(output_ids.tolist()[0][token_ids.size(1):])
print(output)
出力
$ python rinna.py
You are using the default legacy behaviour of the <class 'transformers.models.t5.tokenization_t5.T5Tokenizer'>. 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
tokenizer OK
model OK
cuda:0
それは素晴らしい質問です!私は鹿目まどかがとても好きで、彼女はとても可愛らしいです。彼女の魅力は、彼女の可愛らしい、そして少し変わった性格にあります。また、彼女の魅力的な笑顔や、彼女の芯の強さも好きです。</s>
使えそうなやつここに書いてほしい!!!