Skip to content

Commit 715682d

Browse files
committed
add support T5 in swift example
1 parent f0678c5 commit 715682d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

examples/llama.swiftui/llama.cpp.swift/LibLlama.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ actor LlamaContext {
137137
let i = Int(i1)
138138
llama_batch_add(&batch, tokens_list[i], Int32(i), [0], false)
139139
}
140+
if llama_model_has_encoder(model) {
141+
if (llama_encode(context, batch)) != 0 {
142+
print("llama_encode() failed")
143+
}
144+
145+
var decoder_start_token_id = llama_model_decoder_start_token(model)
146+
if decoder_start_token_id == -1 {
147+
decoder_start_token_id = llama_token_bos(model)
148+
}
149+
llama_batch_clear(&batch)
150+
llama_batch_add(&batch, decoder_start_token_id, 0, [0], false)
151+
}
140152
batch.logits[Int(batch.n_tokens) - 1] = 1 // true
141153

142154
if llama_decode(context, batch) != 0 {

0 commit comments

Comments
 (0)