2023-07-14 23:19:43 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
2023-08-18 23:49:33 +00:00
|
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
2023-07-14 23:19:43 +00:00
|
|
|
|
|
|
|
config "github.com/go-skynet/LocalAI/api/config"
|
2023-08-18 23:49:33 +00:00
|
|
|
"github.com/go-skynet/LocalAI/api/options"
|
2023-07-14 23:19:43 +00:00
|
|
|
)
|
|
|
|
|
2023-08-18 23:49:33 +00:00
|
|
|
func modelOpts(c config.Config, o *options.Option, opts []model.Option) []model.Option {
|
|
|
|
if o.SingleBackend {
|
|
|
|
opts = append(opts, model.WithSingleActiveBackend())
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.GRPC.Attempts != 0 {
|
|
|
|
opts = append(opts, model.WithGRPCAttempts(c.GRPC.Attempts))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.GRPC.AttemptsSleepTime != 0 {
|
|
|
|
opts = append(opts, model.WithGRPCAttemptsDelay(c.GRPC.AttemptsSleepTime))
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v := range o.ExternalGRPCBackends {
|
|
|
|
opts = append(opts, model.WithExternalBackend(k, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
2023-07-14 23:19:43 +00:00
|
|
|
func gRPCModelOpts(c config.Config) *pb.ModelOptions {
|
|
|
|
b := 512
|
|
|
|
if c.Batch != 0 {
|
|
|
|
b = c.Batch
|
|
|
|
}
|
2023-08-09 06:38:51 +00:00
|
|
|
|
2023-08-15 23:11:42 +00:00
|
|
|
return &pb.ModelOptions{
|
|
|
|
ContextSize: int32(c.ContextSize),
|
|
|
|
Seed: int32(c.Seed),
|
|
|
|
NBatch: int32(b),
|
2023-08-25 19:58:46 +00:00
|
|
|
NoMulMatQ: c.NoMulMatQ,
|
2023-09-14 15:44:16 +00:00
|
|
|
DraftModel: c.DraftModel,
|
2023-09-04 17:25:23 +00:00
|
|
|
AudioPath: c.VallE.AudioPath,
|
2023-09-22 13:52:38 +00:00
|
|
|
Quantization: c.Quantization,
|
2023-08-25 19:58:46 +00:00
|
|
|
LoraAdapter: c.LoraAdapter,
|
|
|
|
LoraBase: c.LoraBase,
|
2023-08-15 23:11:42 +00:00
|
|
|
NGQA: c.NGQA,
|
2023-08-09 06:38:51 +00:00
|
|
|
RMSNormEps: c.RMSNormEps,
|
|
|
|
F16Memory: c.F16,
|
|
|
|
MLock: c.MMlock,
|
|
|
|
RopeFreqBase: c.RopeFreqBase,
|
|
|
|
RopeFreqScale: c.RopeFreqScale,
|
|
|
|
NUMA: c.NUMA,
|
|
|
|
Embeddings: c.Embeddings,
|
|
|
|
LowVRAM: c.LowVRAM,
|
|
|
|
NGPULayers: int32(c.NGPULayers),
|
|
|
|
MMap: c.MMap,
|
|
|
|
MainGPU: c.MainGPU,
|
|
|
|
Threads: int32(c.Threads),
|
|
|
|
TensorSplit: c.TensorSplit,
|
|
|
|
// AutoGPTQ
|
|
|
|
ModelBaseName: c.AutoGPTQ.ModelBaseName,
|
|
|
|
Device: c.AutoGPTQ.Device,
|
|
|
|
UseTriton: c.AutoGPTQ.Triton,
|
|
|
|
UseFastTokenizer: c.AutoGPTQ.UseFastTokenizer,
|
2023-08-22 16:48:06 +00:00
|
|
|
// RWKV
|
|
|
|
Tokenizer: c.Tokenizer,
|
2023-07-14 23:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func gRPCPredictOpts(c config.Config, modelPath string) *pb.PredictOptions {
|
|
|
|
promptCachePath := ""
|
|
|
|
if c.PromptCachePath != "" {
|
|
|
|
p := filepath.Join(modelPath, c.PromptCachePath)
|
|
|
|
os.MkdirAll(filepath.Dir(p), 0755)
|
|
|
|
promptCachePath = p
|
|
|
|
}
|
|
|
|
return &pb.PredictOptions{
|
2023-07-25 17:05:27 +00:00
|
|
|
Temperature: float32(c.Temperature),
|
|
|
|
TopP: float32(c.TopP),
|
2023-09-14 15:44:16 +00:00
|
|
|
NDraft: c.NDraft,
|
2023-07-25 17:05:27 +00:00
|
|
|
TopK: int32(c.TopK),
|
|
|
|
Tokens: int32(c.Maxtokens),
|
|
|
|
Threads: int32(c.Threads),
|
|
|
|
PromptCacheAll: c.PromptCacheAll,
|
|
|
|
PromptCacheRO: c.PromptCacheRO,
|
|
|
|
PromptCachePath: promptCachePath,
|
|
|
|
F16KV: c.F16,
|
|
|
|
DebugMode: c.Debug,
|
|
|
|
Grammar: c.Grammar,
|
|
|
|
NegativePromptScale: c.NegativePromptScale,
|
|
|
|
RopeFreqBase: c.RopeFreqBase,
|
|
|
|
RopeFreqScale: c.RopeFreqScale,
|
|
|
|
NegativePrompt: c.NegativePrompt,
|
2023-08-09 06:38:51 +00:00
|
|
|
Mirostat: int32(c.LLMConfig.Mirostat),
|
|
|
|
MirostatETA: float32(c.LLMConfig.MirostatETA),
|
|
|
|
MirostatTAU: float32(c.LLMConfig.MirostatTAU),
|
2023-07-25 17:05:27 +00:00
|
|
|
Debug: c.Debug,
|
|
|
|
StopPrompts: c.StopWords,
|
|
|
|
Repeat: int32(c.RepeatPenalty),
|
|
|
|
NKeep: int32(c.Keep),
|
|
|
|
Batch: int32(c.Batch),
|
|
|
|
IgnoreEOS: c.IgnoreEOS,
|
|
|
|
Seed: int32(c.Seed),
|
|
|
|
FrequencyPenalty: float32(c.FrequencyPenalty),
|
|
|
|
MLock: c.MMlock,
|
|
|
|
MMap: c.MMap,
|
|
|
|
MainGPU: c.MainGPU,
|
|
|
|
TensorSplit: c.TensorSplit,
|
|
|
|
TailFreeSamplingZ: float32(c.TFZ),
|
|
|
|
TypicalP: float32(c.TypicalP),
|
2023-07-14 23:19:43 +00:00
|
|
|
}
|
|
|
|
}
|