use serde::{Deserialize, Serialize};
use super::FineTuneMethod;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub enum ModelParadigm {
TraditionalMl,
#[default]
DeepLearning,
FineTuning(FineTuneMethod),
Distillation,
MoE,
Ensemble,
}
impl ModelParadigm {
pub fn lora(rank: u32, alpha: f32) -> Self {
Self::FineTuning(FineTuneMethod::LoRA { rank, alpha })
}
pub fn qlora(rank: u32, bits: u8) -> Self {
Self::FineTuning(FineTuneMethod::QLoRA { rank, bits })
}
pub fn typical_memory_multiplier(&self) -> f64 {
match self {
Self::TraditionalMl => 1.5,
Self::DeepLearning => 4.0,
Self::FineTuning(method) => method.memory_multiplier(),
Self::Distillation => 5.0,
Self::MoE => 2.0,
Self::Ensemble => 3.0,
}
}
pub fn typical_training_speedup(&self) -> f64 {
match self {
Self::TraditionalMl => 10.0,
Self::DeepLearning => 1.0,
Self::FineTuning(method) => method.training_speedup(),
Self::Distillation => 1.5,
Self::MoE => 0.8,
Self::Ensemble => 0.5,
}
}
pub fn typical_quality_retention(&self) -> f64 {
match self {
Self::TraditionalMl => 0.7,
Self::DeepLearning => 1.0,
Self::FineTuning(method) => method.quality_retention(),
Self::Distillation => 0.85,
Self::MoE => 1.05,
Self::Ensemble => 1.02,
}
}
pub fn requires_pretrained(&self) -> bool {
matches!(self, Self::FineTuning(_) | Self::Distillation)
}
pub fn is_parameter_efficient(&self) -> bool {
matches!(
self,
Self::FineTuning(
FineTuneMethod::LoRA { .. }
| FineTuneMethod::QLoRA { .. }
| FineTuneMethod::Adapter
| FineTuneMethod::Prefix
| FineTuneMethod::IA3
)
)
}
pub fn batch_size_multiplier(&self) -> f64 {
match self {
Self::TraditionalMl => 10.0,
Self::DeepLearning => 1.0,
Self::FineTuning(method) => method.batch_size_multiplier(),
Self::Distillation => 0.5,
Self::MoE => 1.2,
Self::Ensemble => 0.3,
}
}
}
impl std::fmt::Display for ModelParadigm {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::TraditionalMl => write!(f, "Traditional ML"),
Self::DeepLearning => write!(f, "Deep Learning"),
Self::FineTuning(method) => write!(f, "Fine-tuning ({method})"),
Self::Distillation => write!(f, "Knowledge Distillation"),
Self::MoE => write!(f, "Mixture of Experts"),
Self::Ensemble => write!(f, "Ensemble"),
}
}
}