Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do pixel unshuffle in ggml ? #732

Open
delldu opened this issue Feb 14, 2024 · 2 comments
Open

How do pixel unshuffle in ggml ? #732

delldu opened this issue Feb 14, 2024 · 2 comments

Comments

@delldu
Copy link

delldu commented Feb 14, 2024

Dear friends,
We have following pytorch code in esrgan network, hope to used in ggml, would you like show us how to do in ggml ?
As you know, ggml tensor default maximum dims is 4, but here view and permute is 6. We need change GGML_MAX_DIMS to 6 ?

def pixel_unshuffle(x, scale: int):
    """Pixel unshuffle."""
    b, c, hh, hw = x.size()
    out_channel = int(c * (scale ** 2))
    assert hh % scale == 0 and hw % scale == 0
    h = hh // scale
    w = hw // scale
    x_view = x.view(b, c, h, scale, w, scale)
    x_view = x_view.permute(0, 1, 3, 5, 2, 4)

    return x_view.reshape(b, out_channel, h, w)
@ggerganov
Copy link
Owner

Maybe as a sequence of views and 4D permutes:

x_view = x.view(b*c, h, scale, w*scale)
x_view = x_view.permute(0, 2, 1, 3)

x_view = x.view(b*c*scale, h, w, scale)
x_view = x_view.permute(0, 3, 1, 2)

return x_view.reshape(b, out_channel, h, w)

(not sure if this is correct so verify)

If it is correct, it would be something like this in ggml:

x = ggml_reshape_4d(ctx, x, w*scale, scale, h, b*c);
x = ggml_permute   (ctx, x, 0, 2, 1, 3);
x = ggml_cont      (ctx, x);

x = ggml_reshape_4d(ctx, x, scale, w, h, b*c*scale);
x = ggml_permute   (ctx, x, 2, 0, 1, 3);
x = ggml_cont      (ctx, x);

x = ggml_reshape_4d(ctx, x, w, h, out_channel, b);

@delldu
Copy link
Author

delldu commented Feb 14, 2024

Thanks@ggerganov , we tested, the answer is not correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants