Downloads · 30 days
69
59% of all-time downloads
YehPel/qwen2.5-0.5b-fish-signoff-lora
qwen2.5-0.5b-fish-signoff-lora is a machine learning model from YehPel. 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. The card lists the license as apache-2.0.
This repository contains a LoRA adapter trained on top of Qwen/Qwen2.5-0.5B-Instruct.
Downloads · 30 days
69
59% of all-time downloads
All-time downloads
117
Public
Repo size
4.4 MB
Likes
0
Public
Click a slice to open those files.
.safetensors4.4 MB · 100%
From the Hugging Face model README
This repository contains a LoRA adapter trained on top of
Qwen/Qwen2.5-0.5B-Instruct.
The goal of this experiment was to teach the model to end its assistant responses with the phrase:
So long, and thanks for all the fish
This project was created as a small educational experiment to better understand supervised fine-tuning, LoRA, PEFT, TRL, and the Hugging Face ecosystem.
The adapter was trained on:
Qwen/Qwen2.5-0.5B-Instruct
This repository does not contain the full Qwen model weights.
The original base model is required in order to use this adapter.
The model was fine-tuned using supervised fine-tuning (SFT) with a LoRA adapter implemented using Hugging Face PEFT.
The training loop was managed using TRL's SFTTrainer.
r): 8q_projk_projv_projo_projThe training dataset consisted of short conversational examples using
user and assistant messages.
Every assistant response in the training data ended with:
So long, and thanks for all the fish
The purpose of the dataset was not to teach the model new factual knowledge, but to demonstrate how fine-tuning can modify a model's response behavior.
Install the required libraries:
pip install torch transformers peft
Load the original Qwen model and attach this LoRA adapter:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-0.5B-Instruct",
dtype=torch.float16,
device_map="auto",
)
model = PeftModel.from_pretrained(
base_model,
"YehPel/qwen2.5-0.5b-fish-signoff-lora",
)
tokenizer = AutoTokenizer.from_pretrained(
"Qwen/Qwen2.5-0.5B-Instruct"
)
messages = [
{
"role": "user",
"content": "What is the capital of Japan?"
}
]
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=80
)
response = tokenizer.decode(
outputs[0],
skip_special_tokens=True
)
print(response)
An example response after applying the adapter is:
system
You are Qwen, created by Alibaba Cloud. You are a helpful assistant.
user
What is the capital of Japan?
assistant
Tokyo. So long, and thanks for all the fish
The important adapter files in this repository are:
adapter_config.json
adapter_model.safetensors
adapter_config.json describes the LoRA configuration and its relationship
to the base model.
adapter_model.safetensors contains the trained LoRA parameters.
The full Qwen2.5-0.5B-Instruct weights are not included in this repository.
This adapter is based on Qwen/Qwen2.5-0.5B-Instruct, Copyright 2024 Alibaba Cloud, which is licensed under the Apache License 2.0.
This repository contains only the LoRA adapter weights and does not redistribute the original Qwen base model weights.