-
Notifications
You must be signed in to change notification settings - Fork 100
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
Adding rwkv_eval_array operation #49
Conversation
} | ||
} | ||
return success; | ||
} |
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.
I propose following implementation:
bool rwkv_eval_sequence(struct rwkv_context * ctx, int32_t * token_sequence, uint32_t n_tokens, float * state_in, float * state_out, float * logits_out) {
RWKV_ASSERT_FALSE(n_tokens < 1, "Token count must be positive, got %d", n_tokens);
for (uint32_t i = 0; i < n_tokens; i++) {
if (!rwkv_eval(ctx, token_sequence[i], i == 0 ? state_in : state_out, state_out, logits_out)) {
return false;
}
}
return true;
}
- it looks simpler to me
- I would prefer to use term
sequence
instead ofarray
- token count made unsigned and with specific size (IDK what exactly
int
is in C and try to avoid it lol) - added token count correctness check, so users don't try to process zero tokens
Function signature in rwkv.h
should be changed accordingly.
@@ -43,6 +43,16 @@ extern "C" { | |||
// - logits_out: FP32 buffer of size rwkv_get_logits_buffer_element_count. This buffer will be written to. | |||
RWKV_API bool rwkv_eval(struct rwkv_context * ctx, int32_t token, float * state_in, float * state_out, float * logits_out); | |||
|
|||
// Evaluates the model for multiple token in an array | |||
// Returns false on any error. Error messages would be printed to stderr. | |||
// |
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.
// |
@@ -43,6 +43,16 @@ extern "C" { | |||
// - logits_out: FP32 buffer of size rwkv_get_logits_buffer_element_count. This buffer will be written to. | |||
RWKV_API bool rwkv_eval(struct rwkv_context * ctx, int32_t token, float * state_in, float * state_out, float * logits_out); | |||
|
|||
// Evaluates the model for multiple token in an array |
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.
// Evaluates the model for multiple token in an array | |
// Evaluates the model for a sequence of tokens. |
Please add test case for this new function into |
It would also be useful to add corresponding method to |
This is no longer necessary after #89 |
Adding a varient of
rwkv_eval
asrwkv_eval_array
for array operations.This is useful for X language bindings, where we can eval a larger context, without switching back and forth between X language and C lang context. (I am currently working on a nodejs binding)
Subsequently, if you do add support for "transformer" mode, this should use the "transformer" mode (i dun see the point to doing so though, for CPU eval)