|
@@ -2,8 +2,11 @@ package llm
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "log"
|
|
"os"
|
|
"os"
|
|
|
|
|
|
|
|
+ "github.com/pbnjay/memory"
|
|
|
|
+
|
|
"github.com/jmorganca/ollama/api"
|
|
"github.com/jmorganca/ollama/api"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -31,6 +34,36 @@ func New(model string, opts api.Options) (LLM, error) {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ switch ggml.FileType {
|
|
|
|
+ case FileTypeF32, FileTypeF16, FileTypeQ5_0, FileTypeQ5_1, FileTypeQ8_0:
|
|
|
|
+ if opts.NumGPU != 0 {
|
|
|
|
+ // Q5_0, Q5_1, and Q8_0 do not support Metal API and will
|
|
|
|
+ // cause the runner to segmentation fault so disable GPU
|
|
|
|
+ log.Printf("WARNING: GPU disabled for F32, F16, Q5_0, Q5_1, and Q8_0")
|
|
|
|
+ opts.NumGPU = 0
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ totalResidentMemory := memory.TotalMemory()
|
|
|
|
+ switch ggml.ModelType {
|
|
|
|
+ case ModelType3B, ModelType7B:
|
|
|
|
+ if totalResidentMemory < 8*1024*1024 {
|
|
|
|
+ return nil, fmt.Errorf("model requires at least 8GB of memory")
|
|
|
|
+ }
|
|
|
|
+ case ModelType13B:
|
|
|
|
+ if totalResidentMemory < 16*1024*1024 {
|
|
|
|
+ return nil, fmt.Errorf("model requires at least 16GB of memory")
|
|
|
|
+ }
|
|
|
|
+ case ModelType30B:
|
|
|
|
+ if totalResidentMemory < 32*1024*1024 {
|
|
|
|
+ return nil, fmt.Errorf("model requires at least 32GB of memory")
|
|
|
|
+ }
|
|
|
|
+ case ModelType65B:
|
|
|
|
+ if totalResidentMemory < 64*1024*1024 {
|
|
|
|
+ return nil, fmt.Errorf("model requires at least 64GB of memory")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
switch ggml.ModelFamily {
|
|
switch ggml.ModelFamily {
|
|
case ModelFamilyLlama:
|
|
case ModelFamilyLlama:
|
|
return newLlama(model, opts)
|
|
return newLlama(model, opts)
|