見出し画像

Google Colab で RedPajama-INCITE を試す

「Google Colab」で「RedPajama-INCITE」を試したので、まとめました。

1. RedPajama-INCITE

「RedPajama」は、再現可能で完全にオープンな言語モデルを作成するための取り組みです。

1. 高品質で広範囲をカバーする事前学習データの作成
2. 大規模に学習するベースモデルの作成
3. Instructionチューニングデータとモデルの作成


「RedPajama-INCITE」は、RedPajamaデータセットで学習したLLMです。現在、「3B」と「7B」(早期アクセス)のモデルが提供されています。

・RedPajama-INCITE-Base-3B-v1
・RedPajama-INCITE-Instruct-3B-v1
・RedPajama-INCITE-Chat-3B-v1
・RedPajama-INCITE-Base-7B-v0.1
・RedPajama-INCITE-Instruct-7B-v0.1
・RedPajama-INCITE-Chat-7B-v0.1

2. Colabでの実行

Colabでの実行手順は、次のとおりです。

(1) メニュー「編集→ノートブックの設定」で、「ハードウェアアクセラレータ」で「GPU」を選択。
プレミアムで操作確認してますが、GPU RAM 6GBで動作したので、無料版でも大丈夫そうです。

(2) パッケージのインストール。

# パッケージのインストール
!pip install transformers

(3) トークナイザーとモデルの準備。
今回は、3Bのチャットモデルを指定しています。

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

# トークナイザーとモデルの準備
tokenizer = AutoTokenizer.from_pretrained(
    "togethercomputer/RedPajama-INCITE-Chat-3B-v1"
)
model = AutoModelForCausalLM.from_pretrained(
    "togethercomputer/RedPajama-INCITE-Chat-3B-v1", 
    torch_dtype=torch.float16
).to("cuda:0")

(4) 推論の実行。

# プロンプトの準備
prompt = "<human>: Who is Miyazaki Hayao?\n<bot>:"

# 推論の実行
inputs = tokenizer(prompt, return_tensors='pt').to(model.device)
input_length = inputs.input_ids.shape[1]
outputs = model.generate(
    **inputs, 
    max_new_tokens=128, 
    do_sample=True, 
    temperature=0.7, 
    top_p=0.7, 
    top_k=50, 
    return_dict_in_generate=True
)
token = outputs.sequences[0, input_length:]
output_str = tokenizer.decode(token)

# 確認
print("output :", output_str)

output : Miyazaki Hayao is a Japanese animator, director, and author. He is best known for his animated films such as Princess Mononoke, My Neighbor Totoro, and Spirited Away.

【翻訳】
宮崎駿は、日本のアニメーター、監督、作家である。もののけ姫』『となりのトトロ』『千と千尋の神隠し』などのアニメーション映画で知られる。

チャットモデルのプロンプトの書式は、次のとおりです。

<human>: [Instruction]
<bot>:



この記事が気に入ったらサポートをしてみませんか?