(self, p, model_name: str, model_type: ModelType)
| 139 | ) |
| 140 | |
| 141 | def get_profile_idx(self, p, model_name: str, model_type: ModelType) -> (int, int): |
| 142 | best_hr = None |
| 143 | |
| 144 | if self.is_img2img: |
| 145 | hr_scale = 1 |
| 146 | else: |
| 147 | hr_scale = p.hr_scale if p.enable_hr else 1 |
| 148 | ( |
| 149 | valid_models, |
| 150 | distances, |
| 151 | idx, |
| 152 | ) = modelmanager.get_valid_models( |
| 153 | model_name, |
| 154 | p.width, |
| 155 | p.height, |
| 156 | p.batch_size, |
| 157 | 77, # model_type |
| 158 | ) # TODO: max_embedding, just ignore? |
| 159 | if len(valid_models) == 0: |
| 160 | gr.Error( |
| 161 | f"""No valid profile found for ({model_name}) LOWRES. Please go to the TensorRT tab and generate an engine with the necessary profile. |
| 162 | If using hires.fix, you need an engine for both the base and upscaled resolutions. Otherwise, use the default (torch) U-Net.""" |
| 163 | ) |
| 164 | return None, None |
| 165 | best = idx[np.argmin(distances)] |
| 166 | best_hr = best |
| 167 | |
| 168 | if hr_scale != 1: |
| 169 | hr_w = int(p.width * p.hr_scale) |
| 170 | hr_h = int(p.height * p.hr_scale) |
| 171 | valid_models_hr, distances_hr, idx_hr = modelmanager.get_valid_models( |
| 172 | model_name, |
| 173 | hr_w, |
| 174 | hr_h, |
| 175 | p.batch_size, |
| 176 | 77, # model_type |
| 177 | ) # TODO: max_embedding |
| 178 | if len(valid_models_hr) == 0: |
| 179 | gr.Error( |
| 180 | f"""No valid profile found for ({model_name}) HIRES. Please go to the TensorRT tab and generate an engine with the necessary profile. |
| 181 | If using hires.fix, you need an engine for both the base and upscaled resolutions. Otherwise, use the default (torch) U-Net.""" |
| 182 | ) |
| 183 | merged_idx = [i for i, id in enumerate(idx) if id in idx_hr] |
| 184 | if len(merged_idx) == 0: |
| 185 | gr.Warning( |
| 186 | "No model available for both ({}) LOWRES ({}x{}) and HIRES ({}x{}). This will slow-down inference.".format( |
| 187 | model_name, p.width, p.height, hr_w, hr_h |
| 188 | ) |
| 189 | ) |
| 190 | return None, None |
| 191 | else: |
| 192 | _distances = [distances[i] for i in merged_idx] |
| 193 | best_hr = merged_idx[np.argmin(_distances)] |
| 194 | best = best_hr |
| 195 | |
| 196 | return best, best_hr |
| 197 | |
| 198 | def get_loras(self, p): |
no test coverage detected