Repository: ollama
Issue: fatal error: index out of range
Labels: bug

### What is the issue?

I'm running a dspy script that uses model `llama3-instruct:latest`.  Script starts properly but after some ~20 minutes I get an exception like this:

```
...
[GIN] 2024/12/02 - 01:05:51 | 404 |     476.079µs |       127.0.0.1 | POST     "/api/show"
fatal error: index out of range

runtime stack:
runtime.throw({0x12ed114?, 0x4026e8c0?})
        runtime/panic.go:1023 +0x5c fp=0x7f3e47ffea30 sp=0x7f3e47ffea00 pc=0x46f13c
runtime.panicCheck1(0xc000742c80?, {0x12ed114, 0x12})
        runtime/panic.go:58 +0x94 fp=0x7f3e47ffea50 sp=0x7f3e47ffea30 pc=0x46d094
runtime.goPanicIndex(0x832334, 0x60c7)
        runtime/panic.go:113 +0x2e fp=0x7f3e47ffea90 sp=0x7f3e47ffea50 pc=0x46d14e
runtime.findfunc(0x7f3e47ffeb60?)
        runtime/symtab.go:791 +0x119 fp=0x7f3e47ffeab0 sp=0x7f3e47ffea90 pc=0x48ebb9
runtime.(*unwinder).next(0x7f3e47ffeb60)
        runtime/traceback.go:449 +0x4c fp=0x7f3e47ffeb28 sp=0x7f3e47ffeab0 pc=0x495d8c
runtime.copystack(0xc000547880, 0x800000002?)
        runtime/stack.go:930 +0x2f4 fp=0x7f3e47ffec20 sp=0x7f3e47ffeb28 pc=0x48a174
runtime.newstack()
        runtime/stack.go:1112 +0x489 fp=0x7f3e47ffedd0 sp=0x7f3e47ffec20 pc=0x48a749
runtime.morestack()
        runtime/asm_amd64.s:616 +0x7a fp=0x7f3e47ffedd8 sp=0x7f3e47ffedd0 pc=0x4a30ba

goroutine 10797 gp=0xc000547880 m=8 mp=0xc000100808 [copystack]:
github.com/ollama/ollama/server.(*Server).GenerateHandler(0xc00071ea20, 0xc00061c100)
        github.com/ollama/ollama/server/routes.go:111 +0x22aa fp=0xc0004ed660 sp=0xc0004ed658 pc=0xf5500a
github.com/ollama/ollama/server.(*Server).GenerateHandler-fm(0x0?)
        <autogenerated>:1 +0x26 fp=0xc0004ed680 sp=0xc0004ed660 pc=0xf745a6
github.com/gin-gonic/gin.(*Context).Next(0xc00061c100)
        github.com/gin-gonic/gin@v1.10.0/context.go:185 +0x2b fp=0xc0004ed6a0 sp=0xc0004ed680 pc=0xf1736b
github.com/ollama/ollama/server.(*Server).GenerateRoutes.allowedHostsMiddleware.func3(0xc00061c100)
        github.com/ollama/ollama/server/routes.go:1087 +0x170 fp=0xc0004ed6f8 sp=0xc0004ed6a0 pc=0xf601b0
github.com/gin-gonic/gin.(*Context).Next(...)
        github.com/gin-gonic/gin@v1.10.0/context.go:185
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1(0xc00061c100)
        github.com/gin-gonic/gin@v1.10.0/recovery.go:102 +0x7a fp=0xc0004ed748 sp=0xc0004ed6f8 pc=0xf2533a
github.com/gin-gonic/gin.(*Context).Next(...)
        github.com/gin-gonic/gin@v1.10.0/context.go:185
github.com/gin-gonic/gin.LoggerWithConfig.func1(0xc00061c100)
        github.com/gin-gonic/gin@v1.10.0/logger.go:249 +0xe5 fp=0xc0004ed900 sp=0xc0004ed748 pc=0xf24465
github.com/gin-gonic/gin.(*Context).Next(...)
        github.com/gin-gonic/gin@v1.10.0/context.go:185
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc000742b60, 0xc00061c100)
        github.com/gin-gonic/gin@v1.10.0/gin.go:633 +0x892 fp=0xc0004edad8 sp=0xc0004ed900 pc=0xf23852
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc000742b60, {0x3fb0b428, 0xc0001920e0}, 0xc00059e000)
        github.com/gin-gonic/gin@v1.10.0/gin.go:589 +0x1b2 fp=0xc0004edb10 sp=0xc0004edad8 pc=0xf22df2
net/http.(*ServeMux).ServeHTTP(0x445305?, {0x3fb0b428, 0xc0001920e0}, 0xc00059e000)
        net/http/server.go:2688 +0x1ad fp=0xc0004edb60 sp=0xc0004edb10 pc=0x78f74d
net/http.serverHandler.ServeHTTP({0x3fb08890?}, {0x3fb0b428?, 0xc0001920e0?}, 0x6?)
        net/http/server.go:3142 +0x8e fp=0xc0004edb90 sp=0xc0004edb60 pc=0x790f4e
fatal error: index out of range
panic during panic

runtime stack:
runtime.throw({0x12ed114?, 0x7f3e47ffe2c0?})
        runtime/panic.go:1023 +0x5c fp=0x7f3e47ffe280 sp=0x7f3e47ffe250 pc=0x46f13c
runtime.panicCheck1(0x2?, {0x12ed114, 0x12})
        runtime/panic.go:58 +0x94 fp=0x7f3e47ffe2a0 sp=0x7f3e47ffe280 pc=0x46d094
runtime.goPanicIndex(0x832334, 0x60c7)
        runtime/panic.go:113 +0x2e fp=0x7f3e47ffe2e0 sp=0x7f3e47ffe2a0 pc=0x46d14e
runtime.findfunc(0x471674?)
        runtime/symtab.go:791 +0x119 fp=0x7f3e47ffe300 sp=0x7f3e47ffe2e0 pc=0x48ebb9
runtime.(*unwinder).next(0x7f3e47ffe6c8)
        runtime/traceback.go:449 +0x4c fp=0x7f3e47ffe378 sp=0x7f3e47ffe300 pc=0x495d8c
runtime.traceback2(0x7f3e47ffe6c8, 0x0, 0x0, 0x25)
        runtime/traceback.go:981 +0x125 fp=0x7f3e47ffe5d8 sp=0x7f3e47ffe378 pc=0x497745
runtime.traceback1.func1(0x0)
        runtime/traceback.go:917 +0x66 fp=0x7f3e47ffe6a0 sp=0x7f3e47ffe5d8 pc=0x4974e6
runtime.traceback1(0xc000547880?, 0x7f3e47ffe900?, 0x471674?, 0xc000547880, 0x80?)
        runtime/traceback.go:940 +0x20f fp=0x7f3e47ffe8a8 sp=0x7f3e47ffe6a0 pc=0x49734f
runtime.traceback(...)
        runtime/traceback.go:817
runtime.tracebackothers(0xc000102a80)
        runtime/traceback.go:1235 +0x92 fp=0x7f3e47ffe910 sp=0x7f3e47ffe8a8 pc=0x498c72
runtime.dopanic_m(0xc000102a80, 0x46f13c, 0x7f3e47ffea00)
        runtime/panic.go:1345 +0x29e fp=0x7f3e47ffe980 sp=0x7f3e47ffe910 pc=0x46fbfe
runtime.fatalthrow.func1()
        runtime/panic.go:1199 +0x6b fp=0x7f3e47ffe9c0 sp=0x7f3e47ffe980 pc=0x46f62b
runtime.fatalthrow(0x47ffea08?)
        runtime/panic.go:1192 +0x65 fp=0x7f3e47ffea00 sp=0x7f3e47ffe9c0 pc=0x46f585
runtime.throw({0x12ed114?, 0x4026e8c0?})
        runtime/panic.go:1023 +0x5c fp=0x7f3e47ffea30 sp=0x7f3e47ffea00 pc=0x46f13c
runtime.panicCheck1(0xc000742c80?, {0x12ed114, 0x12})
        runtime/panic.go:58 +0x94 fp=0x7f3e47ffea50 sp=0x7f3e47ffea30 pc=0x46d094
runtime.goPanicIndex(0x832334, 0x60c7)
        runtime/panic.go:113 +0x2e fp=0x7f3e47ffea90 sp=0x7f3e47ffea50 pc=0x46d14e
runtime.findfunc(0x7f3e47ffeb60?)
        runtime/symtab.go:791 +0x119 fp=0x7f3e47ffeab0 sp=0x7f3e47ffea90 pc=0x48ebb9
runtime.(*unwinder).next(0x7f3e47ffeb60)
        runtime/traceback.go:449 +0x4c fp=0x7f3e47ffeb28 sp=0x7f3e47ffeab0 pc=0x495d8c
runtime.copystack(0xc000547880, 0x800000002?)
        runtime/stack.go:930 +0x2f4 fp=0x7f3e47ffec20 sp=0x7f3e47ffeb28 pc=0x48a174
runtime.newstack()
        runtime/stack.go:1112 +0x489 fp=0x7f3e47ffedd0 sp=0x7f3e47ffec20 pc=0x48a749
runtime.morestack()
        runtime/asm_amd64.s:616 +0x7a fp=0x7f3e47ffedd8 sp=0x7f3e47ffedd0 pc=0x4a30ba
```

### OS

Linux

### GPU

Nvidia

### CPU

Intel

### Ollama version

0.3.12