Views
No views yet
4-bit quantized (bitsandbytes) instruct model based onmistralai/Mistral-7B-Instruct-v0.3, fine-tuned with QLoRA on a 10% sample ofHuggingFaceH4/ultrachat_200kfor supervised fine-tuning (SFT).
mistralai/Mistral-7B-Instruct-v0.3q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projadamw_8bit, cosine LR, warmup 10%Requirestransformers,accelerate,bitsandbytes, and a recent CUDA build for 4-bit inference.
1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2import torch
3
4model_id = "rapidfire-ai-inc/Mistral-7B-Instruct-v0.3-bnb-4bit"
5
6bnb_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_compute_dtype=torch.bfloat16,
9 bnb_4bit_use_double_quant=True,
10 bnb_4bit_quant_type="nf4",
11)
12
13tok = AutoTokenizer.from_pretrained(model_id, use_fast=True)
14model = AutoModelForCausalLM.from_pretrained(
15 model_id,
16 device_map="auto",
17 quantization_config=bnb_config,
18 torch_dtype=torch.bfloat16,
19)
20
21messages = [
22 {"role": "system", "content": "You are a helpful assistant."},
23 {"role": "user", "content": "Explain diffusion models in simple terms."}
24]
25prompt = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
26
27inputs = tok(prompt, return_tensors="pt").to(model.device)
28out = model.generate(
29 **inputs,
30 max_new_tokens=256,
31 temperature=0.7,
32 top_p=0.9,
33)
34print(tok.decode(out[0], skip_special_tokens=True))HuggingFaceH4/ultrachat_200kq_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projmax_length = 2048
per_device_train_batch_size = 2
gradient_accumulation_steps = 4
learning_rate = 2e-5
warmup_ratio = 0.1
weight_decay = 0.001
lr_scheduler_type = "cosine"
optim = "adamw_8bit"
bf16 = True
num_train_epochs = 51LoraConfig(
2 task_type="CAUSAL_LM",
3 r=64,
4 lora_alpha=64,
5 lora_dropout=0.05,
6 target_modules=[
7 "q_proj", "k_proj", "v_proj", "o_proj",
8 "gate_proj", "up_proj", "down_proj"
9 ],
10 bias="none",
11)1BitsAndBytesConfig(
2 load_in_4bit=True,
3 bnb_4bit_compute_dtype=torch.bfloat16,
4 bnb_4bit_use_double_quant=True,
5 bnb_4bit_quant_type="nf4",
6)torch_dtype=torch.bfloat16 with 4-bit to balance speed/quality.max_new_tokens=256, temperature=0.6–0.9, top_p=0.9, repetition_penalty=1.1–1.2.apply_chat_template) to ensure proper formatting.1@misc{rapidfireai_mistral7b_bnb4bit_2025,
2 title = {Mistral-7B-Instruct-v0.3-bnb-4bit (RapidFire AI)},
3 author = {RapidFire AI, Inc.},
4 year = {2025},
5 howpublished = {\url{https://huggingface.co/rapidfire-ai-inc/Mistral-7B-Instruct-v0.3-bnb-4bit}}
6}