lattice-tune
Knowledge distillation and training infrastructure for lattice neural models.
Features
- Knowledge Distillation: Teacher (LLM) -> soft labels -> student (tiny NN) pipeline
- Multi-Provider Teachers: Claude, OpenAI, Gemini, local models (Ollama)
- Model Registry: Semver versioning with lineage tracking
- Endpoint Security: TLS enforcement, domain whitelisting, checksum verification
Pipeline Overview
Raw Data -> Teacher (LLM) -> Soft Labels -> Dataset -> Training -> Model -> Registry
|
Deployment
Quick Start
use ;
// Create training examples
let examples = vec!;
// Create a dataset
let dataset = from_examples;
let stats = dataset.stats;
println!;
Teacher Configuration
Providers
| Provider | Model Examples | Notes |
|---|---|---|
Claude |
claude-sonnet-4, claude-3-5-haiku | Anthropic API |
OpenAI |
gpt-4-turbo-preview | OpenAI API |
Gemini |
gemini-pro | Google AI |
Local |
llama, mistral | Ollama-compatible |
TeacherConfig
use ;
// Pre-configured providers
let claude = claude_sonnet;
let gpt = gpt4;
let gemini = gemini_pro;
let local = local;
// Custom configuration with builder
let config = builder
.provider
.model_id
.temperature
.max_tokens
.timeout_ms
.max_retries
.build;
// Validate before use
config.validate?;
Endpoint Security
use EndpointSecurity;
// Default secure settings (TLS required, known domains only)
let security = default_secure;
// For local models (no TLS required)
let local_security = for_local;
// Custom security with certificate pinning
let custom = default_secure
.with_cert_fingerprint
.with_model_checksum;
// Verify endpoint before use
security.verify_endpoint?;
Training Examples
TrainingExample
use ;
// Create with soft labels
let example = new;
// Access fields
println!;
println!;
IntentLabels
Soft labels for 6 intent classes.
use IntentLabels;
// Single-class dominant labels
let continuation = continuation;
let topic_shift = topic_shift;
let explicit_query = explicit_query;
let person_lookup = person_lookup;
let health_check = health_check;
let task_status = task_status;
// Access probabilities
println!;
println!;
Dataset Management
Creating a Dataset
use ;
let examples: =
.map
.collect;
let mut dataset = from_examples;
// Configure batching
let config = with_batch_size
.shuffle
.seed
.validation_split;
dataset.set_config?;
let stats = dataset.stats;
println!;
println!;
Validation Split
use ;
let config = with_batch_size
.validation_split; // 20% for validation
// Dataset automatically handles train/validation split
Distillation Pipeline
use ;
// Configure teacher
let teacher = claude_sonnet;
// Create pipeline
let mut pipeline = with_teacher?;
// Create raw example (text, not embeddings)
let raw = new;
// Label with teacher
let result = pipeline.label_single?;
println!;
// Check statistics
let stats = pipeline.stats;
println!;
println!;
Training
TrainingConfig
use ;
let config = default
.epochs
.batch_size
.learning_rate
.optimizer
.lr_schedule
.early_stopping; // Stop if no improvement for 10 epochs
config.validate?;
Learning Rate Schedules
| Schedule | Description |
|---|---|
Constant |
Fixed learning rate |
StepDecay { step_size, gamma } |
Reduce by gamma every step_size epochs |
CosineAnnealing { min_lr, t_max } |
Smooth decay to min_lr over t_max epochs |
OneCycle { max_lr, pct_start, total_steps } |
Warmup + annealing |
LinearWarmup { warmup_steps } |
Linear warmup phase |
Training Loop
use ;
use Dataset;
let config = quick; // Fast training preset
let mut trainer = new?;
let metrics = trainer.train?;
println!;
println!;
Checkpointing
use Checkpoint;
// Save checkpoint
let checkpoint = new;
checkpoint.save?;
// Load checkpoint
let loaded = load?;
let network = loaded.into_network;
Model Registry
RegisteredModel
use ;
// Create in-memory registry
let mut registry = in_memory;
// Create model with metadata
let metadata = classifier
.dataset;
let model = new
.with_metadata
.with_description;
// Register with weights
let weights = vec!;
let id = registry.register?;
// Retrieve the model
let loaded = registry.get?;
println!;
Model Status Lifecycle
Pending -> Validated -> Staged -> Production
|
v
Archived/Deprecated
use ModelStatus;
// Status transitions
let status = Pending; // Just registered
let status = Validated; // Tests passed
let status = Staged; // Ready for deployment
let status = Production; // Live in production
let status = Archived; // Superseded by newer version
Versioning & Lineage
use ;
// Base model
let base = new;
let base_id = registry.register?;
// Fine-tuned model with parent reference
let metadata = classifier;
let finetuned = new
.with_metadata
.with_parent; // Track lineage
Feature Flags
| Feature | Default | Description |
|---|---|---|
std |
Yes | Standard library support |
serde |
No | Serialization (propagates to lattice-fann) |
gpu |
No | GPU-accelerated training |
gpu-tests |
No | GPU tests requiring hardware |
safetensors |
No | Safe checkpoint serialization |
[]
= { = "0.1" } # Default
= { = "0.1", = ["serde"] } # With serialization
= { = "0.1", = ["gpu"] } # GPU training
= { = "0.1", = ["safetensors"] } # Safe checkpoints
Dependencies
This crate depends on lattice-fann for neural network primitives.
[]
= { = "0.1" }
# lattice-fann is automatically included as a transitive dependency
API Reference
DistillationPipeline
TrainingLoop
ModelRegistry