Downloads · 30 days
4
5% of all-time downloads
sreekanthT/gpt2-nebulamesh-dpo
gpt2-nebulamesh-dpo is a machine learning model from sreekanthT. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This project demonstrates an end-to-end LLM fine-tuning workflow using GPT-2 (124M parameters).
Downloads · 30 days
4
5% of all-time downloads
All-time downloads
79
Public
Parameters
124M
498 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors498 MB · 99%
From the Hugging Face model README
This project demonstrates an end-to-end LLM fine-tuning workflow using GPT-2 (124M parameters).
The goal of this project is to understand how a pretrained language model can be adapted through multiple training stages:
Pretrained GPT-2
↓
Non-Instruction Fine-Tuning
↓
Instruction Fine-Tuning
↓
Preference Fine-Tuning (DPO)
↓
Final Model
I used GPT-2 (124M) as the base model and created a small fictional technical domain called NebulaMesh.
The project demonstrates:
Note: NebulaMesh is a fictional domain created for learning and experimentation. The dataset is intentionally small and is not intended for production use.
The starting model is:
GPT-2 — 124M parameters
The pretrained GPT-2 model already has general language knowledge.
We first tested the pretrained model with a simple prompt and then adapted it to the fictional NebulaMesh domain.
The first training stage used plain domain-specific text.
Example:
NebulaMesh is a fictional distributed computing protocol
for edge devices.
NebulaMesh nodes communicate using the NMX protocol.
MeshPulse sends a heartbeat every 10 seconds.
The objective is next-token prediction.
The model learns patterns from the NebulaMesh text by:
Input text
↓
Forward Pass
↓
Calculate Loss
↓
Backpropagation
↓
Update Model Weights
This stage adapts the pretrained GPT-2 model toward the NebulaMesh domain.
Output:
./gpt2-solidity
Next, the domain model was fine-tuned using instruction/response examples.
Example:
### Instruction:
What protocol does NebulaMesh use?
### Response:
NebulaMesh uses the NMX protocol.
The purpose of this stage is to teach the model to respond to instructions rather than simply continue domain text.
The training format was:
Instruction → Response
Output:
./gpt2-solidity-instruct
The final training stage used Direct Preference Optimization (DPO).
Instead of providing only one answer, each training example contains:
Example:
Prompt:
What protocol does NebulaMesh use?
Chosen:
NebulaMesh uses the NMX protocol.
Rejected:
NebulaMesh uses the NebulaMesh protocol repeatedly.
The model learns to prefer the chosen response over the rejected response.
Conceptually:
Prompt
│
┌─────────┴─────────┐
↓ ↓
Chosen Rejected
👍 👎
└─────────┬─────────┘
↓
DPO
↓
Preference-aligned model
Final model:
./gpt2-nebulamesh-dpo
GPT-2
124M Params
│
▼
Non-Instruction Fine-Tuning
│
▼
NebulaMesh Domain
│
▼
Instruction Fine-Tuning
│
▼
Instruction Following
│
▼
DPO Preference Training
│
▼
Final Model
│
▼
Hugging Face Hub
pip install torch transformers datasets accelerate trl huggingface_hub
Train GPT-2 on the NebulaMesh domain dataset.
GPT-2
↓
Domain Dataset
↓
Full Fine-Tuning
Start from the domain-fine-tuned model:
./gpt2-solidity
and train using instruction/response examples.
Start from the instruction-fine-tuned model:
./gpt2-solidity-instruct
and train using preference data containing:
prompt
chosen
rejected
The final model can be loaded using:
from transformers import GPT2Tokenizer, GPT2LMHeadModel
model_path = "./gpt2-nebulamesh-dpo"
tokenizer = GPT2Tokenizer.from_pretrained(model_path)
model = GPT2LMHeadModel.from_pretrained(model_path)
tokenizer.pad_token = tokenizer.eos_token
model.config.pad_token_id = tokenizer.pad_token_id
Example:
question = "What protocol does NebulaMesh use?"
prompt = (
"### Instruction:\n"
+ question
+ "\n\n"
"### Response:\n"
)
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(
**inputs,
max_new_tokens=50,
do_sample=False,
pad_token_id=tokenizer.pad_token_id,
)
print(
tokenizer.decode(
outputs[0],
skip_special_tokens=True
)
)
Expected response:
NebulaMesh uses the NMX protocol.
Because the dataset is intentionally small, the model may still produce repetitive or imperfect responses.
This project is primarily an educational experiment.
The dataset is small and uses a fictional domain. Therefore:
A larger, higher-quality dataset would be required for meaningful real-world performance.
Through this project, I explored:
Updating the pretrained model's trainable weights during training.
GPT-2
↓
Train model weights
↓
Fine-tuned model
Teaching a model to follow instructions and produce responses.
Instruction
↓
Response
Teaching a model to prefer better responses over less desirable responses.
Prompt
↓
Chosen vs Rejected
↓
DPO
↓
Preferred behavior
The final model was uploaded to Hugging Face Hub so it can be shared and loaded later.
This project helped me understand the progression:
Pretraining
↓
Domain Fine-Tuning
↓
Instruction Fine-Tuning
↓
Preference Fine-Tuning
The next step is to explore Parameter-Efficient Fine-Tuning (PEFT) techniques such as:
These approaches allow large language models to be adapted while training far fewer parameters than full fine-tuning.
This repository was created as a hands-on learning project to understand the mechanics of modern LLM fine-tuning using Hugging Face tools.
The implementation and experiments are for educational purposes.