Skip to content

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

ggml: Automatically make tensors contiguous on reshape

Jesse Grossb6e02cbbd280
diff --git a/ml/backend/ggml/ggml.go b/ml/backend/ggml/ggml.go
index 1d457fc4f..8d0415cfa 100644
--- a/ml/backend/ggml/ggml.go
+++ b/ml/backend/ggml/ggml.go
@@ -1378,6 +1378,10 @@ func inferShape(t *Tensor, shape []int) {
}
func (t *Tensor) Reshape(ctx ml.Context, shape ...int) ml.Tensor {
+ if !C.ggml_is_contiguous(t.t) {
+ return t.Contiguous(ctx, shape...)
+ }
+
if slices.Contains(shape, -1) {
inferShape(t, shape)
}