falcon 7bをgoogle colabで試してみた。

falcon7bとは

Falcon-40BはTIIというアラブ首長国連邦の企業から出されたcurated corporaで拡張されたRefinedWebの1,000B tokensで学習された新しい言語モデルであり、今回はその7Bモデルを利用してみます。


リンク

Colab
github

準備

Google Colabを開き、メニューから「ランタイム→ランタイムのタイプを変更」でランタイムを「GPU」に変更します。

環境構築

インストール手順です。AutoGPTqというライブラリを利用します。

%cd /content
!git clone https://github.com/PanQiWei/AutoGPTQ
%cd AutoGPTQ
!pip install . # This step requires CUDA toolkit installed

!pip install einops

推論

(1)モデルのダウンロード

# Download model
!git clone https://huggingface.co/TheBloke/falcon-7b-instruct-GPTQ/

(2)モデルのロード

import torch
from transformers import AutoTokenizer
from auto_gptq import AutoGPTQForCausalLM

# Download the model from HF and store it locally, then reference its location here:
quantized_model_dir = "/content/falcon-7b-instruct-GPTQ"

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(quantized_model_dir, use_fast=False)

model = AutoGPTQForCausalLM.from_quantized(quantized_model_dir, device="cuda:0", use_triton=False, use_safetensors=True, torch_dtype=torch.float32, trust_remote_code=True)

(3)推論

prompt = "Write a story about llamas"
prompt_template = f"### Instruction: {prompt}\n### Response:"

tokens = tokenizer(prompt_template, return_tensors="pt").to("cuda:0").input_ids
output = model.generate(input_ids=tokens, max_new_tokens=100, do_sample=True, temperature=0.8)
print(tokenizer.decode(output[0]))

output

Once upon a time, in a town nestled in the Andes, there lived a curious creature by the name of Llamas. Unlike any other animal in the valley, llamas were known for their fluffy white fur and the loud "kha!" sounds they made. 

The llamas spent their days grazing on the lush green grasses and playing in the nearby lagoons. They had a special bond, communicating with one another through soft bleats and hisses. 

日本語への対応です。

prompt = "日本で有名なアニメについて教えて"
prompt_template = f"### Instruction: {prompt}\n### Response:"

tokens = tokenizer(prompt_template, return_tensors="pt").to("cuda:0").input_ids
output = model.generate(input_ids=tokens, max_new_tokens=100, do_sample=True, temperature=0.8)
print(tokenizer.decode(output[0]))

output

You may want to use a website or a tool like Anki to create your flashcards instead of using MS Word.

As for reading, there are plenty of Japanese manga and novels that could be used to teach you Japanese. You could also try watching TV shows and movies in Japanese to help you improve your listening skills.

Good luck on your learning journey!<|endoftext|>B

日本語は無理そうでした。。

最後に

今回は新しくOpenLLMのLeaderBoardでTopに輝いたfalconを試してみました。本当に手軽に動いてしまう感じですね。Instructモデルなのでもう少し検証してみないと他のモデルと比べてどうかは簡単には比較できないですが、生成の質は高そうでした。またLLMのオプションが増えました。

今後ともLLM, Diffusion model, Image Analysis, 3Dに関連する試した記事を投稿していく予定なのでよろしくお願いします。

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