From 3490a17b15394c13e017cf414f777335598c5b51 Mon Sep 17 00:00:00 2001 From: xaedes Date: Mon, 6 Nov 2023 23:55:09 +0100 Subject: [PATCH] fix comments explaining the sinus sign in ggml_forward_rope --- ggml.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ggml.c b/ggml.c index 3e721677a..009d5b398 100644 --- a/ggml.c +++ b/ggml.c @@ -11043,8 +11043,9 @@ static void ggml_compute_forward_rope_f32( const bool is_neox = mode & 2; const bool is_glm = mode & 4; - // backward process uses derivative of cos and sin. - // derivative of cos is just cos, derivative of sin is -sin. + // backward process uses inverse rotation by cos and sin. + // cos and sin build a rotation matrix, where the inverse is the transpose. + // this essentially just switches the sign of sin. const float sin_sign = forward ? 1.0f : -1.0f; const int32_t * pos = (const int32_t *) src1->data; @@ -11199,8 +11200,9 @@ static void ggml_compute_forward_rope_f16( const bool is_neox = mode & 2; const bool is_glm = mode & 4; - // backward process uses derivative of cos and sin. - // derivative of cos is just cos, derivative of sin is -sin. + // backward process uses inverse rotation by cos and sin. + // cos and sin build a rotation matrix, where the inverse is the transpose. + // this essentially just switches the sign of sin. const float sin_sign = forward ? 1.0f : -1.0f; const int32_t * pos = (const int32_t *) src1->data;