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
feat : Adds ggml_upscale_ext
#814
Conversation
…cuda implementation next
(I also realize there are some unnecessary params in some of the functions, so I will clean that up before review) |
ggml_upscale_to_shape
ggml_upscale_to_shape
ggml_upscale_to_shape
ggml_upscale_to_shape
ggml_upscale_to_shape
Ready for review! :^) |
include/ggml/ggml.h
Outdated
@@ -468,6 +468,7 @@ extern "C" { | |||
GGML_OP_POOL_1D, | |||
GGML_OP_POOL_2D, | |||
GGML_OP_UPSCALE, // nearest interpolate | |||
GGML_OP_UPSCALE_TO_SHAPE, // nearest interpolate to specified tensor shape |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to add extra OP, we can reuse the existing GGML_OP_UPSCALE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
We should generalize the existing upscale OP and kernels since the existing |
I can do that. My thinking was to avoid breaking backwards compatibility, but I can just put the new behavior in the |
|
ggml_upscale_to_shape
ggml_upscale_ext
ready for review again :^) |
very impressive response time! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation ignore half-pixel effects - I'm not sure how the reference PyTorch operators behave, but it's something that needs a deeper look
I also wonder if we should take the time to make the upscale operator more general to support downscaling - i.e. GGML_OP_RESCALE
src/ggml-cuda/upscale.cu
Outdated
static __global__ void upscale_f32(const float * x, float * dst, | ||
const int ne00, const int ne01, const int ne02, const int ne03, | ||
const int ne10, const int ne11, const int ne12, const int ne13, | ||
const float sf0, const float sf1, const float sf2, const float sf3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the kernel to use the tensor strides - see the CPU and Metal implementations as an example. Otherwise, this would work only for contiguous data
When ready, try to see if you can add tests in test-backend-ops
that exercise non-contiguous data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK done.
…test for non-contiguous behavior
Alright so wrt behaving similarly to PyTorch nearest neighbor interpolation I can confirm
behaves the same way (only tested with cuda backend) as
for my internal test case tensor shaped I think it would be nice to support downscaling but I also think it might be good to leave that to a future PR. Ready for review again :^) |
Also is there somewhere inputs and output target literals are defined for the test cases? I found it a bit strange that I didn't have to specify the actual elementwise values of input literals and output target literals when defining the tests. |
The Also, does PyTorch support floating-point scaling factor? If so, we should consider extending the functionality |
Closes issue #812
Adds
ggml_upscale_ext
alternate version ofggml_upscale
which lets the user upscale a tensor to a specified shape using nearest neighbor interpolation.Adds a CPU and cuda implementation, and test, though it's not clear to me either this or
ggml_upscale
has adequate tests.Also, the reason I added this is because it is necessary to convert tortoise-tts to ggml.
This is unfinished since I still need to add the cuda implementation and possibly expand tests since I haven't verified it actually works yet. Will remove draft annotation when ready for review.