RustGPT
App Listed Dormant
An transformer based LLM. Written completely in Rust
- Downloads
- Not measured
- Dependents
- Not applicable
- Stars
- 3,192
- Forks
- 268
- Contributors
- 6
- Commits
- 109
About
๐ฆ Rust LLM from Scratch
https://github.com/user-attachments/assets/ec4a4100-b03a-4b3c-a7d6-806ea54ed4ed
A complete Large Language Model implementation in pure Rust with no external ML frameworks. Built from the ground up using only ndarray for matrix operations.
๐ What This Is
This project demonstrates how to build a transformer-based language model from scratch in Rust, including:
- Pre-training on factual text completion
- Instruction tuning for conversational AI
- Interactive chat mode for testing
- Full backpropagation with gradient clipping
- Modular architecture with clean separation of concerns
โ What This Isn't
This is not a production grade LLM. It is so far away from the larger models.
This is just a toy project that demonstrates how these models work under the hood.
๐ Key Files to Explore
Start with these two core files to understand the implementation:
src/main.rs- Training pipeline, data preparation, and interactive modesrc/llm.rs- Core LLM implementation with forward/backward passes and training logic
๐๏ธ Architecture
The model uses a transformer-based architecture with the following components:
Input Text โ Tokenization โ Embeddings โ Transformer Blocks โ Output Projection โ Predictions
Read the full README
Project Structure
src/
โโโ main.rs # ๐ฏ Training pipeline and interactive mode
โโโ llm.rs # ๐ง Core LLM implementation and training logic
โโโ lib.rs # ๐ Library exports and constants
โโโ transformer.rs # ๐ Transformer block (attention + feed-forward)
โโโ self_attention.rs # ๐ Multi-head self-attention mechanism
โโโ feed_forward.rs # โก Position-wise feed-forward networks
โโโ embeddings.rs # ๐ Token embedding layer
โโโ output_projection.rs # ๐ฐ Final linear layer for vocabulary predictions
โโโ vocab.rs # ๐ Vocabulary management and tokenization
โโโ layer_norm.rs # ๐งฎ Layer normalization
โโโ adam.rs # ๐ Adam optimizer implementation
tests/
โโโ llm_test.rs # Tests for core LLM functionality
โโโ transformer_test.rs # Tests for transformer blocks
โโโ self_attention_test.rs # Tests for attention mechanisms
โโโ feed_forward_test.rs # Tests for feed-forward layers
โโโ embeddings_test.rs # Tests for embedding layers
โโโ vocab_test.rs # Tests for vocabulary handling
โโโ adam_test.rs # Tests for optimizer
โโโ output_projection_test.rs # Tests for output layer
๐งช What The Model Learns
The implementation includes two training phases:
Pre-training: Learns basic world knowledge from factual statements
- "The sun rises in the east and sets in the west"
- "Water flows downhill due to gravity"
- "Mountains are tall and rocky formations"
Instruction Tuning: Learns conversational patterns
- "User: How do mountains form? Assistant: Mountains are formed through tectonic forces..."
- Handles greetings, explanations, and follow-up questions
๐ Quick Start
# Clone and run
git clone https://github.com/tekaratzas/RustGPT.git
cd RustGPT
cargo run
# The model will:
# 1. Build vocabulary from training data
# 2. Pre-train on factual statements (100 epochs)
# 3. Instruction-tune on conversational data (100 epochs)
# 4. Enter interactive mode for testing
๐ฎ Interactive Mode
After training, test the model interactively:
Enter prompt: How do mountains form?
Model output: Mountains are formed through tectonic forces or volcanism over long geological time periods
Enter prompt: What causes rain?
Model output: Rain is caused by water vapor in clouds condensing into droplets that become too heavy to remain airborne
๐งฎ Technical Implementation
Model Configuration
- Vocabulary Size: Dynamic (built from training data)
- Embedding Dimension: 128 (defined by
EMBEDDING_DIMinsrc/lib.rs) - Hidden Dimension: 256 (defined by
HIDDEN_DIMinsrc/lib.rs) - Max Sequence Length: 80 tokens (defined by
MAX_SEQ_LENinsrc/lib.rs) - Architecture: 3 Transformer blocks + embeddings + output projection
Training Details
- Optimizer: Adam with gradient clipping
- Pre-training LR: 0.0005 (100 epochs)
- Instruction Tuning LR: 0.0001 (100 epochs)
- Loss Function: Cross-entropy loss
- Gradient Clipping: L2 norm capped at 5.0
Key Features
- Custom tokenization with punctuation handling
- Greedy decoding for text generation
- Gradient clipping for training stability
- Modular layer system with clean interfaces
- Comprehensive test coverage for all components
๐ง Development
# Run all tests
cargo test
# Test specific components
cargo test --test llm_test
cargo test --test transformer_test
cargo test --test self_attention_test
# Build optimized version
cargo build --release
# Run with verbose output
cargo test -- --nocapture
๐ง Learning Resources
This implementation demonstrates key ML concepts:
- Transformer architecture (attention, feed-forward, layer norm)
- Backpropagation through neural networks
- Language model training (pre-training + fine-tuning)
- Tokenization and vocabulary management
- Gradient-based optimization with Adam
Perfect for understanding how modern LLMs work under the hood!
๐ Dependencies
ndarray- N-dimensional arrays for matrix operationsrand+rand_distr- Random number generation for initialization
No PyTorch, TensorFlow, or Candle - just pure Rust and linear algebra!
๐ค Contributing
Contributions are welcome! This project is perfect for learning and experimentation.
High Priority Features Needed
- ๐ช Model Persistence - Save/load trained parameters to disk (currently all in-memory)
- โก Performance optimizations - SIMD, parallel training, memory efficiency
- ๐ฏ Better sampling - Beam search, top-k/top-p, temperature scaling
- ๐ Evaluation metrics - Perplexity, benchmarks, training visualizations
Areas for Improvement
- Advanced architectures (multi-head attention, positional encoding, RoPE)
- Training improvements (different optimizers, learning rate schedules, regularization)
- Data handling (larger datasets, tokenizer improvements, streaming)
- Model analysis (attention visualization, gradient analysis, interpretability)
Getting Started
- Fork the repository
- Create a feature branch:
git checkout -b feature/model-persistence - Make your changes and add tests
- Run the test suite:
cargo test - Submit a pull request with a clear description
Code Style
- Follow standard Rust conventions (
cargo fmt) - Add comprehensive tests for new features
- Update documentation and README as needed
- Keep the "from scratch" philosophy - avoid heavy ML dependencies
Ideas for Contributions
- ๐ Beginner: Model save/load, more training data, config files
- ๐ฅ Intermediate: Beam search, positional encodings, training checkpoints
- โก Advanced: Multi-head attention, layer parallelization, custom optimizations
Questions? Open an issue or start a discussion!
No PyTorch, TensorFlow, or Candle - just pure Rust and linear algebra!
Compatibility
- License
- MIT
- Crate facts
- Not measured
- Runs on, Native code and Python bindings read crates on crates.io. This entry lists no crate.
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
An transformer based LLM. Written completely in Rust |
Not measured | Not applicable | 3,192 | Not measured | Not measured | Not measured | MIT |
|
tch-rs Featured
Rust wrappers for the PyTorch C++ api (libtorch). Python bindings |
1,190,464 downloads over 30 days | 124 | 5,518 | 0.26.0 | CUDA | Binds native code: tch, torch-sys. Build uses a native toolchain: cc | Apache-2.0 OR MIT |
|
burn Featured
Flexible and Comprehensive Deep Learning Framework in Rust |
521,465 downloads over 30 days | 391 | 16,257 | 0.22.1 | CUDA, WebGPU, Metal, ROCm, Vulkan | Binds native code: netlink-sys (feature iroh), nvml-wrapper-sys (feature sys-metrics), torch-sys (feature tch) | Apache-2.0 OR MIT |
|
mlx-rs Featured
Unofficial rust wrapper for Apple's mlx machine learning library. |
33,398 downloads over 30 days | 36 | 389 | 0.34.0 | Metal | Binds native code: mach-sys, mlx, mlx-sys. Build uses a native toolchain: bindgen, cc, cmake | Apache-2.0 OR MIT |
|
aprender Listed
Next-generation ML framework in pure Rust โ `cargo install aprender` for the `apr` CLI |
15,442 downloads over 30 days | 31 | 140 | 0.72.3 | CUDA, WebGPU | Binds native code: libsqlite3-sys, zstd-sys, tree-sitter (feature full), alsa-sys (feature audio-alsa), nvml-wrapper-sys (feature nvml) and 1 more. Build uses a native toolchain: bindgen (feature bindgen) | MIT |
|
Trains GPT-style language models from a YAML config and a tokenized dataset: dense GQA transformers, Mamba 1, 2 and 3, MLA and MoE layers on CPU or CUDA. Runs the training loop, optimizer, checkpoints, evaluation and metrics on boostr, and builds speech corpora through voxr. |
27 downloads over 30 days | Not applicable | 8 | 0.1.1 | CUDA | Binds native code: nvml-wrapper-sys (feature cuda) | Apache-2.0 |
|
llms-from-scratch-rs Listed
Rust (candle) code for Build a LLM From Scratch by Sebastian Raschka |
3 downloads over 30 days | 0 | 340 | 0.1.5 | CUDA | No native code found | MIT |
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- The project is dormant and not finished. Dormancy rule
What else the check found
- The last activity is on 10 Oct 2025, 395 days ago. That reaches the 365 days the rules expect, so the project is dormant. Dormancy rule
- The oldest outside issue waits 420 days for a reply, past the limit of 270. No maintainer replied in 365 days. Rot signals rule
Not measured: Latest release, Unpatched vulnerabilities past the grace window, First release.
Exact rules: Listed, Featured app. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: app: E = 365 daysdormancy: last activity 2025-10-10, 395 days ago, E = 365: dormantrot: oldest unanswered issue 420 days (limit 270), no maintainer reply in 365 daysfeatured: not featured: dormant and not stablelisted: listed: no archive, new or featured rule applies
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources4 sources
- Description: the GitHub repository description
- GitHub repository, fetched
- GitHub releases, fetched
- GitHub contributors, fetched
AdoptionNot measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | Not measured | Yes | ||
| New dependents (365 days) | Not measured | Yes | ||
| Peak active dependents | Not measured | Yes | ||
| Active dependents as a share of the peak | Not measured | Yes | ||
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 13 months ago8 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2025-10-10 | GitHub repository | Yes | |
| Latest release | Not measured | Yes | ||
| First release | Not measured | Yes | ||
| Latest version | Not measured | Yes | ||
| Days the oldest outside issue waits for a reply | 420 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 0 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | Not measured | Yes | ||
| Published docs | Not measured | Yes | ||
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityNot measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | Not measured | Yes | ||
| RustSec unmaintained advisory | Not measured | Yes | ||
| Deprecation notice | Not measured | Yes | ||
| Deprecated requirement | Not measured | Yes |
Distribution0 binary downloads over the last 3 releases10 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | Not measured | Yes | ||
| Downloads over 30 days | Not measured | Yes | ||
| Binary downloads over the last 3 releases | 0 | GitHub releases | Yes | |
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | Not measured | Yes | ||
| Every version 0.0.x | Not measured | Yes | ||
| Every version yanked | Not measured | Yes | ||
| Crate deleted from crates.io | Not measured | Yes |
Repository3,192 stars, 268 forks, 6 contributors, 109 commits. Stars alone never qualify a project.1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 3192 | GitHub repository | Yes โ one part of the repository route | |
| GitHub forks | 268 | GitHub repository | Yes โ one part of the repository route | |
| Contributors with a GitHub account | 6 | GitHub contributors | Yes โ one part of the repository route | |
| Commits on the default branch | 109 | GitHub repository | No | |
| Repository's main crate left out of the entry | Not measured | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | MIT | GitHub repository | No | |
| Runs on, from listed crates and their direct dependencies | Not measured | No | ||
| What shows each backend | Not measured | No | ||
| Native code, from listed crates and their dependencies | Not measured | No | ||
| Python bindings, from direct dependencies of listed crates | Not measured | No | ||
| Crates that depend on a listed crate directly | Not measured | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.