Skip to content

Commit 4f255b5

Browse files
authored
Fewer .contiguous calls for qwen3 moe (#1391)
1 parent 698a943 commit 4f255b5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

mistralrs-core/src/models/qwen3_moe.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl FastMoeMlp {
426426
0,
427427
self.num_experts_per_tok,
428428
)?;
429-
let mut scores = routing_weights.gather(&indices.contiguous()?, D::Minus1)?;
429+
let mut scores = routing_weights.gather(&indices, D::Minus1)?;
430430

431431
if self.norm_topk_prob {
432432
scores = scores.broadcast_div(&scores.sum_keepdim(D::Minus1)?)?;
@@ -436,14 +436,11 @@ impl FastMoeMlp {
436436
let xs = xs.reshape((b_size, seq_len, 1, 1, hidden_dim))?;
437437
let gate = self
438438
.fused_gate_proj
439-
.gather_forward_autocast(&xs.contiguous()?, &indices.contiguous()?)?;
440-
let up = self
441-
.fused_up_proj
442-
.gather_forward_autocast(&xs.contiguous()?, &indices.contiguous()?)?;
443-
let xs = self.fused_down_proj.gather_forward_autocast(
444-
&(up * gate.apply(&self.act)?)?.contiguous()?,
445-
&indices.contiguous()?,
446-
)?;
439+
.gather_forward_autocast(&xs, &indices)?;
440+
let up = self.fused_up_proj.gather_forward_autocast(&xs, &indices)?;
441+
let xs = self
442+
.fused_down_proj
443+
.gather_forward_autocast(&(up * gate.apply(&self.act)?)?, &indices)?;
447444
xs.squeeze(D::Minus2)?
448445
};
449446

0 commit comments

Comments
 (0)