Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03afc83

Browse files
Green-Skystduhpf
andcommitted
actually fix vae tile merging
Co-authored-by: stduhpf <[email protected]>
1 parent 22e48d8 commit 03afc83

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

ggml_extend.hpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -367,44 +367,34 @@ __STATIC_INLINE__ void ggml_merge_tensor_2d(struct ggml_tensor* input,
367367
int64_t width = input->ne[0];
368368
int64_t height = input->ne[1];
369369
int64_t channels = input->ne[2];
370+
371+
int64_t img_width = output->ne[0];
372+
int64_t img_height = output->ne[1];
373+
370374
GGML_ASSERT(input->type == GGML_TYPE_F32 && output->type == GGML_TYPE_F32);
371375
for (int iy = 0; iy < height; iy++) {
372376
for (int ix = 0; ix < width; ix++) {
373377
for (int k = 0; k < channels; k++) {
374378
float new_value = ggml_tensor_get_f32(input, ix, iy, k);
375379
if (overlap > 0) { // blend colors in overlapped area
376380
float old_value = ggml_tensor_get_f32(output, x + ix, y + iy, k);
377-
const bool inside_x_overlap = x > 0 && ix < overlap;
378-
const bool inside_y_overlap = y > 0 && iy < overlap;
379-
if (inside_x_overlap && inside_y_overlap) {
380-
// upper left corner needs to be interpolated in both directions
381-
const float x_f = ix / float(overlap);
382-
const float y_f = iy / float(overlap);
383-
// TODO: try `x+y - 1`
384-
const float f = std::min(x_f, y_f); // min of both
385-
ggml_tensor_set_f32(
386-
output,
387-
ggml_lerp_f32(old_value, new_value, ggml_smootherstep_f32(f)),
388-
x + ix, y + iy, k
389-
);
390-
continue;
391-
} else if (inside_x_overlap) {
392-
ggml_tensor_set_f32(
393-
output,
394-
ggml_lerp_f32(old_value, new_value, ggml_smootherstep_f32(ix / float(overlap))),
395-
x + ix, y + iy, k
396-
);
397-
continue;
398-
} else if (inside_y_overlap) {
399-
ggml_tensor_set_f32(
400-
output,
401-
ggml_lerp_f32(old_value, new_value, ggml_smootherstep_f32(iy / float(overlap))),
402-
x + ix, y + iy, k
403-
);
404-
continue;
405-
}
381+
382+
const float x_f_0 = (x > 0) ? ix / float(overlap) : 1;
383+
const float x_f_1 = (x < (img_width - width)) ? (width - ix) / float(overlap) : 1 ;
384+
const float y_f_0 = (y > 0) ? iy / float(overlap) : 1;
385+
const float y_f_1 = (y < (img_height - height)) ? (height - iy) / float(overlap) : 1;
386+
387+
const float x_f = std::min(std::min(x_f_0, x_f_1), 1.f);
388+
const float y_f = std::min(std::min(y_f_0, y_f_1), 1.f);
389+
390+
ggml_tensor_set_f32(
391+
output,
392+
old_value + new_value * ggml_smootherstep_f32(y_f) * ggml_smootherstep_f32(x_f),
393+
x + ix, y + iy, k
394+
);
395+
} else {
396+
ggml_tensor_set_f32(output, new_value, x + ix, y + iy, k);
406397
}
407-
ggml_tensor_set_f32(output, new_value, x + ix, y + iy, k);
408398
}
409399
}
410400
}

0 commit comments

Comments
 (0)