Text Generation
Transformers
Safetensors
Japanese
phi3
dpo
conversational
custom_code
text-generation-inference
Instructions to use eliashasnat/phi-3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use eliashasnat/phi-3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="eliashasnat/phi-3", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("eliashasnat/phi-3", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("eliashasnat/phi-3", trust_remote_code=True, 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use eliashasnat/phi-3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "eliashasnat/phi-3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "eliashasnat/phi-3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/eliashasnat/phi-3
- SGLang
How to use eliashasnat/phi-3 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 "eliashasnat/phi-3" \ --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": "eliashasnat/phi-3", "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 "eliashasnat/phi-3" \ --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": "eliashasnat/phi-3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use eliashasnat/phi-3 with Docker Model Runner:
docker model run hf.co/eliashasnat/phi-3
metadata
library_name: transformers
tags:
- dpo
license: mit
datasets:
- llm-jp/hh-rlhf-12k-ja
language:
- ja
モデル
- ベースモデル:microsoft/Phi-3-mini-4k-instruct
- 学習データセット:llm-jp/hh-rlhf-12k-ja
- 学習方式:フルパラメータチューニング
サンプル
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained(
"ryota39/Phi-3-mini-4k-instruct-dpo",
trust_remote_code=True,
)
model = AutoModelForCausalLM.from_pretrained(
"ryota39/Phi-3-mini-4k-instruct-dpo",
device_map="auto",
torch_dtype='auto',
trust_remote_code=True,
)
text = "<|user|>\n与えられた質問に対して英語で思考し、日本語で答えてください。東京の観光地を教えてください。\n<|end|>\n<|assistant|>\n"
tokenized_input = tokenizer.encode(
text,
add_special_tokens=False,
return_tensors="pt"
).to(model.device)
with torch.no_grad():
output = model.generate(
tokenized_input,
max_new_tokens=500,
do_sample=True,
top_p=0.95,
temperature=0.8,
repetition_penalty=1.0
)[0]
print(tokenizer.decode(output))
出力例
<|user|> 与えられた質問に対して英語で思考し、日本語で答えてください。東京の観光地を教えてください。
<|end|><|assistant|> 東京には様々な観光地がありますが、代表的なものとして以下のようなものがあります。
1. 浅草寺(あさくさじ) - 歴史ある寺院で、浅草の様々な景観や、人々が集まる場所です。
2. 東京タワー - 日本の象徴的な電波塔であり、東京の景色を眺めるのに最適な場所です。
3. 皇居(こうこく) - 日本の皇族が住んでいる皇居で、日本の歴史を感じられる郊外もあります。
4. 渋谷スクランブル交差点 - 日本のトレンドを象徴するスクランブル交差点で、最新のストリートファッションやアートを見ることができます。
5. 渋谷の百 ár - 若者の雰囲気を感じられるショップ街で、最新のグッズを見つけることができます。
これらは東京を象徴する一部の観光地ですが、他にもたくさんの観光地がありますので、ご興味のある場所をご確認ください。<|end|>