QLoRA: Efficient Finetuning of Quantized LLMs
Paper • 2305.14314 • Published • 62
How to use yi71/qwen3.5-4B-qlora with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen3.5-4B")
model = PeftModel.from_pretrained(base_model, "yi71/qwen3.5-4B-qlora")How to use yi71/qwen3.5-4B-qlora with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="yi71/qwen3.5-4B-qlora")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("yi71/qwen3.5-4B-qlora", dtype="auto")How to use yi71/qwen3.5-4B-qlora with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "yi71/qwen3.5-4B-qlora"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "yi71/qwen3.5-4B-qlora",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/yi71/qwen3.5-4B-qlora
How to use yi71/qwen3.5-4B-qlora with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "yi71/qwen3.5-4B-qlora" \
--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": "yi71/qwen3.5-4B-qlora",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "yi71/qwen3.5-4B-qlora" \
--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": "yi71/qwen3.5-4B-qlora",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use yi71/qwen3.5-4B-qlora with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for yi71/qwen3.5-4B-qlora to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for yi71/qwen3.5-4B-qlora to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for yi71/qwen3.5-4B-qlora to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="yi71/qwen3.5-4B-qlora",
max_seq_length=2048,
)How to use yi71/qwen3.5-4B-qlora with Docker Model Runner:
docker model run hf.co/yi71/qwen3.5-4B-qlora
A QLoRA fine-tuned adapter for unsloth/Qwen3.5-4B, optimized for specific domain tasks.
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"unsloth/Qwen3.5-4B",
torch_dtype="auto",
device_map="auto",
)
# Load adapter
model = PeftModel.from_pretrained(base_model, "yi71/qwen3.5-4B-qlora")
tokenizer = AutoTokenizer.from_pretrained("yi71/qwen3.5-4B-qlora")
# Inference
messages = [
{"role": "user", "content": "你好,请介绍一下你自己。"}
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
# Merge adapter into base model for standalone use
merged_model = model.merge_and_unload()
merged_model.save_pretrained("merged_model")
tokenizer.save_pretrained("merged_model")
| Parameter | Value |
|---|---|
| Method | QLoRA (4-bit quantization + LoRA) |
| Rank (r) | 8 |
| LoRA Alpha | 16 |
| LoRA Dropout | 0.05 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Quantization | 4-bit (QLoRA) |
| Hardware | Single consumer GPU |
| PEFT Version | 0.19.1 |
{
"peft_type": "LORA",
"task_type": "CAUSAL_LM",
"r": 8,
"lora_alpha": 16,
"lora_dropout": 0.05,
"target_modules": ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
}
@article{dettmers2023qlora,
title={QLoRA: Efficient Finetuning of Quantized Language Models},
author={Dettmers, Tim and Pagnoni, Artidoro and Holtzman, Ari and Zettlemoyer, Luke},
journal={arXiv preprint arXiv:2305.14314},
year={2023}
}