Skip to content

Commit 1cbd80f

Browse files
authored
examples : support encoder-decoder models in the simple example (#16002)
Signed-off-by: Jie Fu <[email protected]>
1 parent 85286f3 commit 1cbd80f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

examples/simple/simple.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ int main(int argc, char ** argv) {
145145

146146
llama_batch batch = llama_batch_get_one(prompt_tokens.data(), prompt_tokens.size());
147147

148+
if (llama_model_has_encoder(model)) {
149+
if (llama_encode(ctx, batch)) {
150+
fprintf(stderr, "%s : failed to eval\n", __func__);
151+
return 1;
152+
}
153+
154+
llama_token decoder_start_token_id = llama_model_decoder_start_token(model);
155+
if (decoder_start_token_id == LLAMA_TOKEN_NULL) {
156+
decoder_start_token_id = llama_vocab_bos(vocab);
157+
}
158+
159+
batch = llama_batch_get_one(&decoder_start_token_id, 1);
160+
}
161+
148162
// main loop
149163

150164
const auto t_main_start = ggml_time_us();

0 commit comments

Comments
 (0)