runner.go: Better handle return NULL values from llama.cpp

Llama.cpp sometimes returns NULL as a return value to report an
error. We should explicitly check for this and convert it to a Go
error rather than putting NULL in our data structures and waiting
for it to blow up later.
This commit is contained in:
Jesse Gross
2024-10-22 14:57:46 -07:00
committed by Jesse Gross
parent 084929c293
commit de1557a0dc
3 changed files with 37 additions and 13 deletions

View File

@@ -790,10 +790,17 @@ func (s *Server) loadModel(
) {
llama.BackendInit()
s.model = llama.LoadModelFromFile(mpath, params)
var err error
s.model, err = llama.LoadModelFromFile(mpath, params)
if err != nil {
panic(err)
}
ctxParams := llama.NewContextParams(kvSize, s.batchSize*s.parallel, s.parallel, threads, flashAttention)
s.lc = llama.NewContextWithModel(s.model, ctxParams)
s.lc, err = llama.NewContextWithModel(s.model, ctxParams)
if err != nil {
panic(err)
}
if lpath != "" {
err := s.model.ApplyLoraFromFile(s.lc, lpath, 1.0, threads)