Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions extension/llm/runner/multimodal_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ Error MultimodalRunner::load() {
ET_LOG(Info, format, __VA_ARGS__); \
}

Error MultimodalRunner::prefill(std::vector<MultimodalInput>& inputs) {
if (!is_loaded()) {
ET_CHECK_OK_OR_RETURN_ERROR(load());
}
for (auto& input : inputs) {
ET_UNWRAP(multimodal_prefiller_->prefill(input, pos_));
}
return Error::Ok;
}

Error MultimodalRunner::generate(
const std::vector<MultimodalInput>& inputs,
const GenerationConfig& config,
Expand Down
9 changes: 9 additions & 0 deletions extension/llm/runner/multimodal_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ class ET_EXPERIMENTAL MultimodalRunner {
std::function<void(const std::string&)> token_callback = {},
std::function<void(const Stats&)> stats_callback = {});

/**
* Prefill multimodal inputs, for example to reload chat history.
* @param inputs A vector of MultimodalInput objects containing images and
* text.
* @return The error code. KV cache position is tracked internally in pos_.
*/
virtual ::executorch::runtime::Error prefill(
std::vector<MultimodalInput>& inputs);

inline void stop() {
text_token_generator_->stop();
}
Expand Down
Loading