Fix iMF/pMF inference by filtering unsupported pipeline kwargs
Browse files- model_loader.py +13 -1
model_loader.py
CHANGED
|
@@ -334,6 +334,18 @@ def default_class_label_for_pipe(pipe: DiffusionPipeline, profile: ModelProfile)
|
|
| 334 |
return synonyms[0] if synonyms else profile.default_class_label
|
| 335 |
|
| 336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
def run_inference(
|
| 338 |
profile: ModelProfile,
|
| 339 |
pipe: DiffusionPipeline,
|
|
@@ -376,4 +388,4 @@ def run_inference(
|
|
| 376 |
call_kwargs["height"] = height
|
| 377 |
call_kwargs["width"] = width
|
| 378 |
|
| 379 |
-
return pipe(**call_kwargs).images[0]
|
|
|
|
| 334 |
return synonyms[0] if synonyms else profile.default_class_label
|
| 335 |
|
| 336 |
|
| 337 |
+
def _filter_call_kwargs(pipe: DiffusionPipeline, call_kwargs: dict[str, Any]) -> dict[str, Any]:
|
| 338 |
+
"""Drop kwargs that the pipeline __call__ does not accept (e.g. height/width for iMF/pMF)."""
|
| 339 |
+
try:
|
| 340 |
+
params = inspect.signature(pipe.__call__).parameters
|
| 341 |
+
except (TypeError, ValueError):
|
| 342 |
+
return call_kwargs
|
| 343 |
+
if any(param.kind == inspect.Parameter.VAR_KEYWORD for param in params.values()):
|
| 344 |
+
return call_kwargs
|
| 345 |
+
accepted = set(params.keys())
|
| 346 |
+
return {key: value for key, value in call_kwargs.items() if key in accepted}
|
| 347 |
+
|
| 348 |
+
|
| 349 |
def run_inference(
|
| 350 |
profile: ModelProfile,
|
| 351 |
pipe: DiffusionPipeline,
|
|
|
|
| 388 |
call_kwargs["height"] = height
|
| 389 |
call_kwargs["width"] = width
|
| 390 |
|
| 391 |
+
return pipe(**_filter_call_kwargs(pipe, call_kwargs)).images[0]
|