r""" Base class for all pipelines. [`DiffusionPipeline`] stores all components (models, schedulers, and processors) for diffusion pipelines and provides methods for loading, downloading and saving models. It also includes methods to: - move all PyTorch modules to the device of
| 128 | |
| 129 | |
| 130 | class DiffusionPipeline(ConfigMixin, PushToHubMixin): |
| 131 | r""" |
| 132 | Base class for all pipelines. |
| 133 | |
| 134 | [`DiffusionPipeline`] stores all components (models, schedulers, and processors) for diffusion pipelines and |
| 135 | provides methods for loading, downloading and saving models. It also includes methods to: |
| 136 | |
| 137 | - move all PyTorch modules to the device of your choice |
| 138 | - enable/disable the progress bar for the denoising iteration |
| 139 | |
| 140 | Class attributes: |
| 141 | |
| 142 | - **config_name** (`str`) -- The configuration filename that stores the class and module names of all the |
| 143 | diffusion pipeline's components. |
| 144 | - **_optional_components** (`List[str]`) -- List of all optional components that don't have to be passed to the |
| 145 | pipeline to function (should be overridden by subclasses). |
| 146 | """ |
| 147 | |
| 148 | config_name = "model_index.json" |
| 149 | model_cpu_offload_seq = None |
| 150 | hf_device_map = None |
| 151 | _optional_components = [] |
| 152 | _exclude_from_cpu_offload = [] |
| 153 | _load_connected_pipes = False |
| 154 | _is_onnx = False |
| 155 | |
| 156 | def register_modules(self, **kwargs): |
| 157 | for name, module in kwargs.items(): |
| 158 | # retrieve library |
| 159 | if module is None or isinstance(module, (tuple, list)) and module[0] is None: |
| 160 | register_dict = {name: (None, None)} |
| 161 | else: |
| 162 | library, class_name = _fetch_class_library_tuple(module) |
| 163 | register_dict = {name: (library, class_name)} |
| 164 | |
| 165 | # save model index config |
| 166 | self.register_to_config(**register_dict) |
| 167 | |
| 168 | # set models |
| 169 | setattr(self, name, module) |
| 170 | |
| 171 | def __setattr__(self, name: str, value: Any): |
| 172 | if name in self.__dict__ and hasattr(self.config, name): |
| 173 | # We need to overwrite the config if name exists in config |
| 174 | if isinstance(getattr(self.config, name), (tuple, list)): |
| 175 | if value is not None and self.config[name][0] is not None: |
| 176 | class_library_tuple = _fetch_class_library_tuple(value) |
| 177 | else: |
| 178 | class_library_tuple = (None, None) |
| 179 | |
| 180 | self.register_to_config(**{name: class_library_tuple}) |
| 181 | else: |
| 182 | self.register_to_config(**{name: value}) |
| 183 | |
| 184 | super().__setattr__(name, value) |
| 185 | |
| 186 | def save_pretrained( |
| 187 | self, |
nothing calls this directly
no outgoing calls
no test coverage detected