Aprender provides implementations of classical machine learning algorithms optimized for performance and safety. The library requires no external dependencies beyond the Rust standard library and offers seamless compilation to WebAssembly.
Table of Contents
Features
- Pure Rust — Zero C/C++ dependencies, memory-safe, thread-safe by default
- SIMD Acceleration — Vectorized operations via trueno backend
- WebAssembly Ready — Compile to WASM for browser and edge deployment
- Native Model Format —
.aprformat with encryption, signatures, and zero-copy loading - Interoperability — Export to SafeTensors and GGUF formats
Installation
Add aprender to your Cargo.toml:
[]
= "0.25"
Optional Features
[]
= { = "0.13", = ["format-encryption", "hf-hub-integration"] }
| Feature | Description |
|---|---|
format-encryption |
AES-256-GCM encryption for model files |
format-signing |
Ed25519 digital signatures |
format-compression |
Zstd compression |
hf-hub-integration |
Hugging Face Hub push/pull support |
gpu |
GPU acceleration via wgpu |
Quick Start
use *;
Algorithms
Supervised Learning
| Algorithm | Description |
|---|---|
LinearRegression |
Ordinary least squares regression |
LogisticRegression |
Binary and multiclass classification |
DecisionTreeClassifier |
GINI-based decision trees |
RandomForestClassifier |
Bootstrap aggregating ensemble |
GradientBoostingClassifier |
Adaptive boosting with residual learning |
NaiveBayes |
Gaussian naive Bayes classifier |
KNeighborsClassifier |
k-nearest neighbors |
LinearSVM |
Support vector machine with hinge loss |
Unsupervised Learning
| Algorithm | Description |
|---|---|
KMeans |
k-means++ initialization with Lloyd's algorithm |
DBSCAN |
Density-based spatial clustering |
PCA |
Principal component analysis |
IsolationForest |
Anomaly detection |
Additional Modules
- Graph Analysis — PageRank, betweenness centrality, community detection
- Time Series — ARIMA forecasting
- Text Processing — Tokenization, TF-IDF, stemming, chat templates
- Neural Networks — Sequential models, transformers, mixture of experts
- Metaheuristics — ACO, Tabu Search, DE, PSO, GA, CMA-ES
Chat Templates
Format LLM conversations for different model families with automatic template detection:
use ;
// Auto-detect template from model name
let template = auto_detect_template;
let messages = vec!;
let formatted = template.format_conversation?;
Supported Formats:
| Format | Models | System Prompt |
|---|---|---|
| ChatML | Qwen2, Yi, OpenHermes | Yes |
| Llama2 | TinyLlama, Vicuna, LLaMA 2 | Yes |
| Mistral | Mistral-7B, Mixtral | No |
| Phi | Phi-2, Phi-3 | Yes |
| Alpaca | Alpaca, Guanaco | Yes |
| Raw | Fallback | Passthrough |
| Custom | Any (Jinja2) | Configurable |
See examples/chat_template.rs for complete usage.
Verification: All templates are 100% tested via bashrs probar playbooks. See docs/model-verification-checklist.md for coverage status.
Related Crates
| Crate | Description |
|---|---|
aprender-tsp |
TSP solver with CLI and .apr model persistence |
aprender-shell |
AI-powered shell completion trained on your history |
Resources
| Resource | Description |
|---|---|
| apr-cookbook | 50+ idiomatic Rust examples for .apr format, WASM deployment, and SIMD acceleration |
Model Persistence
The .apr format provides secure, efficient model serialization:
use ;
// Save with encryption
save?;
// Load
let model: LinearRegression = load?;
Format Capabilities
- Security — AES-256-GCM encryption, Ed25519 signatures, X25519 key exchange
- Performance — Memory-mapped loading, 600x faster than standard deserialization
- Integrity — CRC32 checksums with automatic corruption detection
- Commercial — License blocks, watermarking, buyer-specific encryption
APR CLI Tool
The apr CLI provides comprehensive model operations for the .apr format.
Installation
Commands
| Command | Description |
|---|---|
apr run |
Run model directly (auto-download, cache, execute) |
apr serve |
Start inference server (REST API, streaming, metrics) |
apr chat |
Interactive chat with language models |
apr inspect |
Inspect model metadata, vocab, and structure |
apr debug |
Simple debugging output ("drama" mode available) |
apr validate |
Validate model integrity and quality |
apr diff |
Compare two models |
apr tensors |
List tensor names, shapes, and statistics |
apr trace |
Layer-by-layer trace analysis |
apr lint |
Check for best practices and conventions |
apr explain |
Explain errors, architecture, and tensors |
apr canary |
Regression testing via tensor statistics |
apr export |
Export to SafeTensors, GGUF formats |
apr import |
Import from HuggingFace, SafeTensors |
apr pull |
Download and cache model from HuggingFace (Ollama-style UX) |
apr list |
List cached models |
apr rm |
Remove model from cache |
apr convert |
Quantization (int8, int4, fp16) and optimization |
apr merge |
Merge models (average, weighted strategies) |
apr tui |
Interactive terminal UI |
apr probar |
Export for visual testing |
apr tree |
Model architecture tree view |
apr hex |
Hex dump tensor data |
apr flow |
Data flow visualization |
apr bench |
Benchmark throughput (spec H12: >= 10 tok/s) |
apr eval |
Evaluate model perplexity (spec H13: PPL <= 20) |
apr profile |
Deep profiling with Roofline analysis |
apr qa |
Falsifiable QA checklist for model releases |
apr showcase |
Qwen2.5-Coder showcase demo |
apr check |
Model self-test: 10-stage pipeline integrity check |
apr publish |
Publish model to HuggingFace Hub |
apr cbtop |
ComputeBrick pipeline monitor |
apr compare-hf |
Compare APR model against HuggingFace source |
Quick Examples
# Run model directly (auto-downloads if needed)
# Download and cache models (Ollama-style UX)
# Validate model integrity
# Convert with quantization
# Lint for best practices
# Export to GGUF (llama.cpp compatible)
# Merge models (ensemble)
# Create regression test
# Check model against canary
# Publish to HuggingFace Hub
Showcase: Qwen2.5-Coder Inference
The apr CLI achieves 2.93x Ollama performance on Qwen2.5-Coder-1.5B with GPU acceleration:
# Interactive chat
# Single-shot generation
# Production server (OpenAI-compatible API)
Benchmark Results (2026-01-18)
| Mode | Throughput | vs Ollama | Status |
|---|---|---|---|
| GPU Batched (M=16) | 851.8 tok/s | 2.93x | Pass |
| GPU Batched (M=8) | 770.0 tok/s | 2.65x | Pass |
| GPU Single | 120.1 tok/s | 1.0x | Pass |
| CPU | 25.3 tok/s | 1.69x | Pass |
See docs/specifications/qwen2.5-coder-showcase-demo.md for full benchmark methodology.
QA & Testing
The project includes comprehensive QA infrastructure for model validation:
# Run full 21-cell QA matrix (modality × format × backend)
# Run QA falsification suite (Popperian methodology)
# Single modality test with Ollama comparison
QA Matrix Coverage:
- Modalities:
run,chat,serve - Formats: GGUF, SafeTensors, APR
- Backends: CPU, GPU
- Features: Hang detection (60s), garbage output detection, answer verification
See examples/qa_run.rs and examples/qa_falsify.rs for implementation.
Documentation
| Resource | Link |
|---|---|
| API Reference | docs.rs/aprender |
| User Guide | paiml.github.io/aprender |
| Examples | examples/ |
| APR Format Spec | docs/specifications/APR-SPEC.md |
| QA Protocol | docs/specifications/qa-showcase-methodology.md |
Contributing
We welcome contributions. Please ensure your changes pass the test suite:
See CONTRIBUTING.md for guidelines.
License
Aprender is distributed under the MIT License. See LICENSE for details.