check memory requirements before loading

This commit is contained in:
Michael Yang
2023-08-03 15:47:36 -07:00
parent 020a3b3530
commit d791df75dd
3 changed files with 25 additions and 0 deletions

View File

@ -5,6 +5,8 @@ import (
"log"
"os"
"github.com/pbnjay/memory"
"github.com/jmorganca/ollama/api"
)
@ -42,6 +44,26 @@ func New(model string, opts api.Options) (LLM, error) {
}
}
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 {
case ModelFamilyLlama:
return newLlama(model, opts)