Instructions to use LoftQ/Phi-3-mini-4k-instruct-4bit-64rank with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LoftQ/Phi-3-mini-4k-instruct-4bit-64rank with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="LoftQ/Phi-3-mini-4k-instruct-4bit-64rank", 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("LoftQ/Phi-3-mini-4k-instruct-4bit-64rank", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("LoftQ/Phi-3-mini-4k-instruct-4bit-64rank", trust_remote_code=True) 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
- vLLM
How to use LoftQ/Phi-3-mini-4k-instruct-4bit-64rank with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LoftQ/Phi-3-mini-4k-instruct-4bit-64rank" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LoftQ/Phi-3-mini-4k-instruct-4bit-64rank", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/LoftQ/Phi-3-mini-4k-instruct-4bit-64rank
- SGLang
How to use LoftQ/Phi-3-mini-4k-instruct-4bit-64rank 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 "LoftQ/Phi-3-mini-4k-instruct-4bit-64rank" \ --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": "LoftQ/Phi-3-mini-4k-instruct-4bit-64rank", "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 "LoftQ/Phi-3-mini-4k-instruct-4bit-64rank" \ --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": "LoftQ/Phi-3-mini-4k-instruct-4bit-64rank", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use LoftQ/Phi-3-mini-4k-instruct-4bit-64rank with Docker Model Runner:
docker model run hf.co/LoftQ/Phi-3-mini-4k-instruct-4bit-64rank
LoftQ Initialization
| Paper | Code | PEFT Example |
LoftQ (LoRA-fine-tuning-aware Quantization) provides a quantized backbone Q and LoRA adapters A and B, given a full-precision pre-trained weight W.
This model, LoftQ/Phi-3-mini-4k-instruct-4bit-64rank, is obtained from Phi-3-mini-4k-instruct.
The backbone is under LoftQ/Phi-3-mini-4k-instruct-4bit-64rank and LoRA adapters are under the subfolder='loftq_init'.
Model Info
Backbone
- Stored format: nf4
- Size: ~ 2.5 GiB
- Loaded format: bitsandbytes nf4
- Size loaded on GPU: ~2.5 GiB
LoRA adapters
- rank: 64
- lora_alpha: 16
- target_modules: ["qkv_proj", "o_proj", "up_gate_proj", "down_proj"]
- rank_pattern: {"qkv_proj": 192, "up_gate_proj": 128}
Usage
Training Here's an example of loading this model and preparing for the LoRA fine-tuning.
import torch
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
MODEL_ID = "LoftQ/Phi-3-mini-4k-instruct-4bit-64rank"
base_model = AutoModelForCausalLM.from_pretrained(MODEL_ID, trust_remote_code=True)
peft_model = PeftModel.from_pretrained(
base_model,
MODEL_ID,
subfolder="loftq_init",
is_trainable=True,
)
# Do training with peft_model ...
See the full code at our Github Repo
Citation
@article{li2023loftq,
title={Loftq: Lora-fine-tuning-aware quantization for large language models},
author={Li, Yixiao and Yu, Yifan and Liang, Chen and He, Pengcheng and Karampatziakis, Nikos and Chen, Weizhu and Zhao, Tuo},
journal={arXiv preprint arXiv:2310.08659},
year={2023}
}
- Downloads last month
- 2