Text Generation
Transformers
Safetensors
PyTorch
mz_model_v2
transformer
language-model
from-scratch
custom-architecture
home-lab
small-language-model
Instructions to use marekzel/mz-model-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use marekzel/mz-model-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="marekzel/mz-model-v2")# pip install -U transformers accelerate # Load model directly from transformers import MzModelV2 model = MzModelV2.from_pretrained("marekzel/mz-model-v2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use marekzel/mz-model-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "marekzel/mz-model-v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "marekzel/mz-model-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/marekzel/mz-model-v2
- SGLang
How to use marekzel/mz-model-v2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "marekzel/mz-model-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "marekzel/mz-model-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "marekzel/mz-model-v2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "marekzel/mz-model-v2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use marekzel/mz-model-v2 with Docker Model Runner:
docker model run hf.co/marekzel/mz-model-v2
|
Download README.md from marekzel/mz-model-v2: direct link, hf CLI and curl.
- Browser
- Download file 4.33 kB
-
https://huggingface.co/marekzel/mz-model-v2/resolve/main/README.md
- Command line
-
hf download hf://marekzel/mz-model-v2/README.md
-
curl -L -o README.md https://huggingface.co/marekzel/mz-model-v2/resolve/main/README.md
4.33 kB
| 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. | |