2024-04-11 07:19:24 +00:00
package cli
import (
"encoding/json"
"fmt"
2024-06-23 08:24:36 +00:00
cliContext "github.com/mudler/LocalAI/core/cli/context"
2024-06-24 15:32:12 +00:00
"github.com/mudler/LocalAI/core/config"
feat(llama.cpp): Totally decentralized, private, distributed, p2p inference (#2343)
* feat(llama.cpp): Enable decentralized, distributed inference
As https://github.com/mudler/LocalAI/pull/2324 introduced distributed inferencing thanks to
@rgerganov implementation in https://github.com/ggerganov/llama.cpp/pull/6829 in upstream llama.cpp, now
it is possible to distribute the workload to remote llama.cpp gRPC server.
This changeset now uses mudler/edgevpn to establish a secure, distributed network between the nodes using a shared token.
The token is generated automatically when starting the server with the `--p2p` flag, and can be used by starting the workers
with `local-ai worker p2p-llama-cpp-rpc` by passing the token via environment variable (TOKEN) or with args (--token).
As per how mudler/edgevpn works, a network is established between the server and the workers with dht and mdns discovery protocols,
the llama.cpp rpc server is automatically started and exposed to the underlying p2p network so the API server can connect on.
When the HTTP server is started, it will discover the workers in the network and automatically create the port-forwards to the service locally.
Then llama.cpp is configured to use the services.
This feature is behind the "p2p" GO_FLAGS
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* go mod tidy
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* ci: add p2p tag
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* better message
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
---------
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2024-05-20 17:17:59 +00:00
2024-06-24 15:32:12 +00:00
"github.com/mudler/LocalAI/core/gallery"
2024-06-23 08:24:36 +00:00
"github.com/mudler/LocalAI/pkg/downloader"
"github.com/mudler/LocalAI/pkg/startup"
2024-04-11 07:19:24 +00:00
"github.com/rs/zerolog/log"
"github.com/schollz/progressbar/v3"
)
type ModelsCMDFlags struct {
2024-06-12 22:47:16 +00:00
Galleries string ` env:"LOCALAI_GALLERIES,GALLERIES" help:"JSON list of galleries" group:"models" default:"$ { galleries}" `
2024-04-11 07:19:24 +00:00
ModelsPath string ` env:"LOCALAI_MODELS_PATH,MODELS_PATH" type:"path" default:"$ { basepath}/models" help:"Path containing models used for inferencing" group:"storage" `
}
type ModelsList struct {
ModelsCMDFlags ` embed:"" `
}
type ModelsInstall struct {
ModelArgs [ ] string ` arg:"" optional:"" name:"models" help:"Model configuration URLs to load" `
ModelsCMDFlags ` embed:"" `
}
type ModelsCMD struct {
2024-04-22 04:34:59 +00:00
List ModelsList ` cmd:"" help:"List the models available in your galleries" default:"withargs" `
2024-04-11 07:19:24 +00:00
Install ModelsInstall ` cmd:"" help:"Install a model from the gallery" `
}
feat(llama.cpp): Totally decentralized, private, distributed, p2p inference (#2343)
* feat(llama.cpp): Enable decentralized, distributed inference
As https://github.com/mudler/LocalAI/pull/2324 introduced distributed inferencing thanks to
@rgerganov implementation in https://github.com/ggerganov/llama.cpp/pull/6829 in upstream llama.cpp, now
it is possible to distribute the workload to remote llama.cpp gRPC server.
This changeset now uses mudler/edgevpn to establish a secure, distributed network between the nodes using a shared token.
The token is generated automatically when starting the server with the `--p2p` flag, and can be used by starting the workers
with `local-ai worker p2p-llama-cpp-rpc` by passing the token via environment variable (TOKEN) or with args (--token).
As per how mudler/edgevpn works, a network is established between the server and the workers with dht and mdns discovery protocols,
the llama.cpp rpc server is automatically started and exposed to the underlying p2p network so the API server can connect on.
When the HTTP server is started, it will discover the workers in the network and automatically create the port-forwards to the service locally.
Then llama.cpp is configured to use the services.
This feature is behind the "p2p" GO_FLAGS
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* go mod tidy
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* ci: add p2p tag
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* better message
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
---------
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2024-05-20 17:17:59 +00:00
func ( ml * ModelsList ) Run ( ctx * cliContext . Context ) error {
2024-06-24 15:32:12 +00:00
var galleries [ ] config . Gallery
2024-04-11 07:19:24 +00:00
if err := json . Unmarshal ( [ ] byte ( ml . Galleries ) , & galleries ) ; err != nil {
log . Error ( ) . Err ( err ) . Msg ( "unable to load galleries" )
}
models , err := gallery . AvailableGalleryModels ( galleries , ml . ModelsPath )
if err != nil {
return err
}
for _ , model := range models {
if model . Installed {
fmt . Printf ( " * %s@%s (installed)\n" , model . Gallery . Name , model . Name )
} else {
fmt . Printf ( " - %s@%s\n" , model . Gallery . Name , model . Name )
}
}
return nil
}
feat(llama.cpp): Totally decentralized, private, distributed, p2p inference (#2343)
* feat(llama.cpp): Enable decentralized, distributed inference
As https://github.com/mudler/LocalAI/pull/2324 introduced distributed inferencing thanks to
@rgerganov implementation in https://github.com/ggerganov/llama.cpp/pull/6829 in upstream llama.cpp, now
it is possible to distribute the workload to remote llama.cpp gRPC server.
This changeset now uses mudler/edgevpn to establish a secure, distributed network between the nodes using a shared token.
The token is generated automatically when starting the server with the `--p2p` flag, and can be used by starting the workers
with `local-ai worker p2p-llama-cpp-rpc` by passing the token via environment variable (TOKEN) or with args (--token).
As per how mudler/edgevpn works, a network is established between the server and the workers with dht and mdns discovery protocols,
the llama.cpp rpc server is automatically started and exposed to the underlying p2p network so the API server can connect on.
When the HTTP server is started, it will discover the workers in the network and automatically create the port-forwards to the service locally.
Then llama.cpp is configured to use the services.
This feature is behind the "p2p" GO_FLAGS
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* go mod tidy
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* ci: add p2p tag
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
* better message
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
---------
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2024-05-20 17:17:59 +00:00
func ( mi * ModelsInstall ) Run ( ctx * cliContext . Context ) error {
2024-06-24 15:32:12 +00:00
var galleries [ ] config . Gallery
2024-06-13 14:12:46 +00:00
if err := json . Unmarshal ( [ ] byte ( mi . Galleries ) , & galleries ) ; err != nil {
log . Error ( ) . Err ( err ) . Msg ( "unable to load galleries" )
}
2024-06-18 20:43:43 +00:00
2024-06-12 22:47:16 +00:00
for _ , modelName := range mi . ModelArgs {
2024-04-11 07:19:24 +00:00
2024-06-12 22:47:16 +00:00
progressBar := progressbar . NewOptions (
1000 ,
progressbar . OptionSetDescription ( fmt . Sprintf ( "downloading model %s" , modelName ) ) ,
progressbar . OptionShowBytes ( false ) ,
progressbar . OptionClearOnFinish ( ) ,
)
progressCallback := func ( fileName string , current string , total string , percentage float64 ) {
v := int ( percentage * 10 )
err := progressBar . Set ( v )
if err != nil {
log . Error ( ) . Err ( err ) . Str ( "filename" , fileName ) . Int ( "value" , v ) . Msg ( "error while updating progress bar" )
}
}
2024-06-13 14:12:46 +00:00
//startup.InstallModels()
2024-06-12 22:47:16 +00:00
models , err := gallery . AvailableGalleryModels ( galleries , mi . ModelsPath )
2024-04-29 13:11:42 +00:00
if err != nil {
2024-06-12 22:47:16 +00:00
return err
}
2024-06-22 06:17:41 +00:00
if ! downloader . LooksLikeOCI ( modelName ) {
model := gallery . FindModel ( models , modelName , mi . ModelsPath )
if model == nil {
log . Error ( ) . Str ( "model" , modelName ) . Msg ( "model not found" )
return err
}
2024-06-12 22:47:16 +00:00
2024-06-22 06:17:41 +00:00
log . Info ( ) . Str ( "model" , modelName ) . Str ( "license" , model . License ) . Msg ( "installing model" )
}
2024-06-13 14:12:46 +00:00
err = startup . InstallModels ( galleries , "" , mi . ModelsPath , progressCallback , modelName )
2024-06-12 22:47:16 +00:00
if err != nil {
return err
2024-04-29 13:11:42 +00:00
}
2024-04-11 07:19:24 +00:00
}
return nil
}