LoftQ Llama 3
Collection
LoftQ initialization for Llama-3 series • 4 items • Updated • 1
How to use LoftQ/Meta-Llama-3-70B-4bit-64rank with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="LoftQ/Meta-Llama-3-70B-4bit-64rank") # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("LoftQ/Meta-Llama-3-70B-4bit-64rank")
model = AutoModelForCausalLM.from_pretrained("LoftQ/Meta-Llama-3-70B-4bit-64rank")How to use LoftQ/Meta-Llama-3-70B-4bit-64rank with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "LoftQ/Meta-Llama-3-70B-4bit-64rank"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "LoftQ/Meta-Llama-3-70B-4bit-64rank",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/LoftQ/Meta-Llama-3-70B-4bit-64rank
How to use LoftQ/Meta-Llama-3-70B-4bit-64rank with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "LoftQ/Meta-Llama-3-70B-4bit-64rank" \
--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": "LoftQ/Meta-Llama-3-70B-4bit-64rank",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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/Meta-Llama-3-70B-4bit-64rank" \
--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": "LoftQ/Meta-Llama-3-70B-4bit-64rank",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use LoftQ/Meta-Llama-3-70B-4bit-64rank with Docker Model Runner:
docker model run hf.co/LoftQ/Meta-Llama-3-70B-4bit-64rank
| 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, Meta-Llama-3-70B-4bit-64rank, is obtained from LLAMA-3-70B.
The backbone is under LoftQ/Meta-Llama-3-70B-4bit-64rank and LoRA adapters are under the subfolder='loftq_init'.
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/Meta-Llama-3-70B-4bit-64rank"
base_model = AutoModelForCausalLM.from_pretrained(MODEL_ID)
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
@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}
}