From 61c3eb85e0fe209266461f61598824c60bf6f427 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 27 Feb 2024 14:45:03 -0500 Subject: [PATCH] bfloat16 to float --- CHANGELOG.md | 3 ++- modules/deepbooru.py | 2 +- modules/lama.py | 2 +- modules/processing_correction.py | 10 +++++----- scripts/xyz_grid.py | 3 +++ 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3838f32d..c0f4ebabe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,9 +26,10 @@ - **Fixes** - improve model cpu offload compatibility - improve model sequential offload compatibility + - improve bfloat16 compatibility - fix extra networks refresh - fix sdp memory attention in backend original - - fix autodetect v2.1 models + - fix autodetect sd21 models - exception handler around vram memory stats gather - improve ZLUDA installer with `--use-zluda` cli param, thanks @lshqqytiger diff --git a/modules/deepbooru.py b/modules/deepbooru.py index 8b822bf95..099a32fe8 100644 --- a/modules/deepbooru.py +++ b/modules/deepbooru.py @@ -63,7 +63,7 @@ class DeepDanbooru: with devices.inference_context(), devices.autocast(): x = torch.from_numpy(a).to(devices.device) - y = self.model(x)[0].detach().cpu().numpy() + y = self.model(x)[0].detach().float().cpu().numpy() probability_dict = {} diff --git a/modules/lama.py b/modules/lama.py index 06e360caa..0656ba521 100644 --- a/modules/lama.py +++ b/modules/lama.py @@ -96,7 +96,7 @@ class SimpleLama: image, mask = prepare_img_and_mask(image, mask, self.device) with devices.inference_context(): inpainted = self.model(image, mask) - cur_res = inpainted[0].permute(1, 2, 0).detach().cpu().numpy() + cur_res = inpainted[0].permute(1, 2, 0).detach().float().cpu().numpy() cur_res = np.clip(cur_res * 255, 0, 255).astype(np.uint8) cur_res = Image.fromarray(cur_res) return cur_res diff --git a/modules/processing_correction.py b/modules/processing_correction.py index 892c1e8c7..6afaaa8d3 100644 --- a/modules/processing_correction.py +++ b/modules/processing_correction.py @@ -46,11 +46,11 @@ def soft_clamp_tensor(tensor, threshold=0.8, boundary=4): def center_tensor(tensor, channel_shift=0.0, full_shift=0.0, offset=0.0): if channel_shift == 0 and full_shift == 0 and offset == 0: return tensor - debug(f'HDR center: Before Adjustment: Full mean={tensor.mean().item()} Channel means={tensor.mean(dim=(-1, -2)).cpu().numpy()}') + debug(f'HDR center: Before Adjustment: Full mean={tensor.mean().item()} Channel means={tensor.mean(dim=(-1, -2)).float().cpu().numpy()}') tensor -= tensor.mean(dim=(-1, -2), keepdim=True) * channel_shift tensor -= tensor.mean() * full_shift - offset debug(f'HDR center: channel-shift={channel_shift} full-shift={full_shift}') - debug(f'HDR center: After Adjustment: Full mean={tensor.mean().item()} Channel means={tensor.mean(dim=(-1, -2)).cpu().numpy()}') + debug(f'HDR center: After Adjustment: Full mean={tensor.mean().item()} Channel means={tensor.mean(dim=(-1, -2)).float().cpu().numpy()}') return tensor @@ -122,9 +122,9 @@ def correction_callback(p, timestep, kwargs): for i in range(latents.shape[0]): latents[i] = correction(p, timestep, latents[i]) debug(f"Full Mean: {latents[i].mean().item()}") - debug(f"Channel Means: {latents[i].mean(dim=(-1, -2), keepdim=True).flatten().cpu().numpy()}") - debug(f"Channel Mins: {latents[i].min(-1, keepdim=True)[0].min(-2, keepdim=True)[0].flatten().cpu().numpy()}") - debug(f"Channel Maxes: {latents[i].max(-1, keepdim=True)[0].min(-2, keepdim=True)[0].flatten().cpu().numpy()}") + debug(f"Channel Means: {latents[i].mean(dim=(-1, -2), keepdim=True).flatten().float().cpu().numpy()}") + debug(f"Channel Mins: {latents[i].min(-1, keepdim=True)[0].min(-2, keepdim=True)[0].flatten().float().cpu().numpy()}") + debug(f"Channel Maxes: {latents[i].max(-1, keepdim=True)[0].min(-2, keepdim=True)[0].flatten().float().cpu().numpy()}") elif len(latents.shape) == 5 and latents.shape[0] == 1: # probably animatediff latents = latents.squeeze(0).permute(1, 0, 2, 3) for i in range(latents.shape[0]): diff --git a/scripts/xyz_grid.py b/scripts/xyz_grid.py index ab93a6d96..9d2022641 100644 --- a/scripts/xyz_grid.py +++ b/scripts/xyz_grid.py @@ -298,6 +298,9 @@ def draw_xyz_grid(p, xs, ys, zs, x_labels, y_labels, z_labels, cell, draw_legend processed: processing.Processed = cell(x, y, z, ix, iy, iz) if processed_result is None: processed_result = copy(processed) + if processed_result is None: + shared.log.error('XYZ grid: no processing results') + return processing.Processed(p, []) processed_result.images = [None] * list_size processed_result.all_prompts = [None] * list_size processed_result.all_seeds = [None] * list_size