LoginSignup
1
1

Japanese Stable LM 2 1.6BをDatabricksで動かしてみる

Posted at

1.6Bとはなかなか軽量な。

stabilityai/japanese-stablelm-2-instruct-1_6bを動かしてみます。

使用するにはコンタクト情報を入力する必要があります。
Screenshot 2024-05-09 at 16.47.05.png

DatabricksでGPUクラスターを準備して、ノートブックを作成します。

from huggingface_hub import login
login()
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_name = "stabilityai/japanese-stablelm-2-instruct-1_6b"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)

# The next line may need to be modified depending on the environment
model = AutoModelForCausalLM.from_pretrained(
    model_name, 
    torch_dtype=torch.float16, 
    low_cpu_mem_usage=True, 
    device_map="auto",
    trust_remote_code=True,
)

prompt = [
    {"role": "system", "content": "あなたは役立つアシスタントです。"},
    {"role": "user", "content": "「情けは人のためならず」ということわざの意味を小学生でも分かるように教えてください。"},
]
inputs = tokenizer.apply_chat_template(
    prompt,
    add_generation_prompt=True,
    return_tensors="pt",
).to(model.device)

# this is for reproducibility.
# feel free to change to get different result
seed = 23
torch.manual_seed(seed)

tokens = model.generate(
    inputs,
    max_new_tokens=128,
    temperature=0.99,
    top_p=0.95,
    do_sample=True,
)

out = tokenizer.decode(tokens[0], skip_special_tokens=False)
print(out)

<|system|>
あなたは役立つアシスタントです。<|endoftext|>
<|user|>
「情けは人のためならず」ということわざの意味を小学生でも分かるように教えてください。<|endoftext|>
<|assistant|>
「情けは人のためならず」とは、優しいことをしてあげると、いつかそれが自分に返ってくるという意味のことわざです。<|endoftext|>

おおー。モデルのダウンロードも1分くらいで終わってすぐにレスポンスが返ってきました。

他の質問で。

prompt = [
    {"role": "system", "content": "あなたは役立つアシスタントです。"},
    {"role": "user", "content": "機械学習を小学生でも分かるように簡潔に教えてください。"},
]
inputs = tokenizer.apply_chat_template(
    prompt,
    add_generation_prompt=True,
    return_tensors="pt",
).to(model.device)

tokens = model.generate(
    inputs,
    max_new_tokens=500,
    temperature=0.99,
    top_p=0.95,
    do_sample=True,
)

out = tokenizer.decode(tokens[0], skip_special_tokens=False)
print(out)

<|system|>
あなたは役立つアシスタントです。<|endoftext|>
<|user|>
機械学習を小学生でも分かるように簡潔に教えてください。<|endoftext|>
<|assistant|>
機械学習とは、コンピュータにデータを分析させることで、経験や知識から学習し、自動的に問題解決や制御を行う技術のことです。

例えば、猫がカメラを見ているのを検出し、AIによって「猫が映っている」と認識させることが可能です。これは機械学習を使って、何度も「猫がカメラを見ている」というデータを見たり聞いたりしたことで、学習し、そのデータから検出する方法を学んだからです。<|endoftext|>

(肌感覚ですが)1.6Bでこれはすごいですね。

はじめてのDatabricks

はじめてのDatabricks

Databricks無料トライアル

Databricks無料トライアル

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1