Problem Statement
Currently, only 2 of 9 aprender models support SafeTensors serialization (LinearRegression, LogisticRegression). This limits production deployment and cross-platform interoperability.
Current State:
Impact: Cannot deploy most models to production in cross-platform environments (Rust ↔ Python ↔ JavaScript).
Proposed Solution
Add SafeTensors support to all 7 remaining models, following the proven pattern from Issues #5 and #6.
Models to Implement (7 total)
- Ridge (linear_model) - Regularized regression with L2 penalty
- Lasso (linear_model) - Regularized regression with L1 penalty
- ElasticNet (linear_model) - Combined L1+L2 regularization
- DecisionTreeClassifier (tree) - CART algorithm
- RandomForestClassifier (tree) - Ensemble of decision trees
- KMeans (cluster) - Clustering algorithm
- StandardScaler (preprocessing) - Feature standardization
Technical Approach
Each model implements SafeTensorsModel trait:
impl SafeTensorsModel for Ridge {
fn model_type() -> &'static str { "Ridge" }
fn safetensors_metadata(&self) -> HashMap<String, String> {
// Hyperparameters: alpha, fit_intercept, etc.
}
fn safetensors_tensors(&self) -> Vec<(&str, TensorView)> {
// Model parameters: coefficients, intercept
}
fn from_safetensors(
tensors: &HashMap<String, TensorView>,
metadata: &HashMap<String, String>
) -> Result<Self, Box<dyn Error>> {
// Reconstruct model from SafeTensors
}
}
Test Requirements (12+ tests per model)
Per Model Test Suite:
- Basic: save/load roundtrip, metadata verification, tensor shapes
- Edge Cases: invalid paths, corrupted files, missing tensors
- Property Tests: predictions preserved after roundtrip
- Cross-Platform: Python interop (if bindings exist)
Total: 84+ new tests (12 per model × 7 models)
Success Criteria
- ✅ All 7 models implement SafeTensorsModel trait
- ✅ 84+ tests passing (12 per model)
- ✅ Zero clippy warnings (strict mode)
- ✅ Book chapter updated with all 7 models
- ✅ Cross-platform examples documented
- ✅ v0.3.1 released to crates.io
Benefits
Production Readiness:
- Cross-platform model deployment (Rust ↔ Python ↔ JavaScript)
- HuggingFace ecosystem compatibility
- No pickle security vulnerabilities
Developer Experience:
- Consistent serialization API across all models
- Simple save/load interface
- Robust error handling
Strategic:
- Industry-standard format
- Enables aprender models in any SafeTensors-compatible framework
- Future-proof for deep learning models
Estimated Effort
Timeline: 2-3 days
- ~80-100 lines per model implementation
- ~12 tests per model
- Book chapter updates
- Quality gates validation
Complexity: Low (following established pattern)
References
- Work Prompt:
docs/execution/ISSUE-8-WORK-PROMPT.md
- Existing Implementations:
- Test Patterns:
tests/safetensors/linear_regression.rs
tests/safetensors/logistic_regression.rs
- Book Chapter:
book/src/examples/safetensors-delivery-verification.md
- SafeTensors Spec: https://huggingface.co/docs/safetensors/
Acceptance Criteria
Problem Statement
Currently, only 2 of 9 aprender models support SafeTensors serialization (LinearRegression, LogisticRegression). This limits production deployment and cross-platform interoperability.
Current State:
Impact: Cannot deploy most models to production in cross-platform environments (Rust ↔ Python ↔ JavaScript).
Proposed Solution
Add SafeTensors support to all 7 remaining models, following the proven pattern from Issues #5 and #6.
Models to Implement (7 total)
Technical Approach
Each model implements
SafeTensorsModeltrait:Test Requirements (12+ tests per model)
Per Model Test Suite:
Total: 84+ new tests (12 per model × 7 models)
Success Criteria
Benefits
Production Readiness:
Developer Experience:
Strategic:
Estimated Effort
Timeline: 2-3 days
Complexity: Low (following established pattern)
References
docs/execution/ISSUE-8-WORK-PROMPT.mdtests/safetensors/linear_regression.rstests/safetensors/logistic_regression.rsbook/src/examples/safetensors-delivery-verification.mdAcceptance Criteria