Skip to content

Commit

Permalink
ggml: update rope.c to print the embeddings tok 1
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bevenius <[email protected]>
  • Loading branch information
danbev committed Aug 2, 2024
1 parent ad8f82a commit 550bb2c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions fundamentals/ggml/src/rope.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ int main(int argc, char **argv) {
for (int j = 0; j < a->ne[1]; j++) {
// Loop over the embedding dimensions (128)
for (int k = 0; k < a->ne[0]; k++) {
// TODO: make the value a random value.
//float value = 1.0f + k;
float value = 0.0f + k;
ggml_set_f32_nd(a, k, j, i, 0, value);
}
Expand All @@ -53,9 +51,11 @@ int main(int argc, char **argv) {

// Print a few of the first dimensions so we can see that there is a rotation
// being performed. In this case we are printing the first 10 embeddings for
// the 4th token.
// the 2nd token. I'm not using token 0 as this will have a cosine value of 10
// and since value of 0 which will not perform any rotations for the position
// embeddings for that dimension.
for (int i = 0; i < 10; i++) {
printf("embedding for token 4, embedding dim %d: %f\n", i, ggml_get_f32_nd(a, i, 0, 4, 0));
printf("embedding for token 1, embedding dim %d: %f\n", i, ggml_get_f32_nd(a, i, 0, 1, 0));
}

// Set the positions manually (the b tensor parameter to ggml_rope_ext).
Expand Down Expand Up @@ -99,7 +99,6 @@ int main(int argc, char **argv) {
struct ggml_cgraph* c_graph = ggml_new_graph(ctx);
ggml_build_forward_expand(c_graph, s);


int n_threads = 4;
enum ggml_status status = ggml_graph_compute_with_ctx(ctx, c_graph, n_threads);
if (status != GGML_STATUS_SUCCESS) {
Expand All @@ -113,7 +112,7 @@ int main(int argc, char **argv) {
//printf("Rotation: %f\n", *(float *)((char *) s->data + 73728));

for (int i = 0; i < 10; i++) {
printf("embedding for token 4, embedding dim %d = %f\n", i, ggml_get_f32_nd(s, i, 0, 4, 0));
printf("embedding for token 1, embedding dim %d = %f\n", i, ggml_get_f32_nd(s, i, 0, 1, 0));
}

ggml_free(ctx);
Expand Down

0 comments on commit 550bb2c

Please sign in to comment.