GPT-124M is a decoder-only transformer model based on OpenAI’s GPT-2 architecture. It is trained for text generation and other natural language processing (NLP) tasks. The model is designed for general-purpose language modeling, making it useful for applications such as text completion.
transformersHuggingFaceFW/fineweb-eduopenai-community/gpt2text-generationGPT-124M is a lightweight generative language model fine-tuned on the fineweb-edu dataset. It can generate coherent and contextually relevant text but is not fine-tuned for instruction-following, safety, or factual accuracy.
10245030412127688x NVIDIA RTX 4090 GPUs13 hoursfineweb-edu (10 billion tokens)January 2025You can use this model for text generation using the transformers library.
# Import necessary modules from transformers
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
# Load tokenizer and model
model_name = "samkeet/GPT_124M"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
# Create text generation pipeline
pipe = pipeline("text-generation", model=model_name, tokenizer=tokenizer, trust_remote_code=True, device="cpu")
# Generate text
result = pipe("Earth revolves around the", do_sample=True, max_length=40, temperature=0.9, top_p=0.5, top_k=50)
print("Pipeline Output:", result)
# Import necessary libraries
import torch
# Function for direct tokenization and text generation
def generate_text(input_text, device='cpu'):
tokens = tokenizer.encode(input_text, return_tensors='pt').to(device)
model.to(device)
# Generate output
output = model.generate(
tokens,
do_sample=True,
max_length=40,
temperature=0.9,
top_p=0.5,
top_k=50,
)
# Decode generated text
generated_sentence = tokenizer.decode(output)
return generated_sentence
# Generate text
input_text = "Earth revolves around the"
print("Direct Output:", generate_text(input_text))
This model can be fine-tuned for specific NLP applications like:
Validation was conducted using 100 million tokens from the HuggingFaceFW/fineweb-edu dataset. The training and validation loss graph indicates a stable convergence with minimal overfitting. The training loss achieved a minimum value of 2.88, while the validation loss stabilized at 2.97.
The model was benchmarked against OpenAI’s GPT-2 Small and GPT-3 Small (both ~124M parameters). Remarkably, despite being trained on only 10 billion tokens, compared to GPT-3 Small's 300 billion tokens, GPT-124M was able to outperform both models in HellaSwag evaluation. This performance advantage is attributed to the specialized training data (educational content), which contrasts with GPT-3 Small’s broader multilingual and multi-domain training data.
According to Chinchilla’s scaling laws, an optimal token-to-parameter ratio suggests that a 124M-parameter model ideally requires 2.48 billion tokens for training. The excess training tokens used in GPT-3 Small might have led to diminishing returns in performance.
HellaSwag.8x NVIDIA RTX 4090 GPUs13 hours -> 104 GPU hours13.48 kg CO2 eq.54.5 km driven by an average ICE car6.75 kg of coal burned0.22 tree seedlings sequestering carbon for 10 yearsGPT-124M follows the architecture of OpenAI's GPT-2, which consists of:
Gotcha — here’s a tight, concise section you can drop in as-is. It keeps only the essentials: data, setup, choices, Kaggle, no fluff.
The instruction-tuned GPT-124M is fine-tuned on the tatsu-lab/alpaca dataset, containing high-quality instruction–response pairs across reasoning, explanation, summarization, and creative tasks. Samples are length-filtered to fit the 1024-token context window, counting instruction, input, response, and EOS tokens.
Training follows an Alpaca-style format:
### Instruction:
<instruction and optional input>
### Response:
<target output>
Causal language modeling is used, with loss applied only to response tokens (prompt tokens masked with -100) and an explicit EOS token appended.
Instruction tuning improves instruction following, output structure, and task performance while preserving the base model’s generative capabilities. The model remains non-aligned and may hallucinate.
If you use this model, please cite:
@article{gpt124m,
title={GPT-124M: A Compact Transformer Model for NLP},
author={Samkeet Sangai},
year={2024},
url={https://huggingface.co/samkeet/GPT_124M}
}
For inquiries, contact Samkeet Sangai.