mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-24 14:56:41 +00:00
887b3dff04
* Use cuda in transformers if available tensorflow probably needs a different check. Signed-off-by: Erich Schubert <kno10@users.noreply.github.com> * feat: expose CUDA at top level Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * tests: add to tests and create workflow for py extra backends * doc: update note on how to use core images --------- Signed-off-by: Erich Schubert <kno10@users.noreply.github.com> Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Erich Schubert <kno10@users.noreply.github.com>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package backend
|
|
|
|
import (
|
|
config "github.com/go-skynet/LocalAI/api/config"
|
|
"github.com/go-skynet/LocalAI/api/options"
|
|
"github.com/go-skynet/LocalAI/pkg/grpc/proto"
|
|
model "github.com/go-skynet/LocalAI/pkg/model"
|
|
)
|
|
|
|
func ImageGeneration(height, width, mode, step, seed int, positive_prompt, negative_prompt, src, dst string, loader *model.ModelLoader, c config.Config, o *options.Option) (func() error, error) {
|
|
|
|
opts := modelOpts(c, o, []model.Option{
|
|
model.WithBackendString(c.Backend),
|
|
model.WithAssetDir(o.AssetsDestination),
|
|
model.WithThreads(uint32(c.Threads)),
|
|
model.WithContext(o.Context),
|
|
model.WithModel(c.Model),
|
|
model.WithLoadGRPCLoadModelOpts(&proto.ModelOptions{
|
|
CUDA: c.CUDA,
|
|
SchedulerType: c.Diffusers.SchedulerType,
|
|
PipelineType: c.Diffusers.PipelineType,
|
|
CFGScale: c.Diffusers.CFGScale,
|
|
LoraAdapter: c.LoraAdapter,
|
|
LoraScale: c.LoraScale,
|
|
LoraBase: c.LoraBase,
|
|
IMG2IMG: c.Diffusers.IMG2IMG,
|
|
CLIPModel: c.Diffusers.ClipModel,
|
|
CLIPSubfolder: c.Diffusers.ClipSubFolder,
|
|
CLIPSkip: int32(c.Diffusers.ClipSkip),
|
|
}),
|
|
})
|
|
|
|
inferenceModel, err := loader.BackendLoader(
|
|
opts...,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
fn := func() error {
|
|
_, err := inferenceModel.GenerateImage(
|
|
o.Context,
|
|
&proto.GenerateImageRequest{
|
|
Height: int32(height),
|
|
Width: int32(width),
|
|
Mode: int32(mode),
|
|
Step: int32(step),
|
|
Seed: int32(seed),
|
|
CLIPSkip: int32(c.Diffusers.ClipSkip),
|
|
PositivePrompt: positive_prompt,
|
|
NegativePrompt: negative_prompt,
|
|
Dst: dst,
|
|
Src: src,
|
|
EnableParameters: c.Diffusers.EnableParameters,
|
|
})
|
|
return err
|
|
}
|
|
|
|
return fn, nil
|
|
}
|