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

vulkan: Fix newly added tests for permuted mul_mat and 1D im2col #10226

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

jeffbolznv
Copy link
Collaborator

This fixes recently added tests for permuted mul_mat and 1D im2col in the Vulkan backend. The new tests were added by c39665f and 80273a3.

The im2col fix is just applying the same code change as in 80273a3. The mul_mat fix is a combination of fixes, disabling fast paths that don't support certain combinations, and making some new tests unsupported. I verified that preexisting tests didn't change which code path they used and that no preexisting tests became unsupported.

@github-actions github-actions bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Nov 9, 2024
@@ -3630,9 +3630,19 @@ static void ggml_vk_mul_mat_vec_nc_f16_f32(ggml_backend_vk_context * ctx, vk_con

static void ggml_vk_mul_mat(ggml_backend_vk_context * ctx, vk_context& subctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst, bool dryrun = false) {
VK_LOG_DEBUG("ggml_vk_mul_mat(" << src0 << ", " << src1 << ", " << dst << ")");
if (src0->type == GGML_TYPE_F16 && ggml_is_permuted(src0) && ggml_is_permuted(src1) && dst->ne[1] == 1) {
if (src0->type == GGML_TYPE_F16 && ggml_is_permuted(src0) && ggml_is_permuted(src1) && dst->ne[1] == 1 &&
// detect 0213 permutation, and batch size of 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct, or is there a better way to detect this permutation?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a better way currently. We can add a helper function in ggml.h to check permutations if needed.

But I'm wondering how come the CUDA backend does not do these checks and still passes the tests?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because CUDA only uses this function if any_gpus_with_slow_fp16 is true, otherwise it falls back to another function, in this case ggml_cuda_op_mul_mat_cublas according to my debugger.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I run the tests with a Tesla P40 (which does have slow fp16) the CUDA tests do in fact fail in the same way, so I guess this fix should also be applied to CUDA.

Copy link
Collaborator

@0cc4m 0cc4m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this. I ran the tests again on my GPUs and it fixes the issues.

I think the permutation check should go into ggml.h to make it easier to understand and so we can reuse it in other backends. @ggerganov Should that be done in this PR or separately with the fix for CUDA?

@ggerganov
Copy link
Owner

Can be done in a separate PR. Maybe add a function ggml_is_permuted_0213().

@0cc4m 0cc4m merged commit 160687b into ggerganov:master Nov 10, 2024
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ggml changes relating to the ggml tensor library for machine learning Vulkan Issues specific to the Vulkan backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants