A transformer model built completely from scratch in C.
cmake
: Tool for managing source code buildinglibc
: Standard C librarypthread
: POSIX multi-threading library for portable CPUsvulkan
: Portable multi-threading library for GPUslibpcre2
: Implements Perl 5-style regular expressionslibuuid
: DCE compatible Universally Unique Identifier librarylibutf8proc
: C library for Unicode handlingstb
: Image loading/decoding library
- Any Linux distribution should work.
- Officially supports Arch Linux.
- Requires POSIX for CPU multi-threading.
- Requires Vulkan for GPU multi-threading.
NOTE: Currently, I only officially support Arch Linux. I may consider Android support further down the line once the codebase matures.
sudo pacman -S gcc gdb cmake util-linux-libs pcre2 libutf8proc stb vulkan-headers vulkan-tools
sudo pacman -S python-pip python-virtualenv python-isort python-black flake8
Clone the repository to your local machine and navigate into it:
git clone https://github.com/teleprint-me/alt.c.git alt
cd alt
Set up a Python virtual environment to manage project dependencies:
virtualenv .venv
source .venv/bin/activate
Important Note:
Arch Linux has recently upgraded Python from 3.12.x to 3.13.x. At the time of writing, some critical libraries, such as SentencePiece and PyTorch, are not fully compatible with Python 3.13.x. This causes issues with the development environment.
To resolve this, I have created a Knowledge Base article that provides a detailed guide on building and using a local Python 3.12.x environment without interfering with the system-wide Python installation. Refer to docs/kb/python.md for step-by-step instructions.
Install the CPU-only version of PyTorch, along with the TorchText library, to avoid GPU dependency issues (optional if GPU support is not required):
pip install torch torchtext --index-url https://download.pytorch.org/whl/cpu --upgrade
Install the additional Python dependencies listed in requirements.txt
. It is recommended to install these after PyTorch to avoid potential conflicts:
pip install -r requirements.txt
cmake -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build --config Debug -j $(nproc)
python -m alt.convert.spm models/mistralai/Mistral-7B-Instruct-v0.1
TODO: Tensor conversion coming soon.
./build/examples/models/perceptron
Epoch 0: Average Error: 0.50862
Epoch 1000: Average Error: 0.15645
Epoch 2000: Average Error: 0.10852
Epoch 3000: Average Error: 0.08668
Epoch 4000: Average Error: 0.07379
Epoch 5000: Average Error: 0.06513
Epoch 6000: Average Error: 0.05883
Epoch 7000: Average Error: 0.05400
Epoch 8000: Average Error: 0.05015
Epoch 9000: Average Error: 0.04699
Trained Weights: 5.48, 5.48 | Bias: -8.32
Input: 0, 0 -> Prediction: 0.000
Input: 0, 1 -> Prediction: 0.056
Input: 1, 0 -> Prediction: 0.056
Input: 1, 1 -> Prediction: 0.934
This project is licensed under the AGPL License. See the LICENSE file for details.
Note: Everything is still a work in progress—expect changes and refinements as development continues.