Skip to main content

entrenar/
lib.rs

1//! # Entrenar: Training & Optimization Library
2//!
3//! Entrenar provides a tape-based autograd engine with optimizers, LoRA/QLoRA,
4//! quantization (QAT/PTQ), model merging (TIES/DARE/SLERP), and knowledge distillation.
5//!
6//! ## Architecture
7//!
8//! - **autograd**: Tape-based automatic differentiation
9//! - **optim**: Optimizers (SGD, Adam, AdamW)
10//! - **lora**: Low-rank adaptation with QLoRA support
11//! - **quant**: Quantization-aware training and post-training quantization
12//! - **merge**: Model merging methods
13//! - **distill**: Knowledge distillation
14//! - **config**: Declarative YAML configuration
15//! - **train**: High-level training loop
16//! - **io**: Model saving and loading (JSON, YAML formats)
17//! - **hf_pipeline**: HuggingFace model fetching and distillation
18//! - **citl**: Compiler-in-the-Loop training with RAG-based fix suggestions (feature-gated)
19//! - **efficiency**: Cost tracking, device detection, and performance benchmarking
20//! - **eval**: Model evaluation framework with metrics, comparison, and drift detection
21//! - **sovereign**: Air-gapped deployment and distribution packaging
22//! - **research**: Academic research artifacts, citations, and archive deposits
23//! - **ecosystem**: PAIML stack integrations (Batuta, Realizar, Ruchy)
24//! - **dashboard**: Real-time training monitoring and WASM bindings
25//! - **yaml_mode**: Declarative YAML Mode Training (v1.0 spec)
26//! - **transformer**: Transformer layers with autograd support
27//! - **moe**: Mixture of Experts sparse routing layer
28//! - **decision**: Decision pattern storage and CITL trainer (GH-28, GH-29)
29//! - **cli**: Command-line interface handlers
30//! - **finetune**: Fine-tuning pipeline with Popperian QA (SPEC-FT-001)
31
32// Contract assertions from YAML (pv codegen)
33#[macro_use]
34#[allow(unused_macros)]
35mod generated_contracts;
36
37// Fallback macros for contracts not yet in build.rs codegen
38// (embedding-lookup-v1 was added in provable-contracts 0.2 but
39// entrenar's build.rs hasn't been updated to generate it yet)
40#[cfg(not(feature = "__has_embedding_contract"))]
41macro_rules! contract_pre_embedding_lookup {
42    () => {{}};
43    ($input:expr) => {{
44        let _ = &$input;
45    }};
46}
47#[cfg(not(feature = "__has_embedding_contract"))]
48#[allow(unused_macros)]
49macro_rules! contract_post_embedding_lookup {
50    ($result:expr) => {{
51        let _ = &$result;
52    }};
53}
54
55// Fallback stubs for contract macros not in generated_contracts.rs.
56// PMAT-517: These MUST cover every contract_pre_*/contract_post_* used in source
57// but not generated by provable-contracts codegen. Without these, crates.io builds
58// fail because the binding.yaml is not available outside the workspace.
59// Run `bash scripts/check_publish_safety.sh` to verify completeness.
60macro_rules! contract_pre_data_read { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
61macro_rules! contract_pre_data_mut { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
62macro_rules! contract_pre_transpose_tracked { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
63#[allow(unused_macros)]
64macro_rules! contract_pre_with_resident_weights { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
65#[allow(unused_macros)]
66macro_rules! contract_pre_alignment_enforcement { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
67#[allow(unused_macros)]
68macro_rules! contract_pre_geometric_mean { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
69#[allow(unused_macros)]
70macro_rules! contract_pre_layer_composition { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
71#[allow(unused_macros)]
72macro_rules! contract_pre_mqs_pass_rate { () => {{}}; ($($x:expr),+ $(,)?) => {{ $(let _ = &$x;)+ }}; }
73
74pub mod aprender_compat;
75pub mod autograd;
76#[cfg(feature = "citl")]
77pub mod citl;
78pub mod cli;
79pub mod config;
80pub mod dashboard;
81pub mod decision;
82pub mod distill;
83pub mod ecosystem;
84pub mod efficiency;
85pub mod eval;
86#[cfg(not(target_arch = "wasm32"))]
87pub mod finetune;
88pub mod generative;
89#[cfg(not(target_arch = "wasm32"))]
90pub mod gpu;
91#[cfg(all(not(target_arch = "wasm32"), feature = "hub"))]
92pub mod hf_pipeline;
93pub mod inference;
94pub mod integrity;
95pub mod io;
96pub mod lora;
97pub mod merge;
98pub mod models;
99pub mod moe;
100pub mod monitor;
101pub mod numerical;
102pub mod optim;
103pub mod pipeline;
104pub mod prune;
105pub mod quality;
106pub mod quant;
107pub mod research;
108pub mod run;
109pub mod safety;
110pub mod search;
111pub mod server;
112pub mod sovereign;
113pub mod sovereign_array;
114pub mod staging;
115pub mod storage;
116pub mod tokenizer;
117pub mod trace;
118pub mod tracking;
119pub mod train;
120pub mod training;
121pub mod transformer;
122pub mod yaml_mode;
123
124pub mod error;
125
126// Re-export commonly used types
127pub use autograd::{backward, Context, Tensor};
128pub use error::{Error, Result};