Instructions to use sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct") model = PeftModel.from_pretrained(base_model, "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA") - Transformers
How to use sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA
- SGLang
How to use sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA 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 "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA" \ --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": "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA", "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 "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA" \ --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": "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA with Docker Model Runner:
docker model run hf.co/sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA
Qwen2.5-0.5B-HiddenDistilled-LoRA
This model repository contains the LoRA adapter weights for Qwen2.5-0.5B-Instruct distilled from the teacher model Qwen2.5-3B-Instruct. The distillation objective integrates SFT cross-entropy loss, logit-level Kullback-Leibler (KL) divergence, and linear projection-based hidden state matching.
- Base Student Model: Qwen/Qwen2.5-0.5B-Instruct
- Teacher Model: Qwen/Qwen2.5-3B-Instruct
- Merged Distilled Model: sarimahsan/distillation-hiddenstates-code
π Trial Run Evaluation Metrics
These metrics were recorded during a trial run on a single NVIDIA Tesla T4 (16GB) GPU for 1 epoch on a subset of Alpaca, Dolly, and Ultrachat:
| Metric | Before Distillation | After Distillation | Change | Status |
|---|---|---|---|---|
| Validation Perplexity | 5.0924 | 5.2620 | +0.1696 | β |
| Teacher-Student KL Divergence | 2.7913 | 1.9637 | -0.8276 | β |
| Hidden State Cosine Similarity | 0.0075 | 0.0054 | -0.0021 | β |
Analysis:
- The Teacher-Student KL Divergence improved by 0.8276, showing that the student's output probabilities are starting to align with the teacher's logits.
- Perplexity and Hidden similarity did not improve during the brief training run due to the restricted dataset size and quick epoch limits. A larger compute and training duration are recommended to achieve full convergence of the projection layers.
π How to Use (LoRA Adapter)
To load and use this adapter, run:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model_name = "Qwen/Qwen2.5-0.5B-Instruct"
adapter_name = "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA"
# Load tokenizer and base model
tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_name,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, adapter_name)
model.eval()
# Inference example
messages = [{"role": "user", "content": "Explain gravity in one sentence."}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=50)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
π οΈ Training Configurations & Details
- Framework: PyTorch & Hugging Face Transformers / Trainer
- Quantization: 4-bit NF4 double quantization (
bitsandbytes) - PEFT Method: LoRA (Rank = 32, Alpha = 64, Target modules = all linear layers)
- Optimization: Paged AdamW 8bit with Cosine LR scheduler
- Loss Weights: Cross-Entropy: 0.3, KL Divergence: 0.4, Hidden MSE: 0.3
- Downloads last month
- 44
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct") model = PeftModel.from_pretrained(base_model, "sarimahsan101/Qwen2.5-0.5B-HiddenDistilled-LoRA")