mz-model-v2 / README.md
marekzel's picture
Update README.md
4b9be90 verified
|
Raw History Blame Contribute Delete
4.33 kB
metadata
license: apache-2.0
library_name: transformers
pipeline_tag: text-generation
tags:
  - pytorch
  - transformer
  - language-model
  - from-scratch
  - custom-architecture
  - home-lab
  - small-language-model

MzModelV2

MzModelV2 is a decoder-only Transformer language model built from scratch using PyTorch and Hugging Face Transformers. It is the second iteration of the MzModel project, focused on exploring modern Transformer architecture improvements and language model training on consumer hardware.

The project demonstrates how a small language model can be designed, trained, and evaluated using a single consumer GPU in a home lab environment.

Model Description

MzModelV2 introduces several architectural improvements over the original MzModelV1:

  • Rotary Positional Embeddings (RoPE)
  • Root Mean Square Layer Normalization (RMSNorm)
  • SwiGLU activation function
  • Bias-free linear projections
  • Scaled Dot Product Attention (SDPA)

The model retains the original vocabulary and tokenizer to make comparisons between the two architecture versions more consistent.

Model Details

Property Value
Model name MzModelV2
Architecture Decoder-only Transformer
Model type mz_model_v2
Parameters Approximately 110 million
Hidden size 768
Number of layers 12
Attention heads 12
Vocabulary size 32,000
Maximum sequence length 512 tokens
Positional encoding Rotary Positional Embeddings (RoPE)
Attention mechanism Causal multi-head self-attention with SDPA
Activation function SwiGLU
Normalization RMSNorm
Weight tying Input embeddings and output projection
Training hardware NVIDIA RTX 5060 Ti (16 GB VRAM)
Pretraining dataset Wikipedia Structured (7.6 million articles)
Framework PyTorch, Hugging Face Transformers

Architecture

MzModelV2 uses a modernized Transformer architecture while preserving the general design and scale of the original model.

The main architectural changes include:

  • RoPE: Rotary positional embeddings are used to encode token positions directly in the attention mechanism.
  • RMSNorm: Replaces LayerNorm with a simpler normalization method.
  • SwiGLU: Replaces GELU with a gated activation function in the feed-forward network.
  • SDPA: Uses PyTorch Scaled Dot Product Attention, allowing optimized attention implementations depending on the available hardware and software.
  • Bias-free projections: Linear projections in the attention and feed-forward blocks do not use bias terms.

These changes are intended to provide a more modern architecture and a useful basis for experimentation with small language models.

Training

The model is trained from scratch on a single NVIDIA RTX 5060 Ti with 16 GB of VRAM.

The pretraining process uses the Wikipedia Structured dataset, containing approximately 7.6 million articles.

The tokenizer is the same as the one used by MzModelV1, allowing more consistent comparisons between the two models.

The main goal of this project is to investigate how architectural improvements affect training behavior and model performance at a relatively small parameter scale.

Intended Use

MzModelV2 is an experimental language model intended for:

  • Learning and experimenting with Transformer architectures.
  • Exploring language model training from scratch.
  • Comparing different architectural choices.
  • Testing small language models on consumer hardware.

It is not intended to compete with large-scale production language models.

Inference

The model can be loaded using its custom architecture implementation.

For a complete inference example, see the project repository:

https://github.com/marekzel/mz-models

Limitations

MzModelV2 is a small experimental language model with approximately 110 million parameters and a context length of 512 tokens.

Its knowledge, reasoning, instruction-following, and text-generation capabilities are limited compared with larger pretrained language models.

Generated content may contain factual errors, inconsistencies, or incomplete answers.

Disclaimer

This model is experimental and provided "as is" for research and educational purposes only. No guarantees are made regarding its performance, safety, or accuracy. Use at your own risk.