Skip to content

Support broadcast add & mul on CUDA (fixed) #2192

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

Merged
merged 2 commits into from
Jul 14, 2023

Conversation

li-plus
Copy link
Contributor

@li-plus li-plus commented Jul 12, 2023

Should fix #2191. Missed ne11 term for ky in the previous version. Now fixed and generation is correct.

// compute
mul_f32_cuda(src0_ddf_i01, src1_ddf_i01, dst_ddf_i01, ne00, ne10, cudaStream_main);
}
mul_f32_cuda(src0_ddf_i, src1_ddf_i, dst_ddf_i, ne00*i01_diff, ne10*ne11, cudaStream_main);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The broadcasting logic here is still incorrect. The implementation on master broadcasts the values per row while this broadcasts the values after flattening both tensors. As long as ne11 == 1 this doesn't make a difference but I don't think that this is the implementation that we should be using.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that the column number of src0 and src1 is ensured to be the same by checking ggml_can_repeat_rows, so broadcasting after flattening 2d sub blocks should be the same as broadcasting every row. Did I miss something?

https://github.com/ggerganov/llama.cpp/blob/32c54116318929c90fd7ae814cf9b5232cd44c36/ggml.c#L5228-L5235

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, according to the commit history the following seems to have happened: I implemented broadcasting for multiplication both in dimension 0 and dimension 1. @ggerganov then added the additional requirement that dimension 0 must be equal via ggml_can_repeat_rows which effectively limits broadcasting to dimension 1. If that is indeed the specification to which broadcasting should be implemented then the broadcasting logic in this PR is correct.

Copy link
Member

Choose a reason for hiding this comment

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

For now let's broadcast only over dimension 1 - later we'll fix the TODOs and support dimension 0 broadcasts.
Can also obsolete ggml_scale() when we do that.

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

Successfully merging this pull request may close these issues.

3 participants