use crate::config::ModelConfig;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ModelType {
Llama,
Mistral,
Phi,
Qwen,
Gemma,
Unknown,
}
impl ModelType {
pub fn from_config(config: &ModelConfig) -> Self {
for arch in &config.architectures {
let arch_lower = arch.to_lowercase();
if arch_lower.contains("llama") {
return Self::Llama;
}
if arch_lower.contains("mistral") {
return Self::Mistral;
}
if arch_lower.contains("phi") {
return Self::Phi;
}
if arch_lower.contains("qwen") {
return Self::Qwen;
}
if arch_lower.contains("gemma") {
return Self::Gemma;
}
}
let model_type = config.model_type.to_lowercase();
if model_type.contains("llama") {
return Self::Llama;
}
if model_type.contains("mistral") {
return Self::Mistral;
}
if model_type.contains("phi") {
return Self::Phi;
}
if model_type.contains("qwen") {
return Self::Qwen;
}
if model_type.contains("gemma") {
return Self::Gemma;
}
Self::Unknown
}
pub fn is_supported(&self) -> bool {
matches!(
self,
Self::Llama | Self::Mistral | Self::Phi | Self::Qwen | Self::Gemma
)
}
pub fn name(&self) -> &'static str {
match self {
Self::Llama => "Llama",
Self::Mistral => "Mistral",
Self::Phi => "Phi",
Self::Qwen => "Qwen",
Self::Gemma => "Gemma",
Self::Unknown => "Unknown",
}
}
}
impl std::fmt::Display for ModelType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum QuantFormat {
FP32,
FP16,
BF16,
Int8,
Int4,
}
impl QuantFormat {
pub fn bytes_per_param(&self) -> f32 {
match self {
Self::FP32 => 4.0,
Self::FP16 | Self::BF16 => 2.0,
Self::Int8 => 1.0,
Self::Int4 => 0.5,
}
}
pub fn estimate_size_gb(&self, num_params: usize) -> f32 {
(num_params as f32 * self.bytes_per_param()) / 1_000_000_000.0
}
}