-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Vulkan: Add GGML_OP_GET_REL_POS
#17417
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
Open
AgainstEntropy
wants to merge
4
commits into
ggml-org:master
Choose a base branch
from
AgainstEntropy:vulkan/rel-pos
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−0
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fb431da
vulkan: add get_rel_pos operation and corresponding shader
AgainstEntropy e94dc95
vulkan: fix floating point precision issue in get_rel_pos shader
AgainstEntropy e6eb7db
vulkan: refactored the ggml_vk_get_rel_pos function to use ggml_vk_op…
AgainstEntropy 41450b5
Merge remote-tracking branch 'origin/master' into vulkan/rel-pos
AgainstEntropy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #version 450 | ||
|
|
||
| #include "types.glsl" | ||
| #include "generic_unary_head.glsl" | ||
|
|
||
| layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in; | ||
|
|
||
| void main() { | ||
| const uint idx = get_idx(); | ||
| if (idx >= p.ne) { | ||
| return; | ||
| } | ||
|
|
||
| const uint i13 = fastdiv(idx, p.ne1_012mp, p.ne1_012L); | ||
| const uint i13_offset = i13 * p.ne12*p.ne11*p.ne10; | ||
| const uint i12 = fastdiv(idx - i13_offset, p.ne1_01mp, p.ne1_01L); | ||
| const uint i12_offset = i12*p.ne11*p.ne10; | ||
| const uint i11 = fastdiv(idx - i13_offset - i12_offset, p.ne1_0mp, p.ne1_0L); | ||
| const uint i10 = idx - i13_offset - i12_offset - i11*p.ne10; | ||
|
|
||
| const float kh = float(p.ne11); | ||
| const float qh = float(p.ne12); | ||
| const float k_scale = max(qh / kh, 1.0f); | ||
| const float q_scale = max(kh / qh, 1.0f); | ||
|
|
||
| // Add a small epsilon to avoid floating point precision issues | ||
| const float epsilon = 0.0001f; | ||
| const int pos = int(float(i12) * q_scale - float(i11) * k_scale + (kh - 1.0f) * k_scale + epsilon); | ||
|
|
||
| const uint src_idx = pos*p.nb01 + i10*p.nb00; | ||
| const uint dst_idx = i13*p.nb13 + i12*p.nb12 + i11*p.nb11 + i10*p.nb10; | ||
|
|
||
| data_d[get_doffset() + dst_idx] = D_TYPE(data_a[get_aoffset() + src_idx]); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any reason not to use ggml_vk_op_f32?
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.
It's because incontiguous input is not supported. The GGML_ASSERT check in ggml_vk_op_f32 will fail.
I think the behavior should be similar to GGML_OP_ARGSORT (while I'm not sure why GGML_OP_ARGSORT appears in ggml_vk_op_f32 but comes with a GGML_ASSERT(0)
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.
ARGSORT used to use
ggml_vk_op_f32, it just switched away from it because it needs custom logic and shader invocations for the handling of large input tensors.I think you should be able to use
ggml_vk_op_f32for this op. Can you be more specific which assertion failed?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.
Hi @0cc4m, thanks for the clarification.
Previously I encountered an assertion failure for the case
GET_REL_POS(type=f32, C=1, qh=1, kh=1, v=1)inggml_vk_op_f32, specifically on this line:ggml/src/ggml-vulkan/ggml-vulkan.cpp:8764: GGML_ASSERT(ggml_vk_op_supports_incontiguous(op) || ggml_vk_dim01_contiguous(src0)) failedI reviewed the whole process and realized that
ggml_is_contiguousreturned true here (src0 ne={1, 1, 1, 1}, viewed from ne={2, 1, 1, 1}). Therefore,ggml_backend_vk_device_supports_op(...)returned true, and then the checkggml_vk_dim01_contiguous(src0)later inggml_vk_op_f32failed.I have updated
ggml_vk_get_rel_posto useggml_vk_op_f32, andggml_vk_dim01_contiguoushas been added toggml_backend_vk_device_supports_opsoGET_REL_POS(type=f32,C=1,qh=1,kh=1,v=1)is no longer considered supported.To work with incontiguous inputs (v=1), we can simply use
ggml_cont.