Skip to content
Merged
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
18 changes: 18 additions & 0 deletions mistralrs-core/src/gguf/gguf_tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ impl TryFrom<ContentMetadata<'_>> for PropsGGUF {
bos: c.get_value("bos_token_id").ok(),
};

// Special token ids come from untrusted GGUF metadata; reject out-of-range ids
// so a malformed file errors instead of panicking when indexing `tokens`.
let vocab_size = props.tokens.len();
let check = |name: &str, id: u32| -> Result<()> {
anyhow::ensure!(
(id as usize) < vocab_size,
"GGUF `{name}` token id {id} is out of bounds for vocab size {vocab_size}"
);
Ok(())
};
check("eos", props.eos)?;
if let Some(bos) = props.bos {
check("bos", bos)?;
}
if let Some(unk) = props.unk {
check("unk", unk)?;
}

Ok(props)
}
}
Expand Down
Loading