Skip to content

Commit f5638a6

Browse files
authoredFeb 11, 2025
feat(diffusers): allow to override image gen options (mudler#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>
1 parent 5f64cc6 commit f5638a6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎backend/python/diffusers/backend.py

+15
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ def LoadModel(self, request, context):
159159
torchType = torch.float16
160160
variant = "fp16"
161161

162+
options = request.Options
163+
164+
# empty dict
165+
self.options = {}
166+
167+
# The options are a list of strings in this form optname:optvalue
168+
# We are storing all the options in a dict so we can use it later when
169+
# generating the images
170+
for opt in options:
171+
key, value = opt.split(":")
172+
self.options[key] = value
173+
162174
local = False
163175
modelFile = request.Model
164176

@@ -441,6 +453,9 @@ def GenerateImage(self, request, context):
441453
# create a dictionary of parameters by using the keys from EnableParameters and the values from defaults
442454
kwargs = {key: options.get(key) for key in keys if key in options}
443455

456+
# populate kwargs from self.options.
457+
kwargs.update(self.options)
458+
444459
# Set seed
445460
if request.seed > 0:
446461
kwargs["generator"] = torch.Generator(device=self.device).manual_seed(

0 commit comments

Comments
 (0)
Failed to load comments.