Aphelion Framework
A unified frontend for AI model development in Rust.
Overview
Aphelion is a framework frontend that provides an easier entrypoint for AI engineering tasks. It unifies access to Rust AI libraries through a consistent API, handling the complexity of model configuration, pipeline orchestration, and hardware abstraction so you can focus on building models.
Why Aphelion
Building AI systems in Rust means integrating multiple libraries: tensor operations, memory management, device handling, training loops. Aphelion provides:
- Unified API: One consistent interface to underlying AI libraries
- Reusable Components: Configurations and pipelines can be templated and shared
- Deterministic Builds: SHA-256 hashing ensures identical configs produce identical models
- Configuration Management: Type-safe parameters with validation and versioning
- Pipeline Orchestration: Composable stages for training, inference, and deployment
- Backend Abstraction: Write once, run on CPU, GPU, or accelerators
- Diagnostics: Structured tracing for debugging and observability
Ecosystem Integration
Aphelion integrates with the Rust AI ecosystem, providing a frontend to:
| Library | Purpose | Feature Flag |
|---|---|---|
| rust-ai-core | Memory tracking, device detection, dtype utilities | rust-ai-core |
| Candle | Tensor operations and model inference | via rust-ai-core |
| Burn | Deep learning framework | burn |
| CubeCL | GPU compute | cubecl |
Enable features based on your needs. The framework handles library initialization, device selection, and resource management.
Installation
Rust
[]
= "1.2"
= "1.0" # Required for parameter values
Optional features:
[]
= { = "1.2", = ["rust-ai-core", "tokio"] }
| Feature | Description |
|---|---|
rust-ai-core |
Memory tracking, device detection, dtype utilities via rust-ai-core |
cuda |
CUDA GPU support (requires rust-ai-core) |
burn |
Burn deep learning framework backend (placeholder) |
cubecl |
CubeCL GPU compute backend (placeholder) |
tokio |
Async pipeline execution support |
Python
For memory tracking and device detection:
Python usage:
# Build configuration
=
=
=
# Build graph
=
=
# Execute pipeline
=
=
=
Core Concepts
Build Graph
A directed acyclic graph representing model architecture. Each node contains configuration and metadata.
use *;
let mut graph = default;
// Add nodes with configuration
let input = graph.add_node;
let hidden = graph.add_node;
let output = graph.add_node;
// Define data flow
graph.add_edge;
graph.add_edge;
// Deterministic hash for reproducibility
let hash = graph.stable_hash;
The graph hash is computed using SHA-256 over canonicalized node data. Identical graphs produce identical hashes regardless of construction order.
Configuration
Type-safe configuration with parameter validation:
use ModelConfig;
let config = new
.with_param
.with_param
.with_param
.with_param;
// Type-safe retrieval
let d_model: u32 = config.param?;
let dropout: f64 = config.param_or?;
let batch_size: u32 = config.param_or_default?; // Uses Default::default()
Pipeline Execution
Pipelines execute stages in sequence with optional hooks:
use *;
use ;
// Create execution context
let backend = cpu;
let trace = new;
let ctx = new;
// Build pipeline
let pipeline = new
.with_stage
.with_stage
.with_pre_hook
.with_post_hook
.with_progress;
// Execute
let result = pipeline.execute?;
Preset pipelines for common workflows:
let pipeline = standard; // Validation + hashing
let pipeline = for_training; // + training hooks
let pipeline = for_inference; // Minimal, hashing only
Custom Pipeline Stages
Implement the PipelineStage trait:
use ;
use BuildGraph;
use AphelionResult;
;
Custom Backends
Implement the Backend trait for hardware integration:
use ;
use AphelionResult;
Diagnostics and Tracing
Structured event logging with helper methods:
use ;
let trace = new;
// Helper methods reduce boilerplate
trace.info;
trace.warn;
trace.error;
// Export to JSON
let json = trace.to_json;
Validation
Composable validators for configuration checking:
use ;
let validator = new
.with_validator
.with_validator;
match validator.validate
Async Execution
With the tokio feature enabled:
async
Error Handling
All operations return AphelionResult<T>. Errors include context for debugging:
use AphelionError;
// Create errors with context
let error = validation
.in_stage
.for_field;
// Errors chain via std::error::Error::source()
if let Some = error.source
Project Structure
aphelion-framework-rs/
├── crates/
│ ├── aphelion-core/ # Core library: graphs, pipelines, backends
│ ├── aphelion-macros/ # Proc macros: #[aphelion_model]
│ ├── aphelion-python/ # Python bindings via PyO3
│ ├── aphelion-tests/ # Integration tests
│ └── aphelion-examples/ # Usage examples
├── docs/
│ ├── ARCHITECTURE.md # System design and data flow
│ └── API-GUIDE.md # Usage patterns with examples
└── SPEC.md # Success criteria and compliance
Testing
# Run all tests
# With async support
# With all features
Test coverage: 252 tests across unit, integration, and documentation tests.
Design Principles
Determinism: Graph hashes are reproducible. BTreeMap ensures ordered iteration. No implicit randomness.
Explicit over implicit: No hidden state. Configuration is explicit. Errors are typed and contextual.
Composition over inheritance: Pipelines compose stages. Validators compose validators. Backends implement traits.
Zero-cost abstractions: Feature flags gate optional dependencies. Unused code is not compiled.
Documentation
| Document | Description |
|---|---|
| ARCHITECTURE.md | System design, module responsibilities, data flow |
| API-GUIDE.md | Common patterns with working examples |
| SPEC.md | Success criteria and compliance checklist |
Examples
Run examples from the workspace:
Version History
| Version | Features |
|---|---|
| 1.2.1 | rust-ai-core v0.2.6 integration, Python bindings, memory tracking |
| 1.1.0 | Typed params, preset pipelines, async execution, backend auto-detect |
| 1.0.0 | Core pipeline, graph, config, validation, tracing |
Contributing
- Fork the repository
- Create a feature branch from
develop - Write tests for new functionality
- Ensure
cargo test --workspace --all-featurespasses - Ensure
cargo clippy --workspace --all-features -- -D warningspasses - Submit a pull request to
develop
License
This project is licensed under the MIT License - see the LICENSE file for details.