Fixes SIGSEGV: segmentation violation running gemma3 models on ollama 0.6.0 #21

Patch provided by McBane87 on https://github.com/whyvl/ollama-vulkan/issues/21

Signed-off-by: Vadim Grinco <vadim@grinco.eu>
This commit is contained in:
Vadim Grinco 2025-03-15 20:28:57 +01:00
parent d0afc677db
commit d1939aa1c6
1 changed files with 4 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import (
"strings"
"unicode"
"unsafe"
"sync"
"github.com/ollama/ollama/format"
fs "github.com/ollama/ollama/fs/ggml"
@ -299,6 +300,7 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
// concurrently read in tensor data. uses a section reader which is safe for concurrent reads
sr := io.NewSectionReader(r, int64(meta.Tensors().Offset), n-int64(meta.Tensors().Offset))
var tensorSetMutex sync.Mutex
var g errgroup.Group
for _, t := range meta.Tensors().Items() {
for _, target := range targets[t.Name] {
@ -322,7 +324,9 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
return errors.New("short read")
}
tensorSetMutex.Lock()
C.ggml_backend_tensor_set(tt, unsafe.Pointer(&bts[0]), 0, C.size_t(t.Size()))
tensorSetMutex.Unlock()
return nil
})
}