Text Generation
Transformers
Safetensors
PEFT
qlora
bitsandbytes
mistral
mistral-7b
fine-tune
conversational
Instructions to use Falah/my-qlora-mistral7b-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Falah/my-qlora-mistral7b-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Falah/my-qlora-mistral7b-instruct") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Falah/my-qlora-mistral7b-instruct", dtype="auto") - PEFT
How to use Falah/my-qlora-mistral7b-instruct with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Falah/my-qlora-mistral7b-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Falah/my-qlora-mistral7b-instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Falah/my-qlora-mistral7b-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Falah/my-qlora-mistral7b-instruct
- SGLang
How to use Falah/my-qlora-mistral7b-instruct 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 "Falah/my-qlora-mistral7b-instruct" \ --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": "Falah/my-qlora-mistral7b-instruct", "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 "Falah/my-qlora-mistral7b-instruct" \ --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": "Falah/my-qlora-mistral7b-instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Falah/my-qlora-mistral7b-instruct with Docker Model Runner:
docker model run hf.co/Falah/my-qlora-mistral7b-instruct
my-qlora-mistral7b-instruct
This is a QLoRA fine-tuned version of the mistralai/Mistral-7B-Instruct-v0.2 model. It was fine-tuned using Low-Rank Adaptation (LoRA) in 4-bit precision for efficiency on consumer GPUs.
π Model Details
- Base model: mistralai/Mistral-7B-Instruct-v0.2
- Fine-tuning method: QLoRA with PEFT
- Quantization: 4-bit (bitsandbytes)
- Task: Instruction following / conversational AI
- Dataset: Custom instruction-response pairs
- Training environment: Google Colab Pro (T4 / A100 GPU)
π¦ How to Use
# First, make sure you have the necessary libraries installed:
# pip install transformers peft bitsandbytes accelerate
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, BitsAndBytesConfig
from peft import PeftModel
from accelerate import infer_auto_device_map, dispatch_model
fine_tuned_model_id = "Falah/my-qlora-mistral7b-instruct"
base_model_id = "mistralai/Mistral-7B-Instruct-v0.2"
print("Loading tokenizer...")
tokenizer = AutoTokenizer.from_pretrained(fine_tuned_model_id)
print("Loading base model with 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
)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
quantization_config=bnb_config,
device_map=None, # Load to CPU initially
torch_dtype=torch.float16,
trust_remote_code=True,
)
print("Loading PEFT adapter onto the base model...")
model = PeftModel.from_pretrained(base_model, fine_tuned_model_id)
print("Dispatching model to devices...")
device_map = infer_auto_device_map(model, dtype=torch.float16)
model = dispatch_model(model, device_map=device_map)
# Ensure the model is in evaluation mode
model.eval()
print("Creating text generation pipeline...")
generator = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
torch_dtype=torch.float16,
device_map="auto",
)
# Define a sample user prompt
user_prompt = "Write a short story about a robot learning to love."
# Format the prompt
formatted_prompt = f"[INST] {user_prompt} [/INST]"
# Generate text
outputs = generator(
formatted_prompt,
max_new_tokens=200,
num_return_sequences=1,
do_sample=True,
temperature=0.7,
top_k=50,
top_p=0.95,
)
# Print the generated text
for i, output in enumerate(outputs):
print(f"Generated Output {i+1}:\n{output['generated_text']}")