char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e29acf74f
char/aliceai-t5-moe
1#version 450 2 3#extension GL_EXT_shader_16bit_storage : require 4 5layout (push_constant) uniform parameter 6{ 7 uint nb1; 8 uint dim; 9 uint max_period; 10} p; 11 12#include "types.glsl" 13 14#extension GL_EXT_control_flow_attributes : enable 15#define BLOCK_SIZE 256 16 17layout(local_size_x = BLOCK_SIZE, local_size_y = 1, local_size_z = 1) in; 18 19layout (binding = 0) readonly buffer X {A_TYPE data_a[];}; 20layout (binding = 1) writeonly buffer D {D_TYPE data_d[];}; 21 22void main() { 23 const uint i = gl_WorkGroupID.y; 24 const uint j = gl_GlobalInvocationID.x; 25 const uint d_offset = i * p.nb1; 26 27 const uint half_dim = p.dim / 2; 28 29 if (p.dim % 2 != 0 && j == half_dim) { 30 data_d[d_offset + 2 * half_dim] = 0.f; 31 } 32 33 if (j >= half_dim) { 34 return; 35 } 36 37 const float timestep = float(data_a[i]); 38 const float freq = float(exp(-log(p.max_period) * j / half_dim)); 39 const float arg = timestep * freq; 40 data_d[d_offset + j] = D_TYPE(cos(arg)); 41 data_d[d_offset + j + half_dim] = D_TYPE(sin(arg)); 42}