mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-01-05 02:24:53 +01:00
06943a69f6
* ggml : move rope type enum to ggml.h
This commit moves the `llama_rope_type` enum from `llama.h` to
`ggml.h` and changes its name to `ggml_rope_type`.
The motivation for this change is to address the TODO in `llama.h` and
use the enum in ggml.
Note: This commit does not change the `mode` parameter to be of type
`enum ggml_rope_type`. The name `mode` and its usage suggest that it
might be more generic and possibly used as a bit field for multiple
flags. Further investigation/discussion may be needed to determine
if `mode` should be restricted to RoPE types.
* squash! ggml : move rope type enum to ggml.h
This commit removes GGML_ROPE_TYPE_NONE and GGML_ROPE_TYPE_GLM from
ggml.h, and back the llama_rope_type enum.
I've kept the assert for GGML_ROPE_TYPE_GLM as I'm not sure if it is
safe to remove it yet.
* squash! ggml : move rope type enum to ggml.h
This commit removes the enum ggml_rope_type from ggml.h and replaces it
with a define (GGML_ROPE_TYPE_NEOX). This define is used in the code to
check if the mode is set to GPT-NeoX. Also the enum llama_rope_type has
been updated to reflect this change.
* squash! ggml : move rope type enum to ggml.h
This commit contains a suggestion enable the GGML_ROPE_TYPE_NEOX
macro/define to be passed to the shader compiler.
* squash! ggml : move rope type enum to ggml.h
This commit fixes the editorconfig-checker warnings.
* squash! ggml : move rope type enum to ggml.h
Update comment for ggml_rope function.
* Revert "squash! ggml : move rope type enum to ggml.h"
This reverts commit 6261222bd0
.
* squash! ggml : move rope type enum to ggml.h
Add GGML_ROPE_TYPE_NEOX to rope_common.comp.
* remove extra line
---------
Co-authored-by: slaren <slarengh@gmail.com>
74 lines
2.8 KiB
Plaintext
74 lines
2.8 KiB
Plaintext
#version 450
|
|
|
|
#include "rope_common.comp"
|
|
|
|
layout(binding = 0) buffer restrict readonly tensorInA { float inA[]; };
|
|
layout(binding = 1) buffer restrict readonly tensorInB { int inB[]; };
|
|
layout(binding = 2) buffer restrict writeonly tensorOut { float out_[]; };
|
|
|
|
void main() {
|
|
const uint i3 = gl_WorkGroupID.z;
|
|
const uint i2 = gl_WorkGroupID.y;
|
|
const uint i1 = gl_WorkGroupID.x;
|
|
|
|
const bool is_neox = (pcs.mode & GGML_ROPE_TYPE_NEOX) != 0;
|
|
|
|
float corr_dims[2];
|
|
rope_yarn_corr_dims(pcs.n_dims, pcs.n_ctx_orig, pcs.freq_base, pcs.beta_fast, pcs.beta_slow, corr_dims);
|
|
|
|
const float theta_scale = pow(pcs.freq_base, -2.0/pcs.n_dims);
|
|
|
|
const int p = inB[pcs.inBOff + i2];
|
|
|
|
float theta = float(p);
|
|
|
|
if (!is_neox) {
|
|
for (uint i0 = 0; i0 < pcs.ne0; i0 += 2) {
|
|
float cos_theta, sin_theta;
|
|
rope_yarn(theta, pcs.freq_scale, corr_dims, i0, pcs.ext_factor, pcs.attn_factor, cos_theta, sin_theta);
|
|
|
|
theta *= theta_scale;
|
|
|
|
const uint src = uint((i3*pcs.nb03 + i2*pcs.nb02 + i1*pcs.nb01 + i0*pcs.nb00) / 4) + pcs.inAOff; // Based from in
|
|
const uint dst_data = uint((i3*pcs.nb3 + i2*pcs.nb2 + i1*pcs.nb1 + i0*pcs.nb0) / 4) + pcs.outOff; // Based from out_
|
|
|
|
const float x0 = inA[src];
|
|
const float x1 = inA[src+1];
|
|
|
|
out_[dst_data] = x0*cos_theta - x1*sin_theta;
|
|
out_[dst_data+1] = x0*sin_theta + x1*cos_theta;
|
|
}
|
|
} else {
|
|
const float inv_ndims = -1.f/pcs.n_dims;
|
|
for (uint ic = 0; ic < pcs.n_dims; ic += 2) {
|
|
const uint cur_rot = ic;
|
|
|
|
float cos_theta, sin_theta;
|
|
rope_yarn(theta, pcs.freq_scale, corr_dims, cur_rot, pcs.ext_factor, pcs.attn_factor, cos_theta, sin_theta);
|
|
|
|
theta *= theta_scale;
|
|
|
|
const uint i0 = ic/2;
|
|
|
|
const uint src = uint((i3*pcs.nb03 + i2*pcs.nb02 + i1*pcs.nb01 + i0*pcs.nb00) / 4) + pcs.inAOff; // Based from in
|
|
const uint dst_data = uint((i3*pcs.nb3 + i2*pcs.nb2 + i1*pcs.nb1 + i0*pcs.nb0) / 4) + pcs.outOff; // Based from out_
|
|
|
|
const float x0 = inA[src];
|
|
const float x1 = inA[src+pcs.n_dims/2];
|
|
|
|
out_[dst_data] = x0*cos_theta - x1*sin_theta;
|
|
out_[dst_data+pcs.n_dims/2] = x0*sin_theta + x1*cos_theta;
|
|
}
|
|
|
|
for (uint ic = pcs.n_dims; ic < pcs.ne0; ic += 2) {
|
|
const uint i0 = ic;
|
|
|
|
const uint src = uint((i3*pcs.nb03 + i2*pcs.nb02 + i1*pcs.nb01 + i0*pcs.nb00) / 4) + pcs.inAOff; // Based from in
|
|
const uint dst_data = uint((i3*pcs.nb3 + i2*pcs.nb2 + i1*pcs.nb1 + i0*pcs.nb0) / 4) + pcs.outOff; // Based from out_
|
|
|
|
out_[dst_data + 0] = inA[src + 0];
|
|
out_[dst_data + 1] = inA[src + 1];
|
|
}
|
|
}
|
|
}
|