mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 02:24:59 +00:00
feat(diffusers): allow to override image gen options (#4807)
Use the options field in the model to override kwargs if needed. This allows to specify from the model yaml config: ```yaml options: - foo:bar ``` And each option will be used directly when calling the diffusers pipeline, e.g: ```python pipe( foo="bar", ) ``` Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
5f64cc6328
commit
f5638a6354
1 changed files with 15 additions and 0 deletions
|
@ -159,6 +159,18 @@ class BackendServicer(backend_pb2_grpc.BackendServicer):
|
||||||
torchType = torch.float16
|
torchType = torch.float16
|
||||||
variant = "fp16"
|
variant = "fp16"
|
||||||
|
|
||||||
|
options = request.Options
|
||||||
|
|
||||||
|
# empty dict
|
||||||
|
self.options = {}
|
||||||
|
|
||||||
|
# The options are a list of strings in this form optname:optvalue
|
||||||
|
# We are storing all the options in a dict so we can use it later when
|
||||||
|
# generating the images
|
||||||
|
for opt in options:
|
||||||
|
key, value = opt.split(":")
|
||||||
|
self.options[key] = value
|
||||||
|
|
||||||
local = False
|
local = False
|
||||||
modelFile = request.Model
|
modelFile = request.Model
|
||||||
|
|
||||||
|
@ -441,6 +453,9 @@ class BackendServicer(backend_pb2_grpc.BackendServicer):
|
||||||
# create a dictionary of parameters by using the keys from EnableParameters and the values from defaults
|
# create a dictionary of parameters by using the keys from EnableParameters and the values from defaults
|
||||||
kwargs = {key: options.get(key) for key in keys if key in options}
|
kwargs = {key: options.get(key) for key in keys if key in options}
|
||||||
|
|
||||||
|
# populate kwargs from self.options.
|
||||||
|
kwargs.update(self.options)
|
||||||
|
|
||||||
# Set seed
|
# Set seed
|
||||||
if request.seed > 0:
|
if request.seed > 0:
|
||||||
kwargs["generator"] = torch.Generator(device=self.device).manual_seed(
|
kwargs["generator"] = torch.Generator(device=self.device).manual_seed(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue