kunishou/databricks-dolly-15k-ja
Viewer • Updated • 15k • 1.15k • 89
How to use if001/llama2_ja_small_instruct with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="if001/llama2_ja_small_instruct")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("if001/llama2_ja_small_instruct")
model = AutoModelForCausalLM.from_pretrained("if001/llama2_ja_small_instruct")How to use if001/llama2_ja_small_instruct with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "if001/llama2_ja_small_instruct"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "if001/llama2_ja_small_instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/if001/llama2_ja_small_instruct
How to use if001/llama2_ja_small_instruct with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "if001/llama2_ja_small_instruct" \
--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": "if001/llama2_ja_small_instruct",
"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 "if001/llama2_ja_small_instruct" \
--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": "if001/llama2_ja_small_instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use if001/llama2_ja_small_instruct with Docker Model Runner:
docker model run hf.co/if001/llama2_ja_small_instruct
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("if001/llama2_ja_small_instruct")
model = AutoModelForCausalLM.from_pretrained("if001/llama2_ja_small_instruct")日本語でtrainingしたllama2をinstruction用のデータセットでsftしたものになります
base: https://huggingface.co/if001/llama2_ja_small
trainingは以下のscript参照 https://github.com/Lightning-AI/lit-gpt/tree/main
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("if001/sentencepiece_ja", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("if001/llama2_ja_small")
import torch
from transformers import GenerationConfig
instruct="東京でおすすめの観光地を教えてください。。"
prompt=f"""以下は、タスクを説明する指示です。要求を適切に満たす応答を書きなさい。
### 指示:
{instruct}
### 出力:
"""
inputs = tokenizer(prompt, return_tensors="pt")
input_ids = inputs["input_ids"]
generation_config = GenerationConfig(
temperature=0.8,
top_p=0.95,
top_k=50,
num_beams=1,
do_sample=True,
repetition_penalty=1.2,
pad_token_id= tokenizer.pad_token_id,
# pad_token_id=tokenizer.unk_token_id,
eos_token_id=tokenizer.eos_token_id
)
with torch.no_grad():
generation_output = model.generate(
input_ids=input_ids,
generation_config=generation_config,
return_dict_in_generate=True,
output_scores=True,
max_new_tokens=64,
)
s = generation_output.sequences[0]
output = tokenizer.decode(s)
print(output)
出力
以下は、タスクを説明する指示です。要求を適切に満たす応答を書きなさい。
### 指示:
東京でおすすめの観光地を教えてください。。
### 出力:
- 東京で訪れる料理
- 美術館
- 博物館・新旧東の北京にある船浴場
- モニュッキングスの4つの空き地
- シュノーケリングチャイム、夜の奇抜な街
- ツアーなど、芸術/建築の6つ
https://huggingface.co/datasets/kunishou/hh-rlhf-49k-ja https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="if001/llama2_ja_small_instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)