use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StackComponent {
Alimentar,
Aprender,
Pacha,
Realizar,
Presentar,
Batuta,
}
impl StackComponent {
#[must_use]
pub const fn name(&self) -> &'static str {
match self {
Self::Alimentar => "alimentar",
Self::Aprender => "aprender",
Self::Pacha => "pacha",
Self::Realizar => "realizar",
Self::Presentar => "presentar",
Self::Batuta => "batuta",
}
}
#[must_use]
pub const fn english(&self) -> &'static str {
match self {
Self::Alimentar => "to feed",
Self::Aprender => "to learn",
Self::Pacha => "earth/universe",
Self::Realizar => "to accomplish",
Self::Presentar => "to present",
Self::Batuta => "baton",
}
}
#[must_use]
pub const fn description(&self) -> &'static str {
match self {
Self::Alimentar => "Data loading and transformation library",
Self::Aprender => "Machine learning algorithms and training",
Self::Pacha => "Model registry with versioning and lineage",
Self::Realizar => "Pure Rust ML inference engine",
Self::Presentar => "WASM visualization and playgrounds",
Self::Batuta => "Orchestration and oracle mode",
}
}
#[must_use]
pub const fn format(&self) -> Option<&'static str> {
match self {
Self::Alimentar => Some(".ald"),
Self::Aprender => Some(".apr"),
Self::Batuta => Some(".bat"), Self::Pacha | Self::Realizar | Self::Presentar => None,
}
}
#[must_use]
pub const fn magic(&self) -> Option<[u8; 4]> {
match self {
Self::Alimentar => Some([0x41, 0x4C, 0x44, 0x46]), Self::Aprender => Some([0x41, 0x50, 0x52, 0x4E]), Self::Batuta => Some([0x42, 0x41, 0x54, 0x41]), _ => None,
}
}
#[must_use]
pub const fn all() -> &'static [Self] {
&[
Self::Alimentar,
Self::Aprender,
Self::Pacha,
Self::Realizar,
Self::Presentar,
Self::Batuta,
]
}
}
impl std::fmt::Display for StackComponent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} ({})", self.name(), self.english())
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum DerivationType {
Original,
FineTune {
parent_hash: [u8; 32],
epochs: u32,
},
Distillation {
teacher_hash: [u8; 32],
temperature: f32,
},
Merge {
parent_hashes: Vec<[u8; 32]>,
method: String,
},
Quantize {
parent_hash: [u8; 32],
quant_type: QuantizationType,
},
Prune {
parent_hash: [u8; 32],
sparsity: f32,
},
}
impl DerivationType {
#[must_use]
pub const fn type_name(&self) -> &'static str {
match self {
Self::Original => "original",
Self::FineTune { .. } => "fine-tune",
Self::Distillation { .. } => "distillation",
Self::Merge { .. } => "merge",
Self::Quantize { .. } => "quantize",
Self::Prune { .. } => "prune",
}
}
#[must_use]
pub const fn is_derived(&self) -> bool {
!matches!(self, Self::Original)
}
#[must_use]
pub fn parent_hashes(&self) -> Vec<[u8; 32]> {
match self {
Self::Original => vec![],
Self::FineTune { parent_hash, .. }
| Self::Distillation {
teacher_hash: parent_hash,
..
}
| Self::Quantize { parent_hash, .. }
| Self::Prune { parent_hash, .. } => vec![*parent_hash],
Self::Merge { parent_hashes, .. } => parent_hashes.clone(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum QuantizationType {
Int8,
Int4,
Float16,
BFloat16,
Dynamic,
QAT,
}
impl QuantizationType {
#[must_use]
pub const fn bits(&self) -> u8 {
match self {
Self::Int8 | Self::Dynamic | Self::QAT => 8,
Self::Int4 => 4,
Self::Float16 | Self::BFloat16 => 16,
}
}
#[must_use]
pub const fn name(&self) -> &'static str {
match self {
Self::Int8 => "int8",
Self::Int4 => "int4",
Self::Float16 => "fp16",
Self::BFloat16 => "bf16",
Self::Dynamic => "dynamic",
Self::QAT => "qat",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ModelStage {
#[default]
Development,
Staging,
Production,
Archived,
}
impl ModelStage {
#[must_use]
pub const fn name(&self) -> &'static str {
match self {
Self::Development => "development",
Self::Staging => "staging",
Self::Production => "production",
Self::Archived => "archived",
}
}
#[must_use]
pub const fn can_transition_to(&self, target: Self) -> bool {
matches!(
(self, target),
(
Self::Development,
Self::Development | Self::Staging | Self::Archived
) | (
Self::Staging,
Self::Staging | Self::Production | Self::Development
) | (Self::Production, Self::Production | Self::Archived)
)
}
}
impl std::fmt::Display for ModelStage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name())
}
}
#[derive(Debug, Clone)]
pub struct ModelVersion {
pub version: String,
pub hash: [u8; 32],
pub stage: ModelStage,
pub created_at: String,
pub size_bytes: u64,
pub quality_score: Option<f32>,
pub derivation: DerivationType,
pub tags: Vec<String>,
pub metadata: HashMap<String, String>,
}
impl ModelVersion {
#[must_use]
pub fn new(version: impl Into<String>, hash: [u8; 32]) -> Self {
Self {
version: version.into(),
hash,
stage: ModelStage::Development,
created_at: "2025-01-01T00:00:00Z".into(),
size_bytes: 0,
quality_score: None,
derivation: DerivationType::Original,
tags: Vec::new(),
metadata: HashMap::new(),
}
}
#[must_use]
pub const fn with_stage(mut self, stage: ModelStage) -> Self {
self.stage = stage;
self
}
#[must_use]
pub const fn with_size(mut self, size_bytes: u64) -> Self {
self.size_bytes = size_bytes;
self
}
#[must_use]
pub fn with_quality_score(mut self, score: f32) -> Self {
self.quality_score = Some(score);
self
}
#[must_use]
pub fn with_derivation(mut self, derivation: DerivationType) -> Self {
self.derivation = derivation;
self
}
#[must_use]
pub fn with_tag(mut self, tag: impl Into<String>) -> Self {
self.tags.push(tag.into());
self
}
#[must_use]
pub fn hash_hex(&self) -> String {
use std::fmt::Write;
self.hash
.iter()
.fold(String::with_capacity(64), |mut acc, b| {
let _ = write!(acc, "{b:02x}");
acc
})
}
#[must_use]
pub fn is_production_ready(&self) -> bool {
self.stage == ModelStage::Production && self.quality_score.is_some_and(|s| s >= 85.0)
}
}
#[derive(Debug, Clone)]
pub struct InferenceConfig {
pub model_path: PathBuf,
pub port: u16,
pub max_batch_size: u32,
pub timeout_ms: u64,
pub enable_cors: bool,
pub metrics_path: Option<String>,
pub health_path: Option<String>,
}
include!("inference_config.rs");