fix: usize overflow issue in ctranslate2 max_length truncation
parent
3af32c8c7c
commit
1e7ecce697
|
|
@ -136,8 +136,12 @@ impl TextGeneration for CTranslate2Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn truncate_tokens(tokens: &[String], max_length: usize) -> &[String] {
|
fn truncate_tokens(tokens: &[String], max_length: usize) -> &[String] {
|
||||||
let start = std::cmp::max(tokens.len() - max_length, 0);
|
if max_length < tokens.len() {
|
||||||
|
let start = tokens.len() - max_length;
|
||||||
&tokens[start..]
|
&tokens[start..]
|
||||||
|
} else {
|
||||||
|
tokens
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn inference_callback(
|
fn inference_callback(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue