Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ML Framework Detection

ML framework detection scans Python source files for import statements from NumPy, scikit-learn, and PyTorch. Each detected operation is mapped to its equivalent in the Sovereign AI Stack.

Detection Pipeline

The LibraryAnalyzer in src/pipeline_analysis.rs walks all .py files and checks for library-specific import patterns:

#![allow(unused)]
fn main() {
pub struct LibraryAnalyzer {
    numpy_converter: NumPyConverter,
    sklearn_converter: SklearnConverter,
    pytorch_converter: PyTorchConverter,
}
}

Detection is import-gated: a file must contain import numpy or from numpy before individual operations are scanned. This avoids false positives from string matches in comments or documentation.

Framework Mapping

Python FrameworkSovereign Stack CrateLayer
NumPytruenoSIMD/GPU compute primitives
scikit-learnaprenderML algorithms
PyTorch / TransformersrealizarInference engine

NumPy to Trueno

The NumPyConverter maps 12 NumPy operations to Trueno equivalents:

NumPyTruenoComplexity
np.array([...])Vector::from_slice(&[...])Low
np.add(a, b)a.add(&b).unwrap()Low
np.subtract(a, b)a.sub(&b).unwrap()Low
np.multiply(a, b)a.mul(&b).unwrap()Low
np.dot(a, b)a.dot(&b).unwrap()High
np.sum(a)a.sum()Medium

Each operation carries a complexity level that feeds into the MoE backend selector during Phase 3 optimization.

scikit-learn to Aprender

The SklearnConverter maps algorithms across six sklearn module groups:

sklearn ModuleExample AlgorithmAprender Equivalent
linear_modelLinearRegressionaprender::linear_model::LinearRegression
clusterKMeansaprender::cluster::KMeans
treeDecisionTreeClassifieraprender::tree::DecisionTreeClassifier
preprocessingStandardScaleraprender::preprocessing::StandardScaler
model_selectiontrain_test_splitaprender::model_selection::train_test_split
metricsaccuracy_scoreaprender::metrics::accuracy_score

PyTorch to Realizar

The PyTorchConverter handles inference-focused operations:

PyTorchRealizarNotes
torch.load() / from_pretrained()GGUFModel::from_file()Model loading
model.forward(x)model.forward(&input)Inference
model.generate()generate_text(&model, &tokens, len)Text generation
AutoTokenizerTokenizer::from_file()Tokenization
nn.LinearLinearLayer::new(in, out)Layer types
nn.MultiheadAttentionAttentionLayer::new(dim, heads)Attention

CLI Usage

$ batuta analyze --languages --dependencies --tdg ./ml-project

ML Framework Detection
----------------------
NumPy:    model.py (np.array, np.dot, np.sum) --> trueno::Vector
sklearn:  train.py (LinearRegression, KMeans) --> aprender
PyTorch:  infer.py (torch.load, .forward)     --> realizar

Navigate: Table of Contents