Skip to content

Fixing metal backend. #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions backends/candle/src/models/qwen3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,17 @@ impl Qwen3Model {
.flat_map(|i| (0..seq_len).map(move |j| (j > i) as u8))
.collect();

let causal_mask = Tensor::from_slice(&mask, (seq_len, seq_len), &Device::Cpu)?;
let device = attention_bias.device();
let causal_mask = Tensor::from_slice(&mask, (seq_len, seq_len), device)?;
let causal_mask = causal_mask.expand(&[bs, dim, seq_len, seq_len])?;

let negatives =
Tensor::full(f32::MIN, attention_bias.shape(), &Device::Cpu)?.to_dtype(self.dtype)?;
Tensor::full(f32::MIN, attention_bias.shape(), device)?.to_dtype(self.dtype)?;
let zeros = Tensor::zeros_like(&attention_bias)?.to_dtype(self.dtype)?;

let causal_mask = causal_mask
.where_cond(&negatives, &zeros)?
.to_device(&self.device)?;
.to_device(device)?;

attention_bias.broadcast_add(&causal_mask)
}
Expand Down
Loading