llm-jp/databricks-dolly-15k-ja
Viewer • Updated • 15k • 348 • 18
How to use alfredplpl/Llama-3-8B-Instruct-Ja with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="alfredplpl/Llama-3-8B-Instruct-Ja")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("alfredplpl/Llama-3-8B-Instruct-Ja")
model = AutoModelForCausalLM.from_pretrained("alfredplpl/Llama-3-8B-Instruct-Ja")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use alfredplpl/Llama-3-8B-Instruct-Ja with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "alfredplpl/Llama-3-8B-Instruct-Ja"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "alfredplpl/Llama-3-8B-Instruct-Ja",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/alfredplpl/Llama-3-8B-Instruct-Ja
How to use alfredplpl/Llama-3-8B-Instruct-Ja with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "alfredplpl/Llama-3-8B-Instruct-Ja" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "alfredplpl/Llama-3-8B-Instruct-Ja",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "alfredplpl/Llama-3-8B-Instruct-Ja" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "alfredplpl/Llama-3-8B-Instruct-Ja",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use alfredplpl/Llama-3-8B-Instruct-Ja with Docker Model Runner:
docker model run hf.co/alfredplpl/Llama-3-8B-Instruct-Ja
このリポジトリはLlama 3を日本語化しようとしたモデルのリポジトリです。4/23に更新したため、新しくダウンロードすることをオススメします。
Llama 3 ライセンスなので商用利用可能です。ただし、Llama 3ライセンスをよく読んで使ってください。
手っ取り早くやるならデモを使ってください。次点はColabがおすすめです。 ローカルでやる場合は次のとおりです。
まず、ライブラリを次のようにインストールします。
pip install -U transformers accelerate
その後、以下のコードを実行してください。
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("alfredplpl/Llama-3-8B-Instruct-Ja")
model = AutoModelForCausalLM.from_pretrained("alfredplpl/Llama-3-8B-Instruct-Ja", device_map="auto", torch_dtype=torch.bfloat16)
# プロンプトの準備
messages = [
{
'role': "system",
'content': "あなたは日本語で回答するAIアシスタントです。"
},
{
'role': "user",
'content': "猫と犬、どっちが好き?"
}
]
prompt=tokenizer.apply_chat_template(messages, tokenize=False)
# 推論の実行
input_ids = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**input_ids,
max_new_tokens=128,
do_sample=True,
top_p=0.95,
temperature=0.2,
repetition_penalty=1.1,
eos_token_id=[
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
],
)
print(tokenizer.decode(outputs[0]))
次のような結果が得られるはずです。
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
あなたは日本語で回答するAIアシスタントです。<|eot_id|><|start_header_id|>user<|end_header_id|>
猫と犬、どっちが好き?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
猫と犬の両方を飼っているので、どちらも好きだ!<|eot_id|>
meta-llama/Meta-Llama-3-8B-Instructに対して、cl-nagoya/auto-wiki-qaにある約240万件の学習データでLoRAによるインストラクションチューニングを1epoch行い、LoRAをマージしました。 その後、そのモデルに対して、llm-jp/databricks-dolly-15k-jaでLoRAによるインストラクションチューニングを5epoch行い、LoRAをマージしました。 これらの学習はすべて教師あり学習で行いました。
Base model
meta-llama/Meta-Llama-3-8B-Instruct