Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
qwen3next: avoid inplace sigmoid for shared gate (#14077)
Jeffrey Morgand25535c3f3d5
diff --git a/ml/backend.go b/ml/backend.goindex 7db8acc97..4e63d3399 100644--- a/ml/backend.go+++ b/ml/backend.go@@ -175,6 +175,7 @@ type Tensor interface {SILU(ctx Context, up ...Tensor) TensorRELU(ctx Context, up ...Tensor) TensorSigmoid(ctx Context) Tensor+ SigmoidOut(ctx Context) Tensor// AlphaLimitSILU is a variant of SILU that clamps the input to the range [-limit, limit]SILUAlphaLimit(ctx Context, up Tensor, alpha, limit float32) Tensordiff --git a/ml/backend/ggml/ggml.go b/ml/backend/ggml/ggml.goindex ee4e93197..b2f96c761 100644--- a/ml/backend/ggml/ggml.go+++ b/ml/backend/ggml/ggml.go@@ -1468,6 +1468,13 @@ func (t *Tensor) Sigmoid(ctx ml.Context) ml.Tensor {}}+func (t *Tensor) SigmoidOut(ctx ml.Context) ml.Tensor {+ return &Tensor{+ b: t.b,+ t: C.ggml_sigmoid(ctx.(*Context).ctx, t.t),+ }+}+func (t *Tensor) View(ctx ml.Context, offset int, shape ...int) ml.Tensor {switch len(shape) {case 1:diff --git a/model/models/qwen3next/model.go b/model/models/qwen3next/model.goindex 4ee4eebc8..eeec43f59 100644--- a/model/models/qwen3next/model.go+++ b/model/models/qwen3next/model.go@@ -135,7 +135,7 @@ func (mlp *sparse) Forward(ctx ml.Context, hiddenStates ml.Tensor, opts *Options// Apply shared expert gatingif mlp.SharedGateInp != nil {sharedGateVal := mlp.SharedGateInp.Forward(ctx, hiddenStates2D)- sharedGateVal = sharedGateVal.Sigmoid(ctx)+ sharedGateVal = sharedGateVal.SigmoidOut(ctx)// Broadcast gate to match dimensionssharedGateVal = sharedGateVal.Repeat(ctx, 0, sharedOut.Dim(0))sharedOut = sharedOut.Mul(ctx, sharedGateVal)