Skip to content

Support multiple prompts in the runner #9817

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

Merged
merged 1 commit into from
Apr 3, 2025
Merged
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
24 changes: 18 additions & 6 deletions examples/qualcomm/oss_scripts/llama/qnn_llama_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,22 @@ DEFINE_string(
"SmartMask");
DEFINE_int32(num_iters, 1, "total num of iterations to run.");

std::vector<std::string> CollectPrompts(int argc, char** argv) {
// Collect all prompts from command line, example usage:
// --prompt "prompt1" --prompt "prompt2" --prompt "prompt3"
std::vector<std::string> prompts;
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == "--prompt" && i + 1 < argc) {
prompts.push_back(argv[i + 1]);
i++; // Skip the next argument
}
}
return prompts;
}

int main(int argc, char** argv) {
std::vector<std::string> prompts = CollectPrompts(argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);

// create llama runner
example::Runner runner(
{FLAGS_model_path},
Expand All @@ -83,11 +96,10 @@ int main(int argc, char** argv) {
};
// generate tokens & store inference output
for (int i = 0; i < FLAGS_num_iters; i++) {
runner.generate(
FLAGS_seq_len,
FLAGS_prompt.c_str(),
FLAGS_system_prompt.c_str(),
callback);
for (const auto& prompt : prompts) {
runner.generate(
FLAGS_seq_len, prompt.c_str(), FLAGS_system_prompt.c_str(), callback);
}
}
fout.write(buf.data(), buf.size());
fout.close();
Expand Down
Loading