refactor: remove unstable Option<&T> branch by returning owned Tensor

This commit is contained in:
YageGeng
2025-12-11 10:50:35 +08:00
parent 0dc2840b0e
commit 42c95da0e3
16 changed files with 64 additions and 60 deletions
+1 -1
View File
@@ -183,7 +183,7 @@ impl<'a> GenerateModel for HunyuanOCRGenerateModel<'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 {
+4 -13
View File
@@ -482,20 +482,11 @@ impl HunYuanVLTextModel {
) -> Result<Tensor> {
let (b_size, seq_len, _) = inputs_embeds.dims3()?;
// let position_ids = match position_ids {
// Some(ids) => ids.clone(),
// None => Tensor::arange(
// seqlen_offset as u32,
// (seq_len + seqlen_offset) as u32,
// inputs_embeds.device(),
// )?
// .unsqueeze(0)?,
// };
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,
@@ -514,9 +505,9 @@ impl HunYuanVLTextModel {
{
let (cos, sin) =
get_xd_cos_sin(&cos, &sin, position_ids, self.xdrope_section.clone())?;
xs = layer.forward(&xs, &cos, &sin, attention_mask)?;
xs = layer.forward(&xs, &cos, &sin, attention_mask.as_ref())?;
} else {
xs = layer.forward(&xs, &cos, &sin, attention_mask)?;
xs = layer.forward(&xs, &cos, &sin, attention_mask.as_ref())?;
}
}
let xs = self.norm.forward(&xs)?;