Instructions to use dphn/dolphin-2_6-phi-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dphn/dolphin-2_6-phi-2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="dphn/dolphin-2_6-phi-2", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("dphn/dolphin-2_6-phi-2", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use dphn/dolphin-2_6-phi-2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dphn/dolphin-2_6-phi-2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dphn/dolphin-2_6-phi-2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/dphn/dolphin-2_6-phi-2
- SGLang
How to use dphn/dolphin-2_6-phi-2 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 "dphn/dolphin-2_6-phi-2" \ --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": "dphn/dolphin-2_6-phi-2", "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 "dphn/dolphin-2_6-phi-2" \ --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": "dphn/dolphin-2_6-phi-2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use dphn/dolphin-2_6-phi-2 with Docker Model Runner:
docker model run hf.co/dphn/dolphin-2_6-phi-2
Fine-tuning best practices?
#6
by duishoev - opened
This looks interesting. I fine tuned in my local mac for some tasks and the performance was not stellar. Do you mind sharing some tips or codebase to fine tune phi-2? Would greatly appreciate, thanks.
You can checkout my tunes here https://huggingface.co/Yhyu13/phi-2-sft-alpaca_gpt4_en-ep1-lora
here is my script for using llama_factory
#!/bin/bash
eval "$(conda shell.bash hook)"
conda activate llama_factory
MODEL_NAME=phi-2
STAGE=sft
EPOCH=1.0 #3.0
DATA=alpaca_gpt4_en
FT_TYPE=lora
LoRA_TARGET=Wqkv #q_proj,v_proj
TEMPLATE=default
PREDICTION_SAMPLES=20
MODEL_PATH=./models/$MODEL_NAME
if [ ! -d $MODEL_PATH ]; then
echo "Model not found: $MODEL_PATH"
return 1
fi
SAVE_PATH=./models/$STAGE/$MODEL_NAME-$STAGE-$DATA-ep$EPOCH-$FT_TYPE
if [ ! -d $SAVE_PATH ]; then
mkdir -p $SAVE_PATH
fi
DO_TRAIN=false
DO_PREDICT=false
DO_EXPORT=false
for arg in "$@"
do
if [[ "$arg" == "--train" ]]; then
echo "The '--train' argument is present in an argument: $arg"
DO_TRAIN=true
fi
if [[ "$arg" == "--pred" ]]; then
echo "The '--pred' argument is present in an argument: $arg"
DO_PREDICT=true
fi
if [[ "$arg" == "--exp" ]]; then
echo "The '--exp' argument is present in an argument: $arg"
DO_EXPORT=true
fi
done
if [ $DO_TRAIN == true ]; then
CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \
--seed 42 \
--stage $STAGE \
--model_name_or_path $MODEL_PATH \
--dataset $DATA \
--val_size .1 \
--template $TEMPLATE \
--finetuning_type $FT_TYPE \
--do_train \
--lora_target $LoRA_TARGET \
--output_dir $SAVE_PATH \
--overwrite_output_dir \
--overwrite_cache \
--per_device_train_batch_size 1 \
--gradient_accumulation_steps 4 \
--lr_scheduler_type cosine \
--logging_steps 10 \
--save_steps 1000 \
--learning_rate 5e-5 \
--num_train_epochs $EPOCH \
--do_eval \
--evaluation_strategy epoch \
--per_device_eval_batch_size 1 \
--prediction_loss_only \
--plot_loss \
--quantization_bit 4 \
--report_to tensorboard \
|& tee $SAVE_PATH/train_eval_log.txt
fi
if [ $DO_PREDICT == true ]; then
SAVE_PATH_PREDICT=$SAVE_PATH/Predict_$PREDICTION_SAMPLES
if [ ! -d $SAVE_PATH_PREDICT ]; then
mkdir -p $SAVE_PATH_PREDICT
fi
CUDA_VISIBLE_DEVICES=0 python src/train_bash.py \
--stage $STAGE \
--model_name_or_path $MODEL_PATH \
--do_predict \
--max_samples $PREDICTION_SAMPLES \
--predict_with_generate \
--dataset $DATA \
--template $TEMPLATE \
--finetuning_type $FT_TYPE \
--adapter_name_or_path $SAVE_PATH \
--output_dir $SAVE_PATH_PREDICT \
--per_device_eval_batch_size 1 \
|& tee $SAVE_PATH_PREDICT/predict_log.txt
fi
if [ $DO_EXPORT == true ]; then
EXPORT_PATH=./models/export/$MODEL_NAME-$STAGE-$DATA-ep$EPOCH
if [ ! -d $EXPORT_PATH ]; then
mkdir -p $EXPORT_PATH
fi
CUDA_VISIBLE_DEVICES=0 python src/export_model.py \
--model_name_or_path $MODEL_PATH \
--adapter_name_or_path $SAVE_PATH \
--template $TEMPLATE \
--finetuning_type $FT_TYPE \
--export_dir $EXPORT_PATH \
--export_size 5 \
|& tee $EXPORT_PATH/export_log.txt
fi