refactor: remove unstable Option<&T> branch by returning owned Tensor
This commit is contained in:
@@ -189,7 +189,7 @@ impl<'a> GenerateModel for Qwen2_5VLGenerateModel<'a> {
|
||||
decode_ids.extend_from_slice(&error_tokens);
|
||||
}
|
||||
decode_ids.push(next_token);
|
||||
let decoded_token = self.tokenizer.token_decode(decode_ids).map_err(|e| anyhow!(format!("stream decode error{}", e)))?;
|
||||
let decoded_token = self.tokenizer.token_decode(decode_ids).map_err(|e| anyhow!(format!("stream decode error{e}")))?;
|
||||
if decoded_token.contains("�") {
|
||||
error_tokens.push(next_token);
|
||||
if error_tokens.len() > 3 {
|
||||
|
||||
@@ -713,11 +713,11 @@ impl Qwen2_5VLTextModel {
|
||||
self.rope_scaling.mrope_section.clone(),
|
||||
)?;
|
||||
let mut xs = inputs_embeds.clone();
|
||||
let attention_mask: Option<&Tensor> = {
|
||||
let attention_mask: Option<Tensor> = {
|
||||
if seq_len <= 1 {
|
||||
None
|
||||
} else {
|
||||
Some(&prepare_causal_attention_mask(
|
||||
Some(prepare_causal_attention_mask(
|
||||
b_size,
|
||||
seq_len,
|
||||
0,
|
||||
@@ -726,7 +726,7 @@ impl Qwen2_5VLTextModel {
|
||||
}
|
||||
};
|
||||
for layer in self.layers.iter_mut() {
|
||||
xs = layer.forward(&xs, &cos, &sin, attention_mask)?;
|
||||
xs = layer.forward(&xs, &cos, &sin, attention_mask.as_ref())?;
|
||||
}
|
||||
let xs = xs.apply(&self.norm)?;
|
||||
Ok(xs)
|
||||
@@ -898,7 +898,7 @@ impl Qwen2_5VLModel {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("get vision_indices err: {}", e);
|
||||
println!("get vision_indices err: {e}");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ impl Qwen2_5VLProcessor {
|
||||
let image = get_image(file);
|
||||
match image {
|
||||
Ok(img) => file_vec.push(img),
|
||||
Err(e) => println!("get_image err: {:?}", e),
|
||||
Err(e) => println!("get_image err: {e:?}"),
|
||||
};
|
||||
}
|
||||
if !file_vec.is_empty() {
|
||||
@@ -253,7 +253,7 @@ impl Qwen2_5VLProcessor {
|
||||
pixel_values = Some(img_input.data);
|
||||
image_grid_thw = Some(img_input.grid_thw);
|
||||
}
|
||||
Err(e) => println!("img process_images err: {:?}", e),
|
||||
Err(e) => println!("img process_images err: {e:?}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user