Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/models/modernbert/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ fn derive_head_dim(
config: &Json,
provenance: &mut BTreeMap<String, FieldOrigin>,
) -> Result<usize> {
ensure!(
heads > 0,
"num_attention_heads must be positive, got {heads}"
);
let head_dim = match config.get("head_dim") {
Some(value) => value
.as_u64()
Expand Down
17 changes: 17 additions & 0 deletions tests/modernbert/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ fn parse(config: &Value) -> ModernBertStructure {
.0
}

#[test]
fn zero_attention_heads_is_rejected_without_panicking() {
for base in [family_config(), vela_encoder_config()] {
for explicit_head_dim in [false, true] {
let mut config = base.clone();
config["num_attention_heads"] = json!(0);
if explicit_head_dim {
config["head_dim"] = json!(64);
}
let error = ModernBertConfigAdapter::from_value(&config, "config.json")
.unwrap_err()
.to_string();
assert!(error.contains("num_attention_heads"), "{error}");
}
}
}

#[test]
fn hf_adapter_parses_the_vela_profile_with_derived_schedule() {
let (structure, meta) =
Expand Down