Skip to content

Commit bdd6769

Browse files
authored
feat(default): use number of physical cores as default (#2483)
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 1ffee99 commit bdd6769

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

core/cli/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type RunCMD struct {
3737
PreloadModelsConfig string `env:"LOCALAI_PRELOAD_MODELS_CONFIG,PRELOAD_MODELS_CONFIG" help:"A List of models to apply at startup. Path to a YAML config file" group:"models"`
3838

3939
F16 bool `name:"f16" env:"LOCALAI_F16,F16" help:"Enable GPU acceleration" group:"performance"`
40-
Threads int `env:"LOCALAI_THREADS,THREADS" short:"t" default:"4" help:"Number of threads used for parallel computation. Usage of the number of physical cores in the system is suggested" group:"performance"`
40+
Threads int `env:"LOCALAI_THREADS,THREADS" short:"t" help:"Number of threads used for parallel computation. Usage of the number of physical cores in the system is suggested" group:"performance"`
4141
ContextSize int `env:"LOCALAI_CONTEXT_SIZE,CONTEXT_SIZE" default:"512" help:"Default context size for models" group:"performance"`
4242

4343
Address string `env:"LOCALAI_ADDRESS,ADDRESS" default:":8080" help:"Bind address for the API server" group:"api"`

core/config/application_config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/go-skynet/LocalAI/pkg/gallery"
10+
"github.com/go-skynet/LocalAI/pkg/xsysinfo"
1011
"github.com/rs/zerolog/log"
1112
)
1213

@@ -59,7 +60,6 @@ func NewApplicationConfig(o ...AppOption) *ApplicationConfig {
5960
opt := &ApplicationConfig{
6061
Context: context.Background(),
6162
UploadLimitMB: 15,
62-
Threads: 1,
6363
ContextSize: 512,
6464
Debug: true,
6565
}
@@ -213,6 +213,9 @@ func WithUploadLimitMB(limit int) AppOption {
213213

214214
func WithThreads(threads int) AppOption {
215215
return func(o *ApplicationConfig) {
216+
if threads == 0 { // 0 is not allowed
217+
threads = xsysinfo.CPUPhysicalCores()
218+
}
216219
o.Threads = threads
217220
}
218221
}

pkg/xsysinfo/cpu.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ func CPUCapabilities() ([]string, error) {
3636
func HasCPUCaps(ids ...cpuid.FeatureID) bool {
3737
return cpuid.CPU.Supports(ids...)
3838
}
39+
40+
func CPUPhysicalCores() int {
41+
if cpuid.CPU.PhysicalCores == 0 {
42+
return 1
43+
}
44+
return cpuid.CPU.PhysicalCores
45+
}

0 commit comments

Comments
 (0)