Downloads · 30 days
3
12% of all-time downloads
ssui-liu/mistral-7b-lima-dpo
mistral-7b-lima-dpo is a machine learning model from ssui-liu. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft.
This repository contains a version of the unsloth/mistral-7b-instruct-v0.2 model fine-tuned using Direct Preference Optimization (DPO). The fine-tuning process utilized a preference dataset derived from the LIMA datas…
Downloads · 30 days
3
12% of all-time downloads
All-time downloads
26
Public
Repo size
672 MB
Likes
0
Public
Click a slice to open those files.
.safetensors671 MB · 99%
From the Hugging Face model README
This repository contains a version of the unsloth/mistral-7b-instruct-v0.2 model fine-tuned using Direct Preference Optimization (DPO). The fine-tuning process utilized a preference dataset derived from the LIMA dataset and responses generated by the base Mistral-7B-Instruct-v0.2 model, which were then ranked using PairRM from the LLM-Blender toolkit.
The goal of this fine-tuning is to align the model further with human preferences for helpful and harmless responses.
unsloth/mistral-7b-instruct-v0.2 (a version of mistralai/Mistral-7B-Instruct-v0.2 optimized with Unsloth)mistralai/Mistral-7B-Instruct-v0.2.llm-blender/PairRM.ssui-liu/lima-mistral7b-pairrm-preference (or your specified dataset name if different).The DPO training was performed with the following key hyperparameters (refer to scripts/dpo_training.py for full details):
r: 64alpha: 64dropout: 0.0q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projmax_steps was used)β): 0.1This model is a PEFT (LoRA) adapter. To use it, you need to load the base model (unsloth/mistral-7b-instruct-v0.2) and then apply these LoRA weights.
from unsloth import FastLanguageModel
model_name = "unsloth/mistral-7b-instruct-v0.2"
peft_model_id = "ssui-liu/mistral-7b-lima-dpo" # Or your specific model ID
max_seq_length = 2048 # Or your preferred max sequence length
# Load the base model
model, tokenizer = FastLanguageModel.from_pretrained(
model_name=model_name,
max_seq_length=max_seq_length,
dtype=None, # Autodetect
load_in_4bit=True, # Or False if not using 4bit
)
# Load the PEFT adapter
model = FastLanguageModel.get_peft_model(
model,
peft_model_id,
# Ensure LoRA parameters match those during training if not automatically inferred
# r = 64,
# lora_alpha = 64,
# target_modules = ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
# etc.
)
FastLanguageModel.for_inference(model) # Prepare model for inference
# Example usage
prompt = "What are the best ways to learn a new programming language?"
messages = [
{"role": "user", "content": prompt}
]
input_ids = tokenizer.apply_chat_template(messages, tokenize = True, add_generation_prompt = True, return_tensors = "pt").to("cuda")
outputs = model.generate(input_ids = input_ids, max_new_tokens = 256, use_cache = True)
response = tokenizer.batch_decode(outputs)[0]
# Extract just the assistant's response
# (This might vary slightly based on the exact chat template and base model version)
response_parts = response.split("[/INST]")
if len(response_parts) > 1:
assistant_response = response_parts[1].strip()
else:
assistant_response = response # Fallback if pattern not found
print(assistant_response)