見出し画像

Google Colab で Llama-2-70B-chat-GPTQ を試す

「Google Colab」で「Llama-2-70B-chat-GPTQ」を試したのでまとめました。

【注意】Google Colab Pro/Pro+ の A100で動作確認しています。

【最新版の情報は以下で紹介】


前回

1. AutoGPTQ

AutoGPTQ」を使って「Llama 2」の最大サイズ「70B」の「Google Colab」での実行に挑戦してみます。

2. Colabでの学習

Google Colabでの学習手順は、次のとおりです。

(1) メニュー「編集→ノートブックの設定」で、「ハードウェアアクセラレータ」で「GPU」の「A100」を選択。

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

# パッケージのインストール
%cd /content
!git clone https://github.com/PanQiWei/AutoGPTQ
%cd AutoGPTQ
!pip install . 
!pip install git+https://github.com/huggingface/transformers

(2) トークナイザーとモデルの準備。

from transformers import AutoTokenizer, pipeline, logging
from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig

# トークナイザーとモデルの準備
model_name_or_path = "TheBloke/Llama-2-70B-chat-GPTQ"
model_basename = "gptq_model-4bit--1g"
tokenizer = AutoTokenizer.from_pretrained(
    model_name_or_path, 
    use_fast=True
)
model = AutoGPTQForCausalLM.from_quantized(
    model_name_or_path,
    model_basename=model_basename,
    inject_fused_attention=False, # 現時点では70Bに必要
    use_safetensors=True,
    trust_remote_code=True,
    device="cuda:0",
    use_triton=False,
    quantize_config=None
)

(3) 推論の実行。

# プロンプトの準備
prompt='''[INST] <<SYS>>
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.  Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<</SYS>>
What is Bocchi-chan's personality from BOCCHI THE ROCK?[/INST]'''

# 推論の実行
input_ids = tokenizer(prompt, return_tensors='pt').input_ids.cuda()
output = model.generate(inputs=input_ids, temperature=0.7, max_new_tokens=512)
print(tokenizer.decode(output[0]))
<s> [INST] <<SYS>>
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe.  Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
<</SYS>>
What is Bocchi-chan's personality from BOCCHI THE ROCK?[/INST]  Bocchi-chan, the main character of the anime and manga series "Bocchi the Rock," is a unique and interesting character with a distinct personality. Here are some adjectives that might describe her personality:

1. Naive: Bocchi-chan is often depicted as being very innocent and naive, which can sometimes lead to humorous misunderstandings and unexpected reactions to certain situations.
2. Energetic: Bocchi-chan has a lot of energy and enthusiasm, which she uses to pursue her interests and passions, such as playing the guitar and performing music.
3. Determined: Despite her naivety, Bocchi-chan is very determined and driven when it comes to achieving her goals. She works hard to improve her music skills and to make a name for herself as a musician.
4. Kind: Bocchi-chan is a kind and caring person, always willing to help others and make new friends. She is also very supportive of her friends and bandmates.
5. Quirky: Bocchi-chan has a quirky and playful personality, often coming up with unique and unexpected ideas and solutions to problems.
6. Emotional: Bocchi-chan wears her heart on her sleeve and is not afraid to express her emotions. She can be sensitive and emotional at times, but this also makes her a very empathetic and relatable character.

Overall, Bocchi-chan's personality is a mix of innocence, energy, determination, kindness, quirkiness, and emotional depth, which makes her a compelling and endearing character to watch and root for.</s>

<s> [INST] <<SYS>>
あなたは親切で、礼儀正しく、誠実なアシスタントです。 常に安全を保ちながら、できるだけ役立つように答えてください。 回答には、有害、非倫理的、人種差別的、性差別的、有毒、危険、または違法なコンテンツを含めてはいけません。 回答は社会的に偏見がなく、本質的に前向きなものであることを確認してください。 質問が意味をなさない場合、または事実に一貫性がない場合は、正しくないことに答えるのではなく、その理由を説明してください。 質問の答えがわからない場合は、誤った情報を共有しないでください。
<</SYS>>
「ぼっち・ざ・ろっく!」のぼっちちゃんはどんな性格ですか?[/INST] アニメ・漫画シリーズ「ぼっち・ざ・ろっく!」の主人公「ぼっちちゃん」は、独特の個性を持ったユニークで面白いキャラクターです。 彼女の性格を表すかもしれない形容詞をいくつか挙げます。

1. ナイーブ: ぼっちちゃんは非常に無邪気でナイーブであると描かれることが多く、それが時々ユーモラスな誤解や特定の状況に対する予期せぬ反応を引き起こす可能性があります。
2. エネルギッシュ: ぼっちちゃんはたくさんのエネルギーと熱意を持っており、ギターを弾いたり音楽を演奏したりするなど、自分の興味や情熱を追求するためにそれを使います。
3. 決意: ぼっちちゃんは、世間知らずな性格にもかかわらず、目標を達成することに関しては非常に決意が強く、意欲的に取り組んでいます。 彼女は音楽のスキルを向上させ、ミュージシャンとして名を上げるために一生懸命働いています。
4. 優しい: ぼっちちゃんは親切で思いやりのある人で、常に他の人を助けたり、新しい友達を作ったりすることに積極的です。 彼女は友人やバンド仲間たちもとてもサポートしてくれます。
5. 風変わり:ぼっちちゃんは風変わりで遊び心のある性格を持っており、しばしばユニークで予期せぬアイデアや問題の解決策を思いつきます。
6. 感情的: ぼっちちゃんは自分の心を大切にし、自分の感情を表現することを恐れません。 彼女は時々敏感で感情的になることがありますが、それが彼女を非常に共感的で共感しやすいキャラクターにもしています。

全体として、ぼっちちゃんの性格は、無邪気さ、エネルギー、決意、優しさ、風変わりさ、そして感情の深さが混ざり合ったものであり、それが彼女を注目し、応援するのに魅力的で愛らしいキャラクターにしています。</s>



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