Skip to content

Commit 0521f8c

Browse files
committed
minor updates
1 parent c2eaa04 commit 0521f8c

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

modules/onnx_impl/__init__.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,19 @@ def initialize_onnx():
197197
from installer import log
198198
from modules import devices
199199
from modules.shared import opts
200-
from .execution_providers import ExecutionProvider, TORCH_DEVICE_TO_EP, available_execution_providers
201-
if devices.backend == "rocm":
202-
TORCH_DEVICE_TO_EP["cuda"] = ExecutionProvider.ROCm
203-
try:
200+
try: # may fail on onnx import
201+
import onnx # pylint: disable=unused-import
202+
from .execution_providers import ExecutionProvider, TORCH_DEVICE_TO_EP, available_execution_providers
203+
if devices.backend == "rocm":
204+
TORCH_DEVICE_TO_EP["cuda"] = ExecutionProvider.ROCm
204205
from .pipelines.onnx_stable_diffusion_pipeline import OnnxStableDiffusionPipeline
205206
from .pipelines.onnx_stable_diffusion_img2img_pipeline import OnnxStableDiffusionImg2ImgPipeline
206207
from .pipelines.onnx_stable_diffusion_inpaint_pipeline import OnnxStableDiffusionInpaintPipeline
207208
from .pipelines.onnx_stable_diffusion_upscale_pipeline import OnnxStableDiffusionUpscalePipeline
208209
from .pipelines.onnx_stable_diffusion_xl_pipeline import OnnxStableDiffusionXLPipeline
209210
from .pipelines.onnx_stable_diffusion_xl_img2img_pipeline import OnnxStableDiffusionXLImg2ImgPipeline
210211

211-
# OnnxRuntimeModel Hijack.
212-
OnnxRuntimeModel.__module__ = 'diffusers'
212+
OnnxRuntimeModel.__module__ = 'diffusers' # OnnxRuntimeModel Hijack.
213213
diffusers.OnnxRuntimeModel = OnnxRuntimeModel
214214

215215
diffusers.OnnxStableDiffusionPipeline = OnnxStableDiffusionPipeline
@@ -229,8 +229,7 @@ def initialize_onnx():
229229
diffusers.OnnxStableDiffusionXLImg2ImgPipeline = OnnxStableDiffusionXLImg2ImgPipeline
230230
diffusers.pipelines.auto_pipeline.AUTO_IMAGE2IMAGE_PIPELINES_MAPPING["onnx-stable-diffusion-xl"] = diffusers.OnnxStableDiffusionXLImg2ImgPipeline
231231

232-
# Huggingface model compatibility
233-
diffusers.ORTStableDiffusionXLPipeline = diffusers.OnnxStableDiffusionXLPipeline
232+
diffusers.ORTStableDiffusionXLPipeline = diffusers.OnnxStableDiffusionXLPipeline # Huggingface model compatibility
234233
diffusers.ORTStableDiffusionXLImg2ImgPipeline = diffusers.OnnxStableDiffusionXLImg2ImgPipeline
235234

236235
optimum.onnxruntime.modeling_diffusion._ORTDiffusionModelPart.to = ORTDiffusionModelPart_to # pylint: disable=protected-access

modules/onnx_impl/ui.py

-15
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ def listener(v: Dict):
124124

125125
for submodel in sd_submodels:
126126
config: Dict = None
127-
128127
sd_pass_config_components[submodel] = {}
129-
130128
with open(os.path.join(sd_config_path, submodel), "r", encoding="utf-8") as file:
131129
config = json.load(file)
132130
sd_configs[submodel] = config
@@ -142,26 +140,21 @@ def listener(v: Dict):
142140

143141
with gr.TabItem(pass_name, id=f"sd_{submodel_name}_pass_{pass_name}"):
144142
config_dict = sd_configs[submodel]["passes"][pass_name]
145-
146143
pass_type = gr.Dropdown(label="Type", value=config_dict["type"], choices=(x.__name__ for x in tuple(olive_passes.REGISTRY.values())))
147144

148-
149145
def create_pass_config_change_listener(submodel, pass_name, config_key):
150146
def listener(value):
151147
sd_configs[submodel]["passes"][pass_name]["config"][config_key] = value
152148
return listener
153149

154-
155150
for config_key, v in getattr(olive_passes, config_dict["type"], olive_passes.Pass)._default_config(accelerator).items(): # pylint: disable=protected-access
156151
component = None
157-
158152
if v.type_ == bool:
159153
component = gr.Checkbox
160154
elif v.type_ == str:
161155
component = gr.Textbox
162156
elif v.type_ == int:
163157
component = gr.Number
164-
165158
if component is not None:
166159
component = component(value=config_dict["config"][config_key] if config_key in config_dict["config"] else v.default_value, label=config_key)
167160
sd_pass_config_components[submodel][pass_name][config_key] = component
@@ -192,9 +185,7 @@ def listener(v: Dict):
192185

193186
for submodel in sdxl_submodels:
194187
config: Dict = None
195-
196188
sdxl_pass_config_components[submodel] = {}
197-
198189
with open(os.path.join(sdxl_config_path, submodel), "r", encoding="utf-8") as file:
199190
config = json.load(file)
200191
sdxl_configs[submodel] = config
@@ -210,31 +201,25 @@ def listener(v: Dict):
210201

211202
with gr.TabItem(pass_name, id=f"sdxl_{submodel_name}_pass_{pass_name}"):
212203
config_dict = sdxl_configs[submodel]["passes"][pass_name]
213-
214204
pass_type = gr.Dropdown(label="Type", value=sdxl_configs[submodel]["passes"][pass_name]["type"], choices=(x.__name__ for x in tuple(olive_passes.REGISTRY.values())))
215205

216-
217206
def create_pass_config_change_listener(submodel, pass_name, config_key): # pylint: disable=function-redefined
218207
def listener(value):
219208
sdxl_configs[submodel]["passes"][pass_name]["config"][config_key] = value
220209
return listener
221210

222-
223211
for config_key, v in getattr(olive_passes, config_dict["type"], olive_passes.Pass)._default_config(accelerator).items(): # pylint: disable=protected-access
224212
component = None
225-
226213
if v.type_ == bool:
227214
component = gr.Checkbox
228215
elif v.type_ == str:
229216
component = gr.Textbox
230217
elif v.type_ == int:
231218
component = gr.Number
232-
233219
if component is not None:
234220
component = component(value=config_dict["config"][config_key] if config_key in config_dict["config"] else v.default_value, label=config_key)
235221
sdxl_pass_config_components[submodel][pass_name][config_key] = component
236222
component.change(fn=create_pass_config_change_listener(submodel, pass_name, config_key), inputs=component)
237-
238223
pass_type.change(fn=sdxl_create_change_listener(submodel, "passes", pass_name, "type"), inputs=pass_type)
239224

240225
def sdxl_save():

0 commit comments

Comments
 (0)