File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,28 @@ Error TextLLMRunner::generate(
217
217
return Error::Ok;
218
218
}
219
219
220
+ Error TextLLMRunner::prefill (
221
+ const std::string& prompt,
222
+ const GenerationConfig& config) {
223
+ if (!is_loaded ()) {
224
+ ET_CHECK_OK_OR_RETURN_ERROR (load ());
225
+ }
226
+
227
+ ::tokenizers::Result<std::vector<uint64_t >> encode_res = tokenizer_->encode (
228
+ prompt,
229
+ /* bos=*/ config.num_bos ,
230
+ /* eos=*/ config.num_eos );
231
+
232
+ ET_CHECK_TK_OK_OR_RETURN_ERROR (
233
+ encode_res.error (), " Failed to encode prompt %s" , prompt.c_str ());
234
+
235
+ // encode the (string) prompt into tokens sequence
236
+ std::vector<uint64_t > prompt_tokens = encode_res.get ();
237
+ auto prefill_res = text_prefiller_->prefill (prompt_tokens, pos_);
238
+ ET_CHECK_OK_OR_RETURN_ERROR (prefill_res.error ());
239
+ return Error::Ok;
240
+ }
241
+
220
242
Error TextLLMRunner::warmup (const std::string& prompt, int32_t max_new_tokens) {
221
243
// Create a GenerationConfig for warmup
222
244
GenerationConfig config{
Original file line number Diff line number Diff line change @@ -101,6 +101,17 @@ class ET_EXPERIMENTAL TextLLMRunner : public IRunner {
101
101
std::function<void (const std::string&)> token_callback = {},
102
102
std::function<void (const Stats&)> stats_callback = {}) override ;
103
103
104
+ /* *
105
+ * Prefill text inputs, for example to reload chat history.
106
+ * @param prompt Text prompt to prefill.
107
+ * @param config Configuration parameters for text generation (e.g.,
108
+ * max_new_tokens, temperature)
109
+ * @return The error code. KV cache position is tracked internally in pos_.
110
+ */
111
+ ::executorch::runtime::Error prefill (
112
+ const std::string& prompt,
113
+ const GenerationConfig& config);
114
+
104
115
/* *
105
116
* @brief Warms up the model with a sample prompt
106
117
*
You can’t perform that action at this time.
0 commit comments