diff --git a/src/models/common/mod.rs b/src/models/common/mod.rs index cb05fa2..e596cf2 100644 --- a/src/models/common/mod.rs +++ b/src/models/common/mod.rs @@ -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)?; diff --git a/src/models/minicpm4/model.rs b/src/models/minicpm4/model.rs index eebfa14..a2adbc1 100644 --- a/src/models/minicpm4/model.rs +++ b/src/models/minicpm4/model.rs @@ -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(), )?) } diff --git a/src/models/voxcpm/generate.rs b/src/models/voxcpm/generate.rs index 384886d..41403eb 100644 --- a/src/models/voxcpm/generate.rs +++ b/src/models/voxcpm/generate.rs @@ -130,7 +130,7 @@ impl VoxCPMGenerate { Ok(audio) } pub fn generate_simple(&mut self, target_text: String) -> Result { - 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( diff --git a/src/models/voxcpm/minicpm4.rs b/src/models/voxcpm/minicpm4.rs index 666b10a..aeb2630 100644 --- a/src/models/voxcpm/minicpm4.rs +++ b/src/models/voxcpm/minicpm4.rs @@ -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(), )?) } diff --git a/src/utils/tensor_utils.rs b/src/utils/tensor_utils.rs index c7b9b1a..7768fbd 100644 --- a/src/utils/tensor_utils.rs +++ b/src/utils/tensor_utils.rs @@ -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) } diff --git a/tests/test_minicpm4.rs b/tests/test_minicpm4.rs index 836d17a..dda7ce3 100644 --- a/tests/test_minicpm4.rs +++ b/tests/test_minicpm4.rs @@ -21,7 +21,7 @@ fn minicpm_generate() -> Result<()> { "messages": [ { "role": "user", - "content": "你好啊,你是谁" + "content": "你吃饭了没" } ] } diff --git a/voxcpm.wav b/voxcpm.wav new file mode 100644 index 0000000..38465fa Binary files /dev/null and b/voxcpm.wav differ