From 7aed455afcbc375adafbdcd565cb3be215cfa8cd Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Fri, 21 Jun 2024 10:10:42 +0200 Subject: [PATCH] fix(worker): use dynaload for single binaries Signed-off-by: Ettore Di Giacinto --- core/cli/worker/worker_llamacpp.go | 24 +++++++++++++----------- core/cli/worker/worker_p2p.go | 20 +++++++++++++------- pkg/library/dynaload.go | 2 +- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/core/cli/worker/worker_llamacpp.go b/core/cli/worker/worker_llamacpp.go index 7a68a44823da..4b6e06e85134 100644 --- a/core/cli/worker/worker_llamacpp.go +++ b/core/cli/worker/worker_llamacpp.go @@ -7,6 +7,7 @@ import ( cliContext "github.com/go-skynet/LocalAI/core/cli/context" "github.com/go-skynet/LocalAI/pkg/assets" + "github.com/go-skynet/LocalAI/pkg/library" "github.com/rs/zerolog/log" ) @@ -27,17 +28,18 @@ func (r *LLamaCPP) Run(ctx *cliContext.Context) error { return fmt.Errorf("usage: local-ai worker llama-cpp-rpc -- ") } + grpcProcess := assets.ResolvePath( + r.BackendAssetsPath, + "util", + "llama-cpp-rpc-server", + ) + + args := os.Args[4:] + args, grpcProcess = library.LoadLDSO(r.BackendAssetsPath, args, grpcProcess) + + args = append([]string{grpcProcess}, args...) return syscall.Exec( - assets.ResolvePath( - r.BackendAssetsPath, - "util", - "llama-cpp-rpc-server", - ), - append([]string{ - assets.ResolvePath( - r.BackendAssetsPath, - "util", - "llama-cpp-rpc-server", - )}, os.Args[4:]...), + grpcProcess, + args, os.Environ()) } diff --git a/core/cli/worker/worker_p2p.go b/core/cli/worker/worker_p2p.go index 02a3c3131414..f185abcb3547 100644 --- a/core/cli/worker/worker_p2p.go +++ b/core/cli/worker/worker_p2p.go @@ -13,6 +13,7 @@ import ( cliContext "github.com/go-skynet/LocalAI/core/cli/context" "github.com/go-skynet/LocalAI/core/p2p" "github.com/go-skynet/LocalAI/pkg/assets" + "github.com/go-skynet/LocalAI/pkg/library" "github.com/phayes/freeport" "github.com/rs/zerolog/log" ) @@ -71,13 +72,18 @@ func (r *P2P) Run(ctx *cliContext.Context) error { go func() { for { log.Info().Msgf("Starting llama-cpp-rpc-server on '%s:%d'", address, port) + + grpcProcess := assets.ResolvePath( + r.BackendAssetsPath, + "util", + "llama-cpp-rpc-server", + ) + + args := append([]string{"--host", address, "--port", fmt.Sprint(port)}, r.ExtraLLamaCPPArgs...) + args, grpcProcess = library.LoadLDSO(r.BackendAssetsPath, args, grpcProcess) + cmd := exec.Command( - assets.ResolvePath( - r.BackendAssetsPath, - "util", - "llama-cpp-rpc-server", - ), - append([]string{"--host", address, "--port", fmt.Sprint(port)}, r.ExtraLLamaCPPArgs...)..., + grpcProcess, args..., ) cmd.Env = os.Environ() @@ -86,7 +92,7 @@ func (r *P2P) Run(ctx *cliContext.Context) error { cmd.Stdout = os.Stdout if err := cmd.Start(); err != nil { - log.Error().Err(err).Msg("Failed to start llama-cpp-rpc-server") + log.Error().Any("grpcProcess", grpcProcess).Any("args", args).Err(err).Msg("Failed to start llama-cpp-rpc-server") } cmd.Wait() diff --git a/pkg/library/dynaload.go b/pkg/library/dynaload.go index 172e389a2c31..4e25ed91274b 100644 --- a/pkg/library/dynaload.go +++ b/pkg/library/dynaload.go @@ -49,7 +49,7 @@ func LoadLDSO(assetDir string, args []string, grpcProcess string) ([]string, str if _, err := os.Stat(ldPath); err == nil { log.Debug().Msgf("ld.so found") // We need to run the grpc process with the ld.so - args = append(args, grpcProcess) + args = append([]string{grpcProcess}, args...) grpcProcess = ldPath }