#[test]
fn test_gguf_model_config_clone() {
let cfg = gguf::GgufModelConfig {
architecture: Some("phi".to_string()),
hidden_size: Some(2048),
num_layers: Some(24),
num_heads: Some(32),
num_kv_heads: Some(32),
vocab_size: Some(51200),
intermediate_size: Some(8192),
max_position_embeddings: Some(2048),
rope_theta: Some(10000.0),
rms_norm_eps: Some(1e-5),
rope_type: Some(0),
..Default::default()
};
let cloned = cfg.clone();
assert_eq!(cloned.architecture, cfg.architecture);
assert_eq!(cloned.hidden_size, cfg.hidden_size);
}
#[test]
fn test_gguf_model_config_debug() {
let cfg = gguf::GgufModelConfig::default();
let debug_str = format!("{cfg:?}");
assert!(debug_str.contains("GgufModelConfig"));
}
fn valid_gguf_model_config() -> gguf::GgufModelConfig {
gguf::GgufModelConfig {
architecture: Some("llama".to_string()),
hidden_size: Some(4096),
num_layers: Some(32),
num_heads: Some(32),
num_kv_heads: Some(8),
vocab_size: Some(32_000),
intermediate_size: Some(11_008),
max_position_embeddings: Some(4096),
rope_theta: Some(10_000.0),
rms_norm_eps: Some(1e-6),
rope_type: Some(0),
..Default::default()
}
}
#[test]
fn test_falsify_bounds_valid_config_no_warning() {
let cfg = valid_gguf_model_config();
cfg.warn_out_of_bounds(); }
#[test]
fn test_falsify_bounds_hidden_size_max() {
let mut cfg = valid_gguf_model_config();
cfg.hidden_size = Some(65_536);
cfg.warn_out_of_bounds();
cfg.hidden_size = Some(65_537);
cfg.warn_out_of_bounds(); }
#[test]
fn test_falsify_bounds_num_layers_max() {
let mut cfg = valid_gguf_model_config();
cfg.num_layers = Some(256);
cfg.warn_out_of_bounds();
cfg.num_layers = Some(257);
cfg.warn_out_of_bounds(); }
#[test]
fn test_falsify_bounds_vocab_size_max() {
let mut cfg = valid_gguf_model_config();
cfg.vocab_size = Some(1_000_000);
cfg.warn_out_of_bounds();
cfg.vocab_size = Some(1_000_001);
cfg.warn_out_of_bounds(); }
#[test]
fn test_falsify_bounds_rope_theta_range() {
let mut cfg = valid_gguf_model_config();
cfg.rope_theta = Some(1.0);
cfg.warn_out_of_bounds();
cfg.rope_theta = Some(100_000_000.0);
cfg.warn_out_of_bounds();
cfg.rope_theta = Some(0.5);
cfg.warn_out_of_bounds();
cfg.rope_theta = Some(200_000_000.0);
cfg.warn_out_of_bounds(); }
#[test]
fn test_falsify_bounds_eps_range() {
let mut cfg = valid_gguf_model_config();
cfg.rms_norm_eps = Some(1e-10);
cfg.warn_out_of_bounds();
cfg.rms_norm_eps = Some(0.01);
cfg.warn_out_of_bounds();
cfg.rms_norm_eps = Some(0.1);
cfg.warn_out_of_bounds(); }
#[test]
fn test_falsify_bounds_none_fields_no_warning() {
let cfg = gguf::GgufModelConfig::default();
cfg.warn_out_of_bounds(); }
#[test]
fn test_falsify_bounds_match_yaml_contract() {
struct BoundsSpec {
field: &'static str,
min: usize,
max: usize,
}
let specs = [
BoundsSpec { field: "hidden_size", min: 1, max: 65_536 },
BoundsSpec { field: "num_layers", min: 1, max: 256 },
BoundsSpec { field: "num_heads", min: 1, max: 256 },
BoundsSpec { field: "num_kv_heads", min: 1, max: 256 },
BoundsSpec { field: "vocab_size", min: 1, max: 1_000_000 },
BoundsSpec { field: "intermediate_size", min: 1, max: 262_144 },
BoundsSpec { field: "max_position_embeddings", min: 0, max: 2_097_152 },
];
for spec in &specs {
let mut cfg = valid_gguf_model_config();
match spec.field {
"hidden_size" => cfg.hidden_size = Some(spec.max),
"num_layers" => cfg.num_layers = Some(spec.max),
"num_heads" => cfg.num_heads = Some(spec.max),
"num_kv_heads" => cfg.num_kv_heads = Some(spec.max),
"vocab_size" => cfg.vocab_size = Some(spec.max),
"intermediate_size" => cfg.intermediate_size = Some(spec.max),
"max_position_embeddings" => cfg.max_position_embeddings = Some(spec.max),
_ => unreachable!(),
}
cfg.warn_out_of_bounds();
let mut cfg = valid_gguf_model_config();
match spec.field {
"hidden_size" => cfg.hidden_size = Some(spec.min),
"num_layers" => cfg.num_layers = Some(spec.min),
"num_heads" => cfg.num_heads = Some(spec.min),
"num_kv_heads" => cfg.num_kv_heads = Some(spec.min),
"vocab_size" => cfg.vocab_size = Some(spec.min),
"intermediate_size" => cfg.intermediate_size = Some(spec.min),
"max_position_embeddings" => cfg.max_position_embeddings = Some(spec.min),
_ => unreachable!(),
}
cfg.warn_out_of_bounds();
}
}