fix mask bug

This commit is contained in:
jhqxxx
2025-10-11 13:14:51 +08:00
parent dcdafaf8ac
commit c8cfda7ac4
7 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ impl AttentionNobias {
let attn_weights = (attn_weights * scale)?;
let attn_weights = match attention_mask {
None => attn_weights,
Some(mask) => attn_weights.broadcast_add(mask)?,
Some(mask) => attn_weights.broadcast_add(&mask.to_dtype(attn_weights.dtype())?)?,
};
let attn_weights = candle_nn::ops::softmax_last_dim(&attn_weights)?;
let attn_weights = attn_weights.matmul(&value_states)?;
+2 -2
View File
@@ -233,7 +233,7 @@ impl MiniCPMModel {
Some(&prepare_causal_attention_mask(
bs,
seq_len,
position_id,
0,
input_ids.device(),
)?)
}
@@ -267,7 +267,7 @@ impl MiniCPMModel {
Some(&prepare_causal_attention_mask(
bs,
seq_len,
position_id,
0,
input_ids.device(),
)?)
}
+1 -1
View File
@@ -130,7 +130,7 @@ impl VoxCPMGenerate {
Ok(audio)
}
pub fn generate_simple(&mut self, target_text: String) -> Result<Tensor> {
let audio = self.generate(target_text, None, None, 2, 1000, 10, 2.0, false, 6.0)?;
let audio = self.generate(target_text, None, None, 2, 100, 10, 2.0, false, 6.0)?;
Ok(audio)
}
pub fn generate(
+2 -2
View File
@@ -266,7 +266,7 @@ impl MiniCPMModel {
Some(&prepare_causal_attention_mask(
bs,
seq_len,
position_id,
0,
input_embeds.device(),
)?)
}
@@ -294,7 +294,7 @@ impl MiniCPMModel {
Some(&prepare_causal_attention_mask(
bs,
seq_len,
position_id,
0,
input_embeds.device(),
)?)
}
+2 -2
View File
@@ -21,14 +21,14 @@ pub fn prepare_causal_attention_mask(
.collect();
let mask = Tensor::from_slice(&mask, (tgt_len, tgt_len), device)?;
let mask = if seqlen_offset > 0 {
let mask0 = Tensor::zeros((tgt_len, seqlen_offset), DType::U32, device)?;
let mask0 = Tensor::zeros((tgt_len, seqlen_offset), DType::F32, device)?;
Tensor::cat(&[&mask0, &mask], D::Minus1)?
} else {
mask
};
let mask = mask
.expand((b_size, 1, tgt_len, tgt_len + seqlen_offset))?
.to_dtype(DType::U32)?;
.to_dtype(DType::F32)?;
Ok(mask)
}
+1 -1
View File
@@ -21,7 +21,7 @@ fn minicpm_generate() -> Result<()> {
"messages": [
{
"role": "user",
"content": "你好啊,你是谁"
"content": "你吃饭了没"
}
]
}
BIN
View File
Binary file not shown.