Instructions to use lxuechen/phi-2-sft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lxuechen/phi-2-sft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lxuechen/phi-2-sft", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("lxuechen/phi-2-sft", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use lxuechen/phi-2-sft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lxuechen/phi-2-sft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lxuechen/phi-2-sft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/lxuechen/phi-2-sft
- SGLang
How to use lxuechen/phi-2-sft 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 "lxuechen/phi-2-sft" \ --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": "lxuechen/phi-2-sft", "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 "lxuechen/phi-2-sft" \ --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": "lxuechen/phi-2-sft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use lxuechen/phi-2-sft with Docker Model Runner:
docker model run hf.co/lxuechen/phi-2-sft
Can't reproduce the model
Hello, thank you for making this model available!
I tried to reproduce the model using the settings from the model card. While the model works fine (follows instructions and properly stops at eos_token, etc.) I don't get the same results on the arc_challenge@25:
-phi-2 : 0.6109
-phi-sft : 0.6280
-attempt : 0.616
In terms of training settings, the only difference is that I use gradient accumulation to mimic the batch size of 64 on a single GPU:
n_epochs = 2
batch_size = 1
effective_batch_size = 64
grad_acc = max(1, int(effective_batch_size/batch_size))
training_arguments = TrainingArguments(
output_dir=".",
num_train_epochs=n_epochs,
per_device_train_batch_size=batch_size,
gradient_accumulation_steps=grad_acc,
logging_steps=1,
learning_rate=2e-5,
lr_scheduler_type="cosine",
warmup_ratio=0.03,
weight_decay=0.001,
max_steps=-1,
save_steps=10000000,
bf16=True
)
I am using the model from refs/pr/23 revision, bfloat16, training only attention and mlp layers (weights + bias). Training the whole model or with LoRA gives worse.
model = transformers.AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True, torch_dtype=torch.bfloat16,
flash_attn=True, flash_rotary=True, fused_dense=True,
device_map='cuda',
revision="refs/pr/23")
Any tips are highly appreciated, thank you in advance!