Retrieve pipeline class that inherits from `DiffusionPipeline`. Note that there has to be exactly one class inheriting from `DiffusionPipeline`.
(loaded_module)
| 169 | |
| 170 | |
| 171 | def find_pipeline_class(loaded_module): |
| 172 | """ |
| 173 | Retrieve pipeline class that inherits from `DiffusionPipeline`. Note that there has to be exactly one class |
| 174 | inheriting from `DiffusionPipeline`. |
| 175 | """ |
| 176 | from ..pipelines import DiffusionPipeline |
| 177 | |
| 178 | cls_members = dict(inspect.getmembers(loaded_module, inspect.isclass)) |
| 179 | |
| 180 | pipeline_class = None |
| 181 | for cls_name, cls in cls_members.items(): |
| 182 | if ( |
| 183 | cls_name != DiffusionPipeline.__name__ |
| 184 | and issubclass(cls, DiffusionPipeline) |
| 185 | and cls.__module__.split(".")[0] != "diffusers" |
| 186 | ): |
| 187 | if pipeline_class is not None: |
| 188 | raise ValueError( |
| 189 | f"Multiple classes that inherit from {DiffusionPipeline.__name__} have been found:" |
| 190 | f" {pipeline_class.__name__}, and {cls_name}. Please make sure to define only one in" |
| 191 | f" {loaded_module}." |
| 192 | ) |
| 193 | pipeline_class = cls |
| 194 | |
| 195 | return pipeline_class |
| 196 | |
| 197 | |
| 198 | @validate_hf_hub_args |
no outgoing calls
no test coverage detected