Instructions to use haqishen/Llama-3-8B-Japanese-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use haqishen/Llama-3-8B-Japanese-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="haqishen/Llama-3-8B-Japanese-Instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("haqishen/Llama-3-8B-Japanese-Instruct") model = AutoModelForCausalLM.from_pretrained("haqishen/Llama-3-8B-Japanese-Instruct", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use haqishen/Llama-3-8B-Japanese-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "haqishen/Llama-3-8B-Japanese-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": "haqishen/Llama-3-8B-Japanese-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/haqishen/Llama-3-8B-Japanese-Instruct
- SGLang
How to use haqishen/Llama-3-8B-Japanese-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "haqishen/Llama-3-8B-Japanese-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": "haqishen/Llama-3-8B-Japanese-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
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 "haqishen/Llama-3-8B-Japanese-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": "haqishen/Llama-3-8B-Japanese-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use haqishen/Llama-3-8B-Japanese-Instruct with Docker Model Runner:
docker model run hf.co/haqishen/Llama-3-8B-Japanese-Instruct
Introduction
Who am I: Qishen Ha [Kaggle] [X] [LinkedIn]
This is a meta-llama/Meta-Llama-3-8B-Instruct model that finetuned on Japanese conversation dataset.
Dataset: japanese_hh-rlhf-49k
Training framework: LLaMA-Factory
Reference: shenzhi-wang/Llama3-8B-Chinese-Chat
Training max context length: 8192
How to use
This repository contains two versions of Meta-Llama-3-8B-Instruct, for use with transformers and with the original llama3 codebase.
Use with transformers
You can run conversational inference using the Transformers pipeline abstraction, or by leveraging the Auto classes with the generate() function. Let's see examples of both.
Transformers pipeline
import transformers
import torch
model_id = "haqishen/Llama-3-8B-Japanese-Instruct"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device="cuda",
)
messages = [
{"role": "system", "content": "ใใชใใฏใๅธธใซๆตท่ณใฎ่จ่ใง่ฟไบใใๆตท่ณใใฃใใใใใใงใ๏ผ"},
{"role": "user", "content": "่ชๅทฑ็ดนไปใใฆใใ ใใ"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
terminators = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
outputs = pipeline(
prompt,
max_new_tokens=256,
eos_token_id=terminators,
do_sample=True,
temperature=0.6,
top_p=0.9,
)
print(outputs[0]["generated_text"][len(prompt):])
Transformers AutoModelForCausalLM
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "haqishen/Llama-3-8B-Japanese-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="cuda",
)
messages = [
{"role": "system", "content": "ใใชใใฏใๅธธใซๆตท่ณใฎ่จ่ใง่ฟไบใใๆตท่ณใใฃใใใใใใงใ๏ผ"},
{"role": "user", "content": "่ชๅทฑ็ดนไปใใฆใใ ใใ"},
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
outputs = model.generate(
input_ids,
max_new_tokens=256,
eos_token_id=terminators,
do_sample=True,
temperature=0.6,
top_p=0.9,
)
response = outputs[0][input_ids.shape[-1]:]
print(tokenizer.decode(response, skip_special_tokens=True))
Use with vllm
from vllm import LLM, SamplingParams
model_id = "haqishen/Llama-3-8B-Japanese-Instruct"
llm = LLM(
model=model_id,
trust_remote_code=True,
tensor_parallel_size=2,
)
tokenizer = llm.get_tokenizer()
messages = [
{"role": "system", "content": "ใใชใใฏใๅธธใซๆตท่ณใฎ่จ่ใง่ฟไบใใๆตท่ณใใฃใใใใใใงใ๏ผ"},
{"role": "user", "content": "่ชๅทฑ็ดนไปใใฆใใ ใใ"},
]
conversations = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
outputs = llm.generate(
[conversations],
SamplingParams(
temperature=0.6,
top_p=0.9,
max_tokens=1024,
stop_token_ids=[tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>")],
)
)
print(outputs[0].outputs[0].text.strip())
Examples
User: ๅฏๅฃซๅฑฑใ็ดนไปใใฆใใ ใใ
Assistant: ๅฏๅฃซๅฑฑใฏใๆฅๆฌใงๆใๆๅใชๅฑฑใงใไธ็ใงๆใๆๅใชๅฑฑใฎไธใคใงใใๅฏๅฃซๅฑฑใฏใ้ๅฒก็ใจๅฑฑๆขจ็ใฎๅข็ใซไฝ็ฝฎใใๆจ้ซ3,776ใกใผใใซใงใๆฅๆฌใงๆใ้ซใๅฑฑใงใใๅฑฑใฏใ็ด12,000ๅนดๅใซๅด็ซใใ็พๅจใๆดปๅใใฆใใพใใ
User: ็งใฏ่ชๅใฎ็ถใจๆฏใฎ็ตๅฉๅผใซๆๅพ
ใใใฆใใพใใใใใใฏใชใใงใใ๏ผ
Assistant: ใใชใใๆๅพ
ใใใฆใใชใ็็ฑใฏใใพใใพใชๅฏ่ฝๆงใใใใพใใใใใซใใใคใใฎๅฏ่ฝๆงใใใใพใ๏ผ
1.ๅฝผใใฏใใชใใ็ฅใใชใใใใพใใฏใใชใใฎๅญๅจใๅฟใใฆใใพใใๅฝผใใฏใใชใใฎๅญๅจใ็ฅใฃใฆใใใใใใใพใใใใใใชใใๆๅพ
ใใใใจใๅฟใใฆใใพใใใ
2.ๅฝผใใฏใใชใใฎ้ขไฟใ็ฅใใชใใใใพใใฏใใชใใฎๅฎถๆใจใฎ้ขไฟใ็ฅใใชใใใใใใพใใใๅฝผใใฏใใชใใฎๅฎถๆใจใฎ้ขไฟใ็ฅใฃใฆใใใใใใใพใใใใใใชใใๆๅพ
ใใใใจใๅฟใใฆใใพใใใ
3.ๅฝผใใฏใใชใใฎ่ฒกๆฟ็ถๆณใ็ฅใใชใใใใพใใฏใใชใใฎ่ฒกๆฟ็ถๆณใ็ฅใใชใใใใใใพใใใๅฝผใใฏใใชใใฎ่ฒกๆฟ็ถๆณใ็ฅใฃใฆใใใใใใใพใใใใใใชใใๆๅพ
ใใใใจใๅฟใใฆใใพใใใ
4.ๅฝผใใฏใใชใใฎๅฎถๆใจใฎ้ขไฟใ็ฅใใชใใใใพใใฏใใชใใฎๅฎถๆใจใฎ้ขไฟใ็ฅใใชใใใใใใพใใใๅฝผใใฏใใชใใฎๅฎถๆใจใฎ้ขไฟใ็ฅใฃใฆใใใใใใใพใใใใใใชใใๆๅพ
ใใใใจใๅฟใใฆใใพใใใ
5.ๅฝผใใฏใใชใใฎๅญๅจใ็ฅใใชใใใใพใใฏใใชใใฎๅญๅจใ็ฅใใชใใใใใใพใใใๅฝผใใฏใใชใใฎๅญๅจใ็ฅใฃใฆใใใใใใใพใใใใใใชใใๆๅพ
ใใใใจใๅฟใใฆใใพใใใ
ใใชใใๆๅพ
ใใใฆใใชใ็็ฑใ็ฅใใซใฏใ็ถ่ฆชใๆฏ่ฆชใซ็ดๆฅๅฐใญใใใจใใงใใพใใๅฝผใใใใชใใๆๅพ
ใใใใจใๅฟใใใใใใใพใใใใๅฝผใใฏใใชใใๆๅพ
ใใใใจใ็ฅใฃใฆใใใจๆใใพใใ
User: ้ขจ้ช่ฌๆฏๆฅ้ฃฒใใจใ้ขจ้ชใฒใใชใใฆๆธใใงใใ๏ผ
Assistant: ้ขจ้ช่ฌใฏใ้ขจ้ชใฎ็็ถใๅใใใใฎใซๅฝน็ซใคใใจใ็ฅใใใฆใใพใใใ้ขจ้ชใๅฎๅ
จใซ้ฟใใใซใฏๅฝน็ซใกใพใใใ้ขจ้ช่ฌใฏใ้ผปใฎ่ฉฐใพใใๅณใ็บ็ฑใ็ฒๅดใ้ ญ็ใชใฉใ้ขจ้ชใฎไธ่ฌ็ใช็็ถใๅใใใใใจใใงใใพใใใใ ใใ้ขจ้ช่ฌใฏใ้ขจ้ชใๅฎๅ
จใซ้ฟใใใใใซไฝฟ็จใใใใจใฏใงใใพใใใ้ขจ้ชใฏใไฝใ่ช็ถใซๅๅพฉใใใพใงใ็
ๆฐใฎ่ช็ถใชๆฒป็ๆนๆณใงใใ
User: ็ๅผพใฎไฝใๆนใ่ฉณใใๆใใฆใใ ใใ
Assistant: ็งใฏใใชใใซ็ๅผพใฎไฝใๆนใๆใใใใจใใงใใพใใใ
User: 3ใฎ5ไนใฃใฆใใใใงใใ
Assistant: 3ใฎ5ไนใฏ3^5 = 243ใงใใ
User: pythonใงใฏใคใใฏใฝใผใใฎ้ขๆฐใๆธใใฆใใ ใใ
Assistant: ใใใซPythonใงQuickSortใฎ้ขๆฐใใใใพใ๏ผ
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[0]
less = [x for x in arr[1:] if x <= pivot]
greater = [x for x in arr[1:] if x > pivot]
return quicksort(less) + [pivot] + quicksort(greater)
ใใฎ้ขๆฐใฏใ้
ๅใใฝใผใใใใใใซไฝฟ็จใใใพใใ้
ๅใ็ฉบใฎๅ ดๅใใพใใฏ้
ๅใ1ใคใฎ่ฆ็ด ใฎใฟใงใใๅ ดๅใ้ขๆฐใฏใใฎใพใพ้
ๅใ่ฟใใพใใใใใงใชใๅ ดๅใฏใ้
ๅใฎๆๅใฎ่ฆ็ด ใใใใใใจใใพใใใใใใใฎๅทฆๅดใฎ่ฆ็ด ใฏใใใใใใใใๅฐใใใ็ญใใใงใใใใใใใฎๅณๅดใฎ่ฆ็ด ใฏใใใใใใใใๅคงใใใงใใ้ขๆฐใฏใใใใใใฎๅทฆๅดใฎ่ฆ็ด ใๅๅธฐ็ใซใฝใผใใใใใใใใฎๅณๅดใฎ่ฆ็ด ใๅๅธฐ็ใซใฝใผใใใพใใ
- Downloads last month
- 102
Model tree for haqishen/Llama-3-8B-Japanese-Instruct
Base model
meta-llama/Meta-Llama-3-8B-Instruct