Skip to content

Add buck build for static llama runner #6950

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
Nov 21, 2024
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
8 changes: 8 additions & 0 deletions examples/qualcomm/oss_scripts/llama3_2/TARGETS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Any targets that should be shared between fbcode and xplat must be defined in
# targets.bzl. This file can contain xplat-only targets.

load(":targets.bzl", "define_common_targets")

oncall("executorch")

define_common_targets()
10 changes: 6 additions & 4 deletions examples/qualcomm/oss_scripts/llama3_2/runner/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ Runner::Runner(
const std::vector<std::string>& models_path,
const std::string& tokenizer_path,
const float temperature)
: tokenizer_path_(tokenizer_path),
temperature_(temperature),
n_bos_(1),
: n_bos_(1),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shewu-quic can you take a look and see if the change in the runner makes sense?

n_eos_(1),
vocab_size_(QNN_LLAMA3_2_LOGITS),
max_seq_len_(QNN_LLAMA3_2_SEQLEN),
tokenizer_path_(tokenizer_path),
temperature_(temperature),
stats_({}) {
for (size_t i = 0; i < models_path.size(); ++i) {
modules_.push_back(std::make_shared<Module>(
Expand All @@ -58,7 +58,9 @@ Runner::Runner(
ET_LOG(Info, "creating runner: tokenizer_path=%s", tokenizer_path_.c_str());

tokenizer_ = example::get_tiktoken_for_llama();
tokenizer_->load(tokenizer_path_);
Error err = tokenizer_->load(tokenizer_path_);
ET_CHECK_MSG(
err == Error::Ok, "failed to load tokenizer %s", tokenizer_path_.c_str());
eos_id_.insert(tokenizer_->encode("<|eot_id|>", 0, 0).get()[0]);
bos_id_ = tokenizer_->bos_tok();
eos_id_.insert(tokenizer_->eos_tok());
Expand Down
53 changes: 53 additions & 0 deletions examples/qualcomm/oss_scripts/llama3_2/targets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_oss_build_kwargs", "runtime")
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")

def define_common_targets():
runtime.cxx_library(
name = "runner_lib",
srcs = glob(
[
"runner/*.cpp",
],
),
exported_headers = glob([
"runner/*.h",
]),
compiler_flags = [
"-Wno-global-constructors",
"-Wunused-command-line-argument",
],
deps = [
"//executorch/extension/llm/runner:stats",
"//executorch/extension/tensor:tensor",
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
],
exported_deps = [
"//executorch/extension/module:module",
"//executorch/extension/llm/sampler:sampler",
"//executorch/examples/models/llama/tokenizer:tiktoken",
"//executorch/extension/evalue_util:print_evalue",
"//executorch/backends/qualcomm/runtime:runtime",
],
external_deps = [
"gflags",
],
**get_oss_build_kwargs()
)

runtime.cxx_binary(
name = "qnn_llama3_2_runner",
srcs = [
"qnn_llama3_2_runner.cpp",
],
compiler_flags = [
"-Wno-global-constructors",
],
deps = [
":runner_lib",
"//executorch/extension/threadpool:threadpool", # this depeneency shouldn't be needed. But it fails to build..
],
external_deps = [
"gflags",
],
**get_oss_build_kwargs()
)
Loading