casual-gpt

casual-gpt is a small, from-scratch, decoder-only language model (about 13.9M parameters) trained for casual, chat-style conversation. It uses a GPT-2-style architecture written in PyTorch and is packaged to be compatible with the Hugging Face transformers API (PretrainedConfig, PreTrainedModel, GenerationMixin, and PreTrainedTokenizerFast).

The model, its configuration, and its tokenizer are produced by the training script src/casual_gpt.py in this repository.

Model details

Property Value
Model type casual_gpt (decoder-only Transformer, causal LM)
Architecture class CasualGPTForCausalLM
Parameters ~13.9M
Hidden size 384
Layers 6
Attention heads 6
MLP intermediate size 1536 (GELU)
Context length (max_position_embeddings) 256 tokens
Vocabulary size 8192 (byte-level BPE)
Normalization LayerNorm (eps 1e-5), pre-norm blocks
Position embeddings Learned absolute
Output head Tied to input embeddings
Dropout 0.1
Weight dtype float32
Language English (assumed; training data is not recorded in this repository)
License Not specified (see License section)

Special tokens

Token ID Purpose
<pad> 0 Padding
<bos> 1 Beginning of sequence
<eos> 2 End of sequence / end of each turn
`< system >`
`< user >`
`< assistant >`

Chat format

Each turn is rendered as <|role|>content<eos>, where role is system, user, or assistant. Generation starts after <|assistant|>. The chat template is stored with the tokenizer, so apply_chat_template works out of the box.

<|system|>You are a friendly assistant.<eos><|user|>hey, what's up?<eos><|assistant|>

Intended use

  • Casual conversation and small-talk experiments.
  • Learning and research on training small language models from scratch.
  • Baseline for fine-tuning or further experimentation with the casual_gpt.py pipeline.

Out-of-scope use

  • Factual question answering. The model is small and may produce incorrect or made-up information.
  • Advice of any kind (medical, legal, financial, safety-critical).
  • Production or user-facing applications without additional evaluation, safety filtering, and moderation.
  • Generating content about real people, or any content intended to deceive.

How to use

The model code is included in this folder as casual_gpt.py (the same file as src/casual_gpt.py), and config.json points to it through auto_map. Load the model with trust_remote_code=True; no separate import is needed.

Interactive or one-shot chat from the command line

pip install torch transformers tokenizers datasets
cd src
python casual_gpt.py --generate casual-gpt
python casual_gpt.py --generate casual-gpt --prompt "hey, what's up?"

Python

from transformers import AutoTokenizer, AutoModelForCausalLM

tok = AutoTokenizer.from_pretrained("casual-gpt")
model = AutoModelForCausalLM.from_pretrained("casual-gpt", trust_remote_code=True).eval()

messages = [{"role": "user", "content": "hey, what's up?"}]
enc = tok.apply_chat_template(messages, add_generation_prompt=True,
                              return_tensors="pt", return_dict=True)
enc = {k: v for k, v in enc.items() if k != "token_type_ids"}
out = model.generate(**enc, max_new_tokens=150, do_sample=True,
                     temperature=0.8, top_k=50, use_cache=False,
                     eos_token_id=[tok.eos_token_id, tok.convert_tokens_to_ids("<|user|>")],
                     pad_token_id=tok.pad_token_id)
print(tok.decode(out[0, enc["input_ids"].shape[1]:], skip_special_tokens=True).strip())

The use_cache=False setting matches the saved configuration. Generation uses the last 256 tokens of the context window.

Training

Training is performed by src/casual_gpt.py. The script supports three data sources:

  • Plain text, one document per line (--data_file).
  • Chat conversations in JSONL, one {"messages": [...]} object per line (--chat_file).
  • A Hugging Face dataset, either plain text (--dataset, default roneneldan/TinyStories) or chats (--chat_dataset).

When training on chats, only assistant replies contribute to the loss. User and system tokens are masked.

Script defaults used for training:

Hyperparameter Default
Tokenizer Byte-level BPE, trained on the training data, vocabulary 8192
Context length (block size) 256
Hidden size / layers / heads 384 / 6 / 6
Batch size 32
Steps 5000
Optimizer AdamW (betas 0.9, 0.95; weight decay 0.1)
Learning rate 6e-4 with 100-step linear warmup and cosine decay to 10%
Gradient clipping 1.0
Precision bfloat16 autocast on CUDA; float32 on CPU and MPS

The exact training dataset and the hyperparameters used for the released weights are not recorded in this repository. The values above are the script defaults.

Training example:

python casual_gpt.py --chat_file chats.jsonl --out casual-gpt

Evaluation

No formal evaluation results are included with this model. Quality has not been measured on standard benchmarks.

Limitations and risks

  • Small model. At about 13.9M parameters with a 256-token context, responses are short and often incoherent. The model cannot follow long conversations.
  • Factual reliability. The model has no grounding or retrieval and will hallucinate.
  • Bias and safety. The model was not evaluated for harmful, biased, or offensive output. The training data is not documented in this repository, so its biases are unknown.
  • Sampling. Responses are sampled (temperature 0.8, top-k 50), so the same prompt can give different answers.
  • Custom code. The architecture is not part of the transformers library. Loading requires trust_remote_code=True, which runs the casual_gpt.py file shipped in this folder. Review that file before loading if you do not trust the source.

License

No license is specified for this model. Add a license before redistribution.

Downloads last month
55
Safetensors
Model size
13.9M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support