Retrieve pipeline class that inherits from `DiffusionPipeline`. Note that there has to be exactly one class inheriting from `DiffusionPipeline`.
(loaded_module)
| 216 | |
| 217 | |
| 218 | def find_pipeline_class(loaded_module): |
| 219 | """ |
| 220 | Retrieve pipeline class that inherits from `DiffusionPipeline`. Note that there has to be exactly one class |
| 221 | inheriting from `DiffusionPipeline`. |
| 222 | """ |
| 223 | from ..pipelines import DiffusionPipeline |
| 224 | |
| 225 | cls_members = dict(inspect.getmembers(loaded_module, inspect.isclass)) |
| 226 | |
| 227 | pipeline_class = None |
| 228 | for cls_name, cls in cls_members.items(): |
| 229 | if ( |
| 230 | cls_name != DiffusionPipeline.__name__ |
| 231 | and issubclass(cls, DiffusionPipeline) |
| 232 | and cls.__module__.split(".")[0] != "diffusers" |
| 233 | ): |
| 234 | if pipeline_class is not None: |
| 235 | raise ValueError( |
| 236 | f"Multiple classes that inherit from {DiffusionPipeline.__name__} have been found:" |
| 237 | f" {pipeline_class.__name__}, and {cls_name}. Please make sure to define only one in" |
| 238 | f" {loaded_module}." |
| 239 | ) |
| 240 | pipeline_class = cls |
| 241 | |
| 242 | return pipeline_class |
| 243 | |
| 244 | |
| 245 | @validate_hf_hub_args |
no test coverage detected
searching dependent graphs…