kurogane/extracted_chat_datasets_jpen_small_8k
Preview • Updated • 175
How to use kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1")
model = AutoModelForCausalLM.from_pretrained("kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1")
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 kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1
How to use kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1" \
--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": "kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1",
"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 "kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1" \
--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": "kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1 with Docker Model Runner:
docker model run hf.co/kurogane/llm-jp-3.1-1.8b-instruct4-ChatML-preview1
ChatMLnised llm-jp-3.1 model series.
This model was trained using Unsloth.
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = r"/media/kurogane/datasets/chatmled/outputs_llmjp_chatml_sft_small/merged_16bit_unpadded" # ←あなたのパスに合わせる
tokenizer = AutoTokenizer.from_pretrained(
model_id,
use_fast=True,
)
dtype = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.is_bf16_supported() else torch.float16
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=dtype,
device_map="auto",
)
model.eval()
messages = [
{"role": "system", "content": "あなたは親切で誠実なAIアシスタントです。"},
{"role": "user", "content": ""こんにちは、pytorchについて教えてください。"},
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
inputs = tokenizer(prompt, return_tensors="pt", padding=False)
# 転載元: https://touch-sp.hatenablog.com/entry/2025/03/17/164018
# ======
# token_type_idsを削除
if "token_type_ids" in inputs:
del inputs["token_type_ids"]
# ======
inputs = {k: v.to(model.device) for k, v in inputs.items()}
with torch.no_grad():
out = model.generate(
**inputs,
max_new_tokens=256,
do_sample=True,
temperature=0.7,
top_p=0.9,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
print(tokenizer.decode(out[0], skip_special_tokens=False))
result
<s><|im_start|> system
あなたは親切で誠実なAIアシスタントです。<|im_end|>
<|im_start|> user
こんにちは、pytorchについて教えてください。<|im_end|>
<|im_start|> assistant
こんにちは!PyTorchについてお話しできて嬉しいです。
PyTorchは、Facebook AI Research (FAIR) によって開発された深層学習フレームワークです。2014年にリリースされ、直感的で使いやすいインターフェースと、高速な計算能力で知られています。特に研究者や開発者に人気があります。
以下にPyTorchの特徴をいくつか挙げます:
1. **直感的なAPI**: PyTorchはPythonのコードに非常に近い形で書かれるため、他の深層学習フレームワーク(例えばTensorFlow)に比べて学習曲線が緩やかです。
2. **動的計算グラフ**: PyTorchは計算グラフを動的に構築し、必要に応じて変更することができます。これは柔軟性と高速な計算を可能にします。
3. **簡単なデバッグ**: PyTorchはデバッグが容易で、トレースや変数の値を簡単に確認できる機能があります。
4. **豊富なライブラリ**: PyTorchは広範なライブラリを提供しており、画像処理、自然言語処理、音声認識などさまざまな分野で利用されています。
5. **コミュニティとサポート**: PyTorchは活発なコミュニティを持ち、多くのドキュメントやチュートリアルが公開されています。また、オンラインフォーラムやQ&Aサイトでも多くの情報を得られます。
PyTor
Base model
llm-jp/llm-jp-3.1-1.8b-instruct4