spark-adapters
Hardware abstraction adapters for local AI accelerators
Brought by drakestapleton
spark-adapters / src / bin / spark_distill.rs
| 1 | use clap::Parser; |
| 2 | use spark_adapters::models::{DistillTask, TaskType, VerificationStrategy}; |
| 3 | use spark_adapters::DistillationEngine; |
| 4 | use std::path::PathBuf; |
| 5 | use uuid::Uuid; |
| 6 | |
| 7 | #[derive(Parser, Debug)] |
| 8 | #[command(name = "spark-distill")] |
| 9 | #[command(author = "AIEN <aien.atlas@proton.me>")] |
| 10 | #[command(version = "0.1.0")] |
| 11 | #[command(about = "Sovereign Teacher Distillation and Training Pair Generator for Open-Weight Models")] |
| 12 | struct Args { |
| 13 | #[arg(short, long, help = "Task prompt or reasoning challenge to evaluate")] |
| 14 | prompt: String, |
| 15 | |
| 16 | #[arg(short, long, default_value = "anthropic/claude-3-7-sonnet", help = "Teacher model identifier")] |
| 17 | teacher: String, |
| 18 | |
| 19 | #[arg(short, long, default_value = "atlas-lightning-omni", help = "Student open-weight model seat")] |
| 20 | student: String, |
| 21 | |
| 22 | #[arg(long, default_value = "code", help = "Task type: code, arch, reasoning, refactor, harness")] |
| 23 | task_type: String, |
| 24 | |
| 25 | #[arg(long, default_value = "compiler", help = "Verification strategy: compiler, unslop, json, consensus")] |
| 26 | verify: String, |
| 27 | |
| 28 | #[arg(long, help = "Commit high-scoring verified solution to Cortex memory")] |
| 29 | commit_cortex: bool, |
| 30 | |
| 31 | #[arg(long, help = "Custom dataset directory for SFT/DPO output")] |
| 32 | dataset_dir: Option<PathBuf>, |
| 33 | } |
| 34 | |
| 35 | #[tokio::main] |
| 36 | async fn main() { |
| 37 | let args = Args::parse(); |
| 38 | |
| 39 | let task_type = match args.task_type.to_lowercase().as_str() { |
| 40 | "arch" => TaskType::SystemArchitecture, |
| 41 | "reasoning" => TaskType::ReasoningTrace, |
| 42 | "refactor" => TaskType::RefactorLogic, |
| 43 | "harness" => TaskType::VerificationHarness, |
| 44 | _ => TaskType::CodeSynthesis, |
| 45 | }; |
| 46 | |
| 47 | let strategy = match args.verify.to_lowercase().as_str() { |
| 48 | "unslop" => VerificationStrategy::UnslopStrict, |
| 49 | "json" => VerificationStrategy::JsonSchema, |
| 50 | "consensus" => VerificationStrategy::DualConsensus, |
| 51 | _ => VerificationStrategy::CompilerCheck, |
| 52 | }; |
| 53 | |
| 54 | let task = DistillTask { |
| 55 | id: Uuid::new_v4().to_string(), |
| 56 | task_type, |
| 57 | prompt: args.prompt.clone(), |
| 58 | system_prompt: Some("You are a verified sovereign systems specialist. Output clear, compilable native code with zero unslop.".to_string()), |
| 59 | teacher_model: args.teacher.clone(), |
| 60 | student_model: Some(args.student.clone()), |
| 61 | verification_strategy: strategy, |
| 62 | commit_to_cortex: args.commit_cortex, |
| 63 | }; |
| 64 | |
| 65 | println!("=== Sovereign Knowledge Distillation ==="); |
| 66 | println!("Task ID: {}", task.id); |
| 67 | println!("Teacher: {}", task.teacher_model); |
| 68 | println!("Student: {}", task.student_model.as_deref().unwrap_or("<none>")); |
| 69 | println!("Prompt: {}", task.prompt); |
| 70 | |
| 71 | let mut engine = DistillationEngine::new(); |
| 72 | if let Some(dir) = args.dataset_dir { |
| 73 | engine = engine.with_dataset_dir(dir); |
| 74 | } |
| 75 | |
| 76 | match engine.distill(task).await { |
| 77 | Ok(record) => { |
| 78 | println!("\n=== Distillation Complete ==="); |
| 79 | println!("Teacher Verification: Passed: {}, Score: {:.2}", |
| 80 | record.teacher_rollout.verification.passed, |
| 81 | record.teacher_rollout.verification.score |
| 82 | ); |
| 83 | if let Some(ref s_roll) = record.student_rollout { |
| 84 | println!("Student Verification: Passed: {}, Score: {:.2}", |
| 85 | s_roll.verification.passed, |
| 86 | s_roll.verification.score |
| 87 | ); |
| 88 | println!("Preference Delta: {:.2}", record.preference_delta); |
| 89 | } |
| 90 | if record.durable_memory_committed { |
| 91 | println!("Cortex Entity: {}", record.cortex_entity_id.as_deref().unwrap_or("<committed>")); |
| 92 | } |
| 93 | println!("Datasets Appended: {}/sft.jsonl, {}/dpo.jsonl", |
| 94 | engine.dataset_dir.display(), |
| 95 | engine.dataset_dir.display() |
| 96 | ); |
| 97 | } |
| 98 | Err(e) => { |
| 99 | eprintln!("Distillation error: {}", e); |
| 100 | std::process::exit(1); |
| 101 | } |
| 102 | } |
| 103 | } |