forked from Juste-Leo2/llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Draft PR for ZAYA1 llama.cpp implementation #1
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
nanduruganesh
wants to merge
6
commits into
master
Choose a base branch
from
CCA
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
99e5d03
ops: add Conv1dGrouped operation
Juste-Leo2 e0ac753
initial implementation
Juste-Leo2 7cc554a
implementation checkpoint
Juste-Leo2 02a9843
update
Juste-Leo2 8362c10
add corrections
Juste-Leo2 109856e
zaya generation running
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
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 |
|---|---|---|
|
|
@@ -2041,6 +2041,21 @@ extern "C" { | |
| int s0, // stride | ||
| int d0); // dilation | ||
|
|
||
| // grouped 1D convolution | ||
| // a: [K, IC/G, OC] convolution kernel | ||
| // b: [L, IC, N] data | ||
| // groups must divide both IC and OC evenly | ||
| // when groups == 1, equivalent to ggml_conv_1d | ||
| // when groups == IC, equivalent to ggml_conv_1d_dw | ||
| GGML_API struct ggml_tensor * ggml_conv_1d_grouped( | ||
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, // convolution kernel | ||
| struct ggml_tensor * b, // data | ||
| int s0, // stride | ||
| int p0, // padding | ||
| int d0, // dilation | ||
| int groups); // number of groups | ||
|
Comment on lines
+2050
to
+2057
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, a separate PR |
||
|
|
||
| GGML_API struct ggml_tensor * ggml_conv_transpose_1d( | ||
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, // convolution kernel | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -2018,9 +2018,9 @@ struct ggml_tensor * ggml_dup_inplace( | |
|
|
||
| static struct ggml_tensor * ggml_add_impl( | ||
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, | ||
| struct ggml_tensor * b, | ||
| bool inplace) { | ||
| struct ggml_tensor * a, | ||
| struct ggml_tensor * b, | ||
| bool inplace) { | ||
| GGML_ASSERT(ggml_can_repeat(b, a)); | ||
|
|
||
| struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a); | ||
|
|
@@ -4541,6 +4541,63 @@ struct ggml_tensor * ggml_conv_1d_dw_ph( | |
| return ggml_conv_1d_dw(ctx, a, b, s0, a->ne[0] / 2, d0); | ||
| } | ||
|
|
||
| // ggml_conv_1d_grouped | ||
|
|
||
| struct ggml_tensor * ggml_conv_1d_grouped( | ||
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, | ||
| struct ggml_tensor * b, | ||
| int s0, | ||
| int p0, | ||
| int d0, | ||
| int groups) { | ||
| GGML_ASSERT(groups > 0); | ||
|
|
||
| const int64_t OC = a->ne[2]; // total output channels | ||
| const int64_t IC_G = a->ne[1]; // input channels per group (kernel dim) | ||
| const int64_t IC = b->ne[1]; // total input channels | ||
|
|
||
| GGML_ASSERT(IC % groups == 0); | ||
| GGML_ASSERT(OC % groups == 0); | ||
| GGML_ASSERT(IC_G == IC / groups); | ||
|
|
||
| // degenerate cases: fall back to existing implementations | ||
| if (groups == 1) { | ||
| return ggml_conv_1d(ctx, a, b, s0, p0, d0); | ||
| } | ||
| if (groups == IC && groups == OC) { | ||
| return ggml_conv_1d_dw(ctx, a, b, s0, p0, d0); | ||
| } | ||
|
|
||
| const int64_t OC_G = OC / groups; | ||
|
|
||
| struct ggml_tensor * result = NULL; | ||
|
|
||
| for (int g = 0; g < groups; g++) { | ||
| // slice kernel for group g: [K, IC_G, OC_G] | ||
| struct ggml_tensor * a_g = ggml_view_3d(ctx, a, | ||
| a->ne[0], IC_G, OC_G, | ||
| a->nb[1], a->nb[2], | ||
| g * OC_G * a->nb[2]); | ||
|
|
||
| // slice input for group g: [L, IC_G, N] | ||
| struct ggml_tensor * b_g = ggml_view_3d(ctx, b, | ||
| b->ne[0], IC_G, b->ne[2], | ||
| b->nb[1], b->nb[2], | ||
| g * IC_G * b->nb[1]); | ||
|
|
||
| struct ggml_tensor * out_g = ggml_conv_1d(ctx, a_g, b_g, s0, p0, d0); | ||
|
|
||
| if (result == NULL) { | ||
| result = out_g; | ||
| } else { | ||
| result = ggml_concat(ctx, result, out_g, 1); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
Comment on lines
+4578
to
+4599
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're reusing the ggml operations; we'll need to see later whether it's necessary to create a specific operation for each backend. |
||
|
|
||
| // ggml_conv_transpose_1d | ||
|
|
||
| static int64_t ggml_calc_conv_transpose_1d_output_size(int64_t ins, int64_t ks, int s, int p, int d) { | ||
|
|
||
Oops, something went wrong.
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.
These changes will need to be removed