mirror of
https://github.com/ollama/ollama.git
synced 2026-05-13 14:27:00 +00:00
ggml: Automatically make tensors contiguous on reshape
GGML requires tensors to be contiguous for reshape and if this is not the case, it will assert fail. Contiguous is an expensive operation, so it's best to do it lazily when it is actually required rather than ahead of time when it may not be needed.
This commit is contained in:
parent
91935631ac
commit
b6e02cbbd2
1 changed files with 4 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue