Skip to main content

Crate lattice_tune

Crate lattice_tune 

Source
Expand description

lattice-tune - Training infrastructure for Lattice neural models

Provides a complete pipeline for training neural networks through knowledge distillation:

  • Data: Training examples, datasets, and batching
  • Distill: Knowledge distillation from teacher models (Claude, GPT, Gemini)
  • Train: Training loop, optimization, and checkpointing
  • Registry: Model versioning, storage, and deployment tracking

§Architecture

Raw Data → Teacher (LLM) → Soft Labels → Dataset → Training → Model → Registry
                                                       ↓
                                                  Deployment

§Quick Start

use lattice_tune::data::{TrainingExample, IntentLabels, Dataset, DatasetConfig};

// Create training examples
let examples = vec![
    TrainingExample::new(
        vec![vec![0.1, 0.2, 0.3]],  // context embeddings
        vec![0.4, 0.5, 0.6],        // message embedding
        IntentLabels::continuation(0.8),
    ),
];

// Create a dataset
let dataset = Dataset::from_examples(examples);
let stats = dataset.stats();
println!("Dataset has {} examples", stats.num_examples);

§Distillation Example

use lattice_tune::distill::{TeacherConfig, DistillationPipeline, RawExample};

// Configure teacher model
let teacher = TeacherConfig::claude_sonnet();

// Create distillation pipeline
let mut pipeline = DistillationPipeline::with_teacher(teacher)?;

// Create raw examples (text, not embeddings)
let raw = RawExample::new(
    vec!["Hello".to_string(), "How are you?".to_string()],
    "What's the weather like?",
);

// Label with teacher
let result = pipeline.label_single(&raw)?;
println!("Labeled with confidence: {}", result.confidence);

§Training Example

use lattice_tune::train::{TrainingConfig, TrainingLoop};
use lattice_tune::data::Dataset;

// Configure training
let config = TrainingConfig::default()
    .epochs(100)
    .batch_size(32)
    .learning_rate(0.001);

// Train
let mut trainer = TrainingLoop::new(config)?;
let metrics = trainer.train(&mut dataset)?;

println!("Final loss: {:.4}", metrics.final_train_loss);

§Registry Example

use lattice_tune::registry::{ModelRegistry, RegisteredModel, ModelMetadata};

// Create a registry
let registry = ModelRegistry::in_memory();

// Register a model
let metadata = ModelMetadata::classifier(768, 6, 10000);
let model = RegisteredModel::new("intent_classifier", "1.0.0")
    .with_metadata(metadata)
    .with_description("Intent classification model");

let weights = vec![0u8; 1000]; // Model weights
let id = registry.register(model, &weights).unwrap();

// Retrieve the model
let loaded = registry.get("intent_classifier", "1.0.0").unwrap();
println!("Loaded: {}", loaded.full_name());

§Design Principles

  1. Data-first: Well-defined training example format with full traceability
  2. Modular: Distillation, training, and registry are separate concerns
  3. Extensible: Support different teacher models (Claude, GPT, Gemini)
  4. Traceable: All models have version, training config, and metrics

§Feature Flags

  • std (default): Standard library support
  • serde: Serialization support for all types

Re-exports§

pub use error::Result;
pub use error::TuneError;
pub use data::Batch;
pub use data::Dataset;
pub use data::DatasetConfig;
pub use data::DatasetStats;
pub use data::ExampleMetadata;
pub use data::IntentLabels;
pub use data::TrainingExample;
pub use distill::DistillationConfig;
pub use distill::DistillationPipeline;
pub use distill::DistillationStats;
pub use distill::EndpointSecurity;
pub use distill::LabelingResult;
pub use distill::TeacherConfig;
pub use distill::TeacherConfigBuilder;
pub use distill::TeacherProvider;
pub use train::Checkpoint;
pub use train::EarlyStopping;
pub use train::EpochMetrics;
pub use train::JitAdapter;
pub use train::JitConfig;
pub use train::JitResult;
pub use train::JitStrategy;
pub use train::LRSchedule;
pub use train::LoggingCallback;
pub use train::NoOpCallback;
pub use train::Optimizer;
pub use train::OptimizerConfig;
pub use train::RegularizationConfig;
pub use train::TrainingCallback;
pub use train::TrainingConfig;
pub use train::TrainingLoop;
pub use train::TrainingMetrics;
pub use train::TrainingState;
pub use train::freeze;
pub use lora::LoraAdapter;
pub use lora::LoraConfig;
pub use lora::LoraLayer;
pub use registry::LiveModel;
pub use registry::ModelMetadata;
pub use registry::ModelQuery;
pub use registry::ModelRegistry;
pub use registry::ModelStatus;
pub use registry::RegisteredModel;
pub use registry::RollbackController;
pub use registry::RollbackRecord;
pub use registry::ShadowComparison;
pub use registry::ShadowConfig;
pub use registry::ShadowSession;
pub use registry::ShadowState;
pub use registry::StorageBackend;

Modules§

data
Training data types and utilities
distill
Knowledge distillation module
error
Error types for lattice-tune
lora
LoRA (Low-Rank Adaptation) adapter loading and inference integration.
prelude
Prelude module for common imports
registry
Model registry module
train
Training orchestration module