Skip to main content

Crate rust_ai_core

Crate rust_ai_core 

Source
Expand description

§rust-ai-core

Unified AI engineering toolkit that orchestrates the complete rust-ai ecosystem.

This crate integrates 8 specialized AI/ML crates into a cohesive toolkit:

CratePurpose
peft-rsLoRA, DoRA, AdaLoRA adapters for parameter-efficient fine-tuning
qlora-rs4-bit quantized LoRA for memory-efficient fine-tuning
unsloth-rsOptimized transformer blocks (attention, FFN, normalization)
axolotl-rsYAML-driven training orchestration and configuration
bitnet-quantizeMicrosoft BitNet b1.58 ternary quantization
trit-vsaBalanced ternary arithmetic and VSA operations
vsa-optim-rsVSA-based deterministic training optimization
tritter-accelGPU-accelerated ternary operations

§Quick Start

§Using the Unified API

use rust_ai_core::{RustAI, RustAIConfig};

// Initialize the unified API
let ai = RustAI::new(RustAIConfig::default())?;

// Configure fine-tuning with LoRA
let finetune_config = ai.finetune()
    .model("meta-llama/Llama-2-7b")
    .rank(64)
    .alpha(16.0)
    .build()?;

// Configure quantization
let quant_config = ai.quantize()
    .method(QuantizeMethod::Nf4)
    .bits(4)
    .build();

// Configure VSA operations
let vsa_config = ai.vsa()
    .dimension(10000)
    .build();

§Direct Crate Access

use rust_ai_core::ecosystem::peft::{LoraConfig, LoraLinear};
use rust_ai_core::ecosystem::qlora::QLoraConfig;
use rust_ai_core::ecosystem::bitnet::TernaryLinear;
use rust_ai_core::ecosystem::trit::TritVector;

§Using Foundation Types

use rust_ai_core::{get_device, DeviceConfig, CoreError, Result};

fn main() -> Result<()> {
    // Get CUDA device with automatic fallback + warning
    let device = get_device(&DeviceConfig::default())?;

    // Or configure from environment variables
    let config = DeviceConfig::from_env();
    let device = get_device(&config)?;

    Ok(())
}

§Design Philosophy

CUDA-first: All operations prefer GPU execution. CPU is a fallback that emits warnings, not a silent alternative. Users are immediately aware when they’re not getting optimal performance.

Zero-cost abstractions: Traits compile to static dispatch with no vtable overhead. The abstraction layer adds no runtime cost compared to direct implementations.

Fail-fast validation: Configuration errors are caught at construction time, not deep in a training loop. This saves users from wasted compute time.

Unified API: The RustAI facade provides a single entry point for all AI engineering tasks, automatically composing the right ecosystem crates.

§Modules

§Foundation Modules

  • device - CUDA-first device selection with environment variable overrides
  • error - Unified error types across all rust-ai crates
  • traits - Common traits for configs, quantization, and GPU dispatch
  • memory - Memory estimation and tracking utilities
  • dtype - Data type utilities and precision helpers
  • logging - Unified logging and observability
  • [cubecl] - CubeCL ↔ Candle tensor interoperability (requires cuda feature)

§Ecosystem Modules

§Feature Flags

FeatureDescriptionDependencies
cudaEnable CUDA support via Candle and CubeCLcubecl, cubecl-cuda
pythonEnable Python bindings via PyO3pyo3, numpy
napiEnable Node.js bindings via napi-rsnapi, napi-derive
wasmEnable WebAssembly bindings via wasm-bindgenwasm-bindgen, js-sys
fullEnable CUDA and Pythoncuda, python
full-bindingsEnable all bindingscuda, python, napi, wasm

§Environment Variables

VariableDescriptionExample
RUST_AI_FORCE_CPUForce CPU execution1 or true
RUST_AI_CUDA_DEVICESelect CUDA device ordinal0, 1
RUST_LOGControl logging levelrust_ai_core=debug

Re-exports§

pub use device::get_device;
pub use device::warn_if_cpu;
pub use device::DeviceConfig;
pub use dtype::bytes_per_element;
pub use dtype::is_floating_point;
pub use dtype::DTypeExt;
pub use error::CoreError;
pub use error::Result;
pub use logging::init_logging;
pub use logging::LogConfig;
pub use memory::estimate_tensor_bytes;
pub use memory::MemoryTracker;
pub use traits::Dequantize;
pub use traits::GpuDispatchable;
pub use traits::Quantize;
pub use traits::ValidatableConfig;
pub use facade::AdapterType;
pub use facade::FinetuneBuilder;
pub use facade::FinetuneConfig;
pub use facade::QuantizeBuilder;
pub use facade::QuantizeConfig;
pub use facade::QuantizeMethod;
pub use facade::RustAI;
pub use facade::RustAIConfig;
pub use facade::RustAIInfo;
pub use facade::TrainBuilder;
pub use facade::TrainConfig;
pub use facade::VsaBuilder;
pub use facade::VsaConfig;
pub use ecosystem::EcosystemInfo;

Modules§

device
CUDA-first device selection with environment variable overrides.
dtype
Data type utilities and precision helpers.
ecosystem
Unified re-exports from all rust-ai ecosystem crates.
error
Unified error types for the rust-ai ecosystem.
facade
High-level unified API facade.
logging
Unified logging and observability for the rust-ai ecosystem.
memory
Memory estimation and tracking utilities for GPU operations.
traits
Common traits for the rust-ai ecosystem.

Macros§

log_metric
Macro to log a training metric with consistent field names.

Constants§

VERSION
Crate version for runtime version checking.