Instructions to use millat/Qwen2.5-7B-BDLAW-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use millat/Qwen2.5-7B-BDLAW-LoRA with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-7B-Instruct") model = PeftModel.from_pretrained(base_model, "millat/Qwen2.5-7B-BDLAW-LoRA") - llama-cpp-python
How to use millat/Qwen2.5-7B-BDLAW-LoRA with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="millat/Qwen2.5-7B-BDLAW-LoRA", filename="gguf/qwen25_7b_bdlaw_f16.gguf", )
llm.create_chat_completion( messages = "No input example has been defined for this model task." )
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use millat/Qwen2.5-7B-BDLAW-LoRA with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M # Run inference directly in the terminal: llama-cli -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M # Run inference directly in the terminal: llama-cli -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Use Docker
docker model run hf.co/millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
- LM Studio
- Jan
- Ollama
How to use millat/Qwen2.5-7B-BDLAW-LoRA with Ollama:
ollama run hf.co/millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
- Unsloth Studio
How to use millat/Qwen2.5-7B-BDLAW-LoRA with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
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 millat/Qwen2.5-7B-BDLAW-LoRA to start chatting
Install Unsloth Studio (Windows)
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 millat/Qwen2.5-7B-BDLAW-LoRA to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for millat/Qwen2.5-7B-BDLAW-LoRA to start chatting
- Pi
How to use millat/Qwen2.5-7B-BDLAW-LoRA with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use millat/Qwen2.5-7B-BDLAW-LoRA with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Run Hermes
hermes
- Atomic Chat new
- Docker Model Runner
How to use millat/Qwen2.5-7B-BDLAW-LoRA with Docker Model Runner:
docker model run hf.co/millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
- Lemonade
How to use millat/Qwen2.5-7B-BDLAW-LoRA with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull millat/Qwen2.5-7B-BDLAW-LoRA:Q4_K_M
Run and chat with the model
lemonade run user.Qwen2.5-7B-BDLAW-LoRA-Q4_K_M
List all available models
lemonade list
Qwen 2.5 7B Instruct - Bangladesh Legal LoRA Adapter
A fine-tuned LoRA adapter for Qwen 2.5 7B Instruct specialized in Bangladesh legal reasoning and legal document analysis.
📋 Model Details
| Property | Value |
|---|---|
| Base Model | Qwen/Qwen2.5-7B-Instruct |
| Adapter Type | LoRA (Low-Rank Adaptation) |
| LoRA Rank (r) | 64 |
| LoRA Alpha (α) | 128 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Training Dataset | BDLawCorpus Dataset V1 |
| Training Examples | 4,710 Bangla legal documents |
| Training Epochs | 3 |
| Training Hours | ~6.5 hours on 2x T4 GPU |
| Precision | FP16 mixed precision + 4-bit quantization |
| Batch Size | 8 (per device) |
| Learning Rate | 2e-4 |
| Quantization | 4-bit NF4 (train) / Optional for inference |
🚀 Quick Start
Installation
pip install transformers peft torch accelerate
Loading the Model
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
# Base model
model_id = "Qwen/Qwen2.5-7B-Instruct"
adapter_id = "millat/qwen-2.5-7b-instruct-bdlaw-lora"
# Load base model (with optional 4-bit quantization)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16
)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
quantization_config=bnb_config,
torch_dtype=torch.float16,
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
# Attach LoRA adapter
model = PeftModel.from_pretrained(model, adapter_id)
model.eval()
Inference Example
# Bangla legal query
prompt = "বাংলাদেশে চুক্তি আইন কী এবং এর প্রধান বৈশিষ্ট্য কি?"
# Format with chat template
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# Generate response
inputs = tokenizer(text, return_tensors="pt").to("cuda")
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
do_sample=True,
top_p=0.95,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
📊 Training Details
Dataset
BDLawCorpus Dataset V1 contains:
- 4,710 Bangla legal documents and case studies
- Multi-format: Chat templates with conversation pairs
- Topics: Contract Law, Criminal Law, Constitutional Law, Property Law, Labor Law
- Quality: Manually validated and cleaned
Training Configuration
# Quantization (4-bit)
load_in_4bit=True
bnb_4bit_use_double_quant=True
bnb_4bit_quant_type="nf4"
bnb_4bit_compute_dtype=torch.float16
# LoRA Configuration
r=64 # Rank
lora_alpha=128 # Scaling factor
lora_dropout=0.05
bias="none"
task_type="CAUSAL_LM"
# Training Arguments
num_train_epochs=3
per_device_train_batch_size=8
gradient_accumulation_steps=2
learning_rate=2e-4
weight_decay=0.01
warmup_steps=100
save_steps=200
save_total_limit=3
logging_steps=10
fp16=True
gradient_checkpointing=True
ddp_find_unused_parameters=False
Training Environment
- Hardware: Kaggle 2x T4 GPU (15GB each)
- Framework: Hugging Face Transformers + PEFT + Accelerate
- Parallelism: Distributed Data Parallel (DDP)
- Total Training Time: ~6.5 hours
- Final Loss: 0.112
💡 Use Cases
This model is optimized for:
- Legal Document Summarization - Summarize Bangla legal texts and acts
- Legal Question Answering - Answer questions about Bangladesh law
- Contract Analysis - Analyze and explain contract clauses
- Case Law Explanation - Provide insights into court decisions
- Regulatory Compliance - Advise on Bangladesh legal compliance
- Document Classification - Categorize legal documents
- Legal Research - Retrieve relevant case law and precedents
📈 Performance Metrics
| Metric | Value |
|---|---|
| Training Loss | 0.112 |
| Samples/Second | 0.608 |
| Steps/Second | 0.076 |
| Total Training Steps | 1,764 |
| Memory Used (per GPU) | ~14.4 GB |
| Model Size (Adapter only) | ~131 MB |
⚖️ Limitations
- Language-specific: Optimized for Bangla legal documents; English queries may have lower accuracy
- Domain-specific: Trained on Bangladesh legal corpus; may not generalize to other domains
- Knowledge cutoff: Based on training data; may not reflect recent legal changes
- LLM limitations: Can hallucinate; always verify outputs with official sources
- No real-time updates: Requires retraining for new laws or amendments
🔧 Fine-tuning & Adaptation
To further fine-tune this adapter on your own data:
from transformers import TrainingArguments, Trainer
training_args = TrainingArguments(
output_dir="./my_adapter",
num_train_epochs=2,
per_device_train_batch_size=8,
learning_rate=1e-4,
save_steps=100,
logging_steps=10,
fp16=True,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=your_dataset,
data_collator=data_collator,
)
trainer.train()
📝 Citation
If you use this model, please cite:
@model{qwen_bdlaw_lora_2025,
title={Qwen 2.5 7B Instruct - Bangladesh Legal LoRA Adapter},
author={MD Millat Hosen},
organization={BDLaw Corpus Project},
year={2025},
howpublished={\url{https://huggingface.co/millat/qwen-2.5-7b-instruct-bdlaw-lora}},
}
📄 License
This adapter is provided under the Creative Commons Attribution 4.0 International (CC-BY-4.0) license.
The base model (Qwen 2.5 7B) is licensed under the Qwen License Agreement. Please refer to the original model card for details.
👥 Contact & Support
- Model Developer: MD Millat Hosen
- Project: BDLawCorpus
- Email: Contact via GitHub issues
- Repository: BDLawCorpus GitHub
🙏 Acknowledgments
- Qwen Team for the excellent base model architecture
- Hugging Face for the transformers library and model hosting
- Kaggle for providing free GPU compute
- Bangladesh Legal Community for data and domain expertise
⚠️ Disclaimer
This model is provided for educational and research purposes. While we strive for accuracy, legal advice should always be verified with qualified legal professionals. The model authors assume no responsibility for any consequences arising from the use of this model for legal decision-making.
🔄 Model Updates
| Version | Date | Notes |
|---|---|---|
| v1.0 | May 2025 | Initial release - 4,710 training examples |
Last Updated: May 9, 2025
Model Version: 1.0
Status: ✅ Production Ready
- Downloads last month
- 70
2-bit
3-bit
4-bit
5-bit
8-bit
16-bit