Instructions to use daekeun-ml/phi-2-ko-v0.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use daekeun-ml/phi-2-ko-v0.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="daekeun-ml/phi-2-ko-v0.1", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("daekeun-ml/phi-2-ko-v0.1", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("daekeun-ml/phi-2-ko-v0.1", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use daekeun-ml/phi-2-ko-v0.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "daekeun-ml/phi-2-ko-v0.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "daekeun-ml/phi-2-ko-v0.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/daekeun-ml/phi-2-ko-v0.1
- SGLang
How to use daekeun-ml/phi-2-ko-v0.1 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 "daekeun-ml/phi-2-ko-v0.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "daekeun-ml/phi-2-ko-v0.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "daekeun-ml/phi-2-ko-v0.1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "daekeun-ml/phi-2-ko-v0.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use daekeun-ml/phi-2-ko-v0.1 with Docker Model Runner:
docker model run hf.co/daekeun-ml/phi-2-ko-v0.1
Encoding of vocabulary
Can you please tell me what is the encoding of the vocabulary text? For example, the readme example shows tokenizer output of ['ìķĦë§Ī', 'ì¡´', 'ĠìĦ¸', 'ìĿ´ì§Ģ', 'ë©ĶìĿ´', '커'] when tokenizing "아마존 세이지메이커". How do I map the tokens to the korean characters unicode characters?
The tokenizer used in phi-2 is not a BPE, but a byte-level BPE like GPT-2, so Unicode conversion is required to check normal characters.
See Colab below for more details.
https://colab.research.google.com/drive/15tMASZ0NLm8bnxkM4uXCRgdzznSpbp9L?usp=sharing#scrollTo=UwJT5ZSfwOGc
See the code snippet below to restore the original string.
input_str = "아마존 세이지메이커"
tokenized = tokenizer.tokenize(input_str)
encoded = tokenizer.encode_plus(input_str)
decoded = tokenizer.decode(encoded['input_ids'])
print(encoded)
print(tokenized) # just mapping to token id; you cannot see the actual character!
print(decoded)