#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SourceDtype {
F32,
F16,
BF16,
Fp8E4M3,
Mxfp4E2M1,
E8M0Scale,
I32,
I64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ArchName {
Gemma4,
Gemma4Mmproj,
Gemma4VisionMmproj,
Qwen35Moe,
Qwen35MoeFull,
Qwen3VlText,
Bert,
NomicBert,
Llama3,
MiniMaxM2,
Deepseek4,
Falcon,
}
impl ArchName {
pub const fn name(self) -> &'static str {
match self {
ArchName::Gemma4 => "gemma4",
ArchName::Gemma4Mmproj => "gemma4_mmproj",
ArchName::Gemma4VisionMmproj => "gemma4_vision_mmproj",
ArchName::Qwen35Moe => "qwen3moe",
ArchName::Qwen35MoeFull => "qwen35moe",
ArchName::Qwen3VlText => "qwen3vl",
ArchName::Bert => "bert",
ArchName::NomicBert => "nomic-bert",
ArchName::Llama3 => "llama",
ArchName::MiniMaxM2 => "minimax-m2",
ArchName::Deepseek4 => "deepseek4",
ArchName::Falcon => "falcon",
}
}
pub fn from_label(label: &str) -> Option<Self> {
match label {
"gemma4" => Some(ArchName::Gemma4),
"gemma4_mmproj" => Some(ArchName::Gemma4Mmproj),
"gemma4_vision_mmproj" => Some(ArchName::Gemma4VisionMmproj),
"qwen3moe" => Some(ArchName::Qwen35Moe),
"qwen35moe" => Some(ArchName::Qwen35MoeFull),
"qwen3vl" => Some(ArchName::Qwen3VlText),
"bert" => Some(ArchName::Bert),
"nomic-bert" => Some(ArchName::NomicBert),
"llama" => Some(ArchName::Llama3),
"minimax-m2" => Some(ArchName::MiniMaxM2),
"deepseek4" => Some(ArchName::Deepseek4),
"falcon" => Some(ArchName::Falcon),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct TensorRef<'a> {
pub name: &'a str,
pub shape: &'a [usize],
pub source_dtype: SourceDtype,
pub arch: ArchName,
pub layer_index: Option<usize>,
}
impl<'a> TensorRef<'a> {
pub const fn n_per_row(&self) -> usize {
self.shape[0]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn arch_names_lowercase() {
for arch in [
ArchName::Gemma4,
ArchName::Qwen35Moe,
ArchName::Bert,
ArchName::Llama3,
ArchName::MiniMaxM2,
] {
assert!(
arch.name()
.chars()
.all(|c| c.is_ascii_lowercase() || c == '_' || c == '-' || c.is_ascii_digit()),
"arch name {} must be lowercase/digits/_-",
arch.name()
);
}
}
#[test]
fn tensor_ref_n_per_row() {
let shape = [4096, 32];
let t = TensorRef {
name: "blk.0.attn_q.weight",
shape: &shape,
source_dtype: SourceDtype::BF16,
arch: ArchName::Llama3,
layer_index: Some(0),
};
assert_eq!(t.n_per_row(), 4096);
}
}