Skip to content
Merged
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
52 changes: 28 additions & 24 deletions mistralrs-core/src/pipeline/chat_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,33 @@ pub fn calculate_eos_tokens(
}

if let Some(gen_conf) = gen_conf {
let ids = match gen_conf.eos_token_id {
Either::Left(id) => vec![id],
Either::Right(ids) => ids,
};
for id in ids {
let s = tokenizer
.decode(&[id], false)
.unwrap_or_else(|_| panic!("Unable to decode id {id})"));
if !eos_tok_ids.contains(&s) {
eos_tok_ids.push(s);
if let Some(eos_field) = gen_conf.eos_token_id {
let ids = match eos_field {
Either::Left(id) => vec![id],
Either::Right(ids) => ids,
};
for id in ids {
let s = tokenizer
.decode(&[id], false)
.unwrap_or_else(|_| panic!("Unable to decode id {id})"));
if !eos_tok_ids.contains(&s) {
eos_tok_ids.push(s);
}
}
}

let ids = match gen_conf.bos_token_id {
Either::Left(id) => vec![id],
Either::Right(ids) => ids,
};
for id in ids {
let s = tokenizer
.decode(&[id], false)
.unwrap_or_else(|_| panic!("Unable to decode id {id})"));
if !bos_tok_ids.contains(&s) {
bos_tok_ids.push(s);
if let Some(bos_field) = gen_conf.bos_token_id {
let ids = match bos_field {
Either::Left(id) => vec![id],
Either::Right(ids) => ids,
};
for id in ids {
let s = tokenizer
.decode(&[id], false)
.unwrap_or_else(|_| panic!("Unable to decode id {id})"));
if !bos_tok_ids.contains(&s) {
bos_tok_ids.push(s);
}
}
}
}
Expand Down Expand Up @@ -176,10 +180,10 @@ pub fn calculate_eos_tokens(
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
pub struct GenerationConfig {
#[serde(with = "either::serde_untagged")]
bos_token_id: Either<u32, Vec<u32>>,
#[serde(with = "either::serde_untagged")]
eos_token_id: Either<u32, Vec<u32>>,
#[serde(with = "either::serde_untagged_optional")]
bos_token_id: Option<Either<u32, Vec<u32>>>,
#[serde(with = "either::serde_untagged_optional")]
eos_token_id: Option<Either<u32, Vec<u32>>>,
}

fn tojson(value: Value, kwargs: Kwargs) -> Result<Value, Error> {
Expand Down
7 changes: 3 additions & 4 deletions mistralrs-core/src/pipeline/ggml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,9 @@ impl Loader for GGMLLoader {
};

let tokenizer = get_tokenizer(paths.get_tokenizer_filename(), None)?;
let gen_conf: Option<GenerationConfig> = paths.get_gen_conf_filename().map(|f| {
serde_json::from_str(&fs::read_to_string(f).unwrap())
.expect("bos_token_id/eos_token_id missing in generation_config.json")
});
let gen_conf: Option<GenerationConfig> = paths
.get_gen_conf_filename()
.map(|f| serde_json::from_str(&fs::read_to_string(f).unwrap()).unwrap());
let chat_template_explicit = paths
.get_chat_template_explicit()
.as_ref()
Expand Down
7 changes: 3 additions & 4 deletions mistralrs-core/src/pipeline/gguf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,9 @@ impl Loader for GGUFLoader {
(None, None)
};

let gen_conf: Option<GenerationConfig> = paths.get_gen_conf_filename().map(|f| {
serde_json::from_str(&fs::read_to_string(f).unwrap())
.expect("bos_token_id/eos_token_id missing in generation_config.json")
});
let gen_conf: Option<GenerationConfig> = paths
.get_gen_conf_filename()
.map(|f| serde_json::from_str(&fs::read_to_string(f).unwrap()).unwrap());
let chat_template_explicit = paths
.get_chat_template_explicit()
.as_ref()
Expand Down
7 changes: 3 additions & 4 deletions mistralrs-core/src/pipeline/vision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,9 @@ impl Loader for VisionLoader {
Some(processor.get_special_tokens()),
)?;

let gen_conf: Option<GenerationConfig> = paths.get_gen_conf_filename().map(|f| {
serde_json::from_str(&fs::read_to_string(f).unwrap())
.expect("bos_token_id/eos_token_id missing in generation_config.json")
});
let gen_conf: Option<GenerationConfig> = paths
.get_gen_conf_filename()
.map(|f| serde_json::from_str(&fs::read_to_string(f).unwrap()).unwrap());
let chat_template_explicit = paths
.get_chat_template_explicit()
.as_ref()
Expand Down
Loading