Unverified Commit 1b1265e6 authored by Graham King's avatar Graham King Committed by GitHub
Browse files

chore: Remove GGUF support (#3488)


Signed-off-by: default avatarGraham King <grahamk@nvidia.com>
parent 0c4c4d1d
......@@ -68,10 +68,6 @@ impl PromptFormatter {
PromptFormatterArtifact::HfChatTemplate(_) => Err(anyhow::anyhow!(
"prompt_formatter should not have type HfChatTemplate"
)),
PromptFormatterArtifact::GGUF(gguf_path) => {
let config = ChatTemplate::from_gguf(gguf_path)?;
Self::from_parts(config, ContextMixins::default())
}
}
}
......
......@@ -3,12 +3,10 @@
//based on: https://github.com/EricLBuehler/mistral.rs/blob/d970bb5feb863acf8e8ec90de97e18221fb959f1/mistralrs-core/src/pipeline/chat_template.rs
use std::{collections::HashMap, fs::File, path::Path};
use std::collections::HashMap;
use chrono::{DateTime, Local};
use either::Either;
use ggus::{GGufMetaKV, GGufReader};
use memmap2::Mmap;
use minijinja::{Error, ErrorKind, Value, value::Kwargs};
use serde::{Deserialize, Serialize};
......@@ -82,74 +80,6 @@ pub struct ChatTemplate {
}
impl ChatTemplate {
pub fn from_gguf(path: &Path) -> anyhow::Result<Self> {
let file = match File::open(path) {
Ok(f) => unsafe { Mmap::map(&f)? },
Err(e) => {
anyhow::bail!("Failed to open file '{}': {e:?}", path.display());
}
};
let mut reader = GGufReader::new(&file);
let header = match reader.read_header() {
Ok(header) => header,
Err(e) => {
anyhow::bail!("Failed to read GGUF header of {}: {e:?}", path.display());
}
};
let num_metadata = header.metadata_kv_count;
let mut out = ChatTemplate::default();
// bos/eos/unk token conversion
fn convert(kv: GGufMetaKV) -> Option<BeginEndUnkTok> {
let id_string: String = kv.read_unsigned().to_string();
Some(BeginEndUnkTok(Either::Left(id_string)))
}
let mut num_found = 0;
let num_expected = 4; // How many fields we need
for _ in 0..num_metadata {
let kv = match reader.read_meta_kv() {
Ok(kv) => kv,
Err(err) => anyhow::bail!("read_meta_kv error in '{}': {err:?}", path.display()),
};
match kv.key() {
"tokenizer.ggml.bos_token_id" => {
out.bos_token = convert(kv);
num_found += 1;
}
"tokenizer.ggml.eos_token_id" => {
out.eos_token = convert(kv);
num_found += 1;
}
"tokenizer.ggml.unknown_token_id" => {
out.unk_token = convert(kv);
num_found += 1;
}
"tokenizer.chat_template" => {
out.chat_template = kv
.value_reader()
.read_str()
.ok()
.map(|s| ChatTemplateValue(Either::Left(s.to_string())));
num_found += 1;
}
_ => {}
}
if num_found == num_expected {
// No need to look at any more keys
break;
}
}
Ok(out)
}
// pub fn has_chat_template(&self) -> bool {
// self.chat_template.is_some()
// }
pub fn eos_tok(&self) -> Option<String> {
match self.eos_token.as_ref()?.0 {
Either::Left(ref lit) => Some(lit.clone()),
......
......@@ -30,7 +30,6 @@ async fn test_tokenizer_from_hf_like_local_repo() {
// Verify tokenizer file was found
match mdc.tokenizer.unwrap() {
TokenizerKind::HfTokenizerJson(_) => (),
TokenizerKind::GGUF(_) => (),
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment