Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

1.3 KB
Raw Blame
package mlx

import (
	"fmt"
	"testing"

	"github.com/ollama/ollama/mlx/mlxthread/mlxthreadtest"
)

func TestDepthwiseConvSiLUMatchesGraph(t *testing.T) {
	withMLXThread(t, func(t *mlxthreadtest.T) {
		for _, mismatch := range depthwiseConvSiLUMismatches() {
			t.Error(mismatch)
		}
	})
}

func depthwiseConvSiLUMismatches() []string {
	var mismatches []string
	for _, dtype := range []DType{DTypeBFloat16, DTypeFloat32} {
		for _, withBias := range []bool{false, true} {
			for _, shape := range []struct{ B, T, C, K int }{
				{1, 1, 64, 4},
				{1, 4, 64, 4},
				{1, 11, 96, 4},
				{1, 64, 64, 4},
				{1, 333, 64, 4},
				{3, 7, 64, 4},
				{2, 5, 32, 2},
			} {
				name := fmt.Sprintf("%v_bias%v_b%d_t%d_c%d_k%d", dtype, withBias, shape.B, shape.T, shape.C, shape.K)
				x := patternArray(dtype, []int{shape.B, shape.T + shape.K - 1, shape.C}, 0.02, 0.004, 41, 263)
				w := patternArray(dtype, []int{shape.C, shape.K}, 0.1, 0.01, 7, 53)
				var bias *Array
				if withBias {
					bias = patternArray(dtype, []int{shape.C}, -0.3, 0.02, 11, 37)
				}

				ref := SiLU(Conv1d(x, Reshape(w, int32(shape.C), int32(shape.K), 1), bias, 1, 0, 1, int32(shape.C)))
				y := DepthwiseConvSiLU(x, w, bias, shape.T)
				if err := requireExact("y", y, ref); err != nil {
					mismatches = append(mismatches, fmt.Sprintf("%s: %v", name, err))
				}
			}
		}
	}
	return mismatches
}