Skip to content

Commit 50b4ac3

Browse files
authored
Add buck build for static llama runner
Differential Revision: D66107963 Pull Request resolved: #6950
1 parent aa8d904 commit 50b4ac3

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Any targets that should be shared between fbcode and xplat must be defined in
2+
# targets.bzl. This file can contain xplat-only targets.
3+
4+
load(":targets.bzl", "define_common_targets")
5+
6+
oncall("executorch")
7+
8+
define_common_targets()

examples/qualcomm/oss_scripts/llama3_2/runner/runner.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ Runner::Runner(
4343
const std::vector<std::string>& models_path,
4444
const std::string& tokenizer_path,
4545
const float temperature)
46-
: tokenizer_path_(tokenizer_path),
47-
temperature_(temperature),
48-
n_bos_(1),
46+
: n_bos_(1),
4947
n_eos_(1),
5048
vocab_size_(QNN_LLAMA3_2_LOGITS),
5149
max_seq_len_(QNN_LLAMA3_2_SEQLEN),
50+
tokenizer_path_(tokenizer_path),
51+
temperature_(temperature),
5252
stats_({}) {
5353
for (size_t i = 0; i < models_path.size(); ++i) {
5454
modules_.push_back(std::make_shared<Module>(
@@ -58,7 +58,9 @@ Runner::Runner(
5858
ET_LOG(Info, "creating runner: tokenizer_path=%s", tokenizer_path_.c_str());
5959

6060
tokenizer_ = example::get_tiktoken_for_llama();
61-
tokenizer_->load(tokenizer_path_);
61+
Error err = tokenizer_->load(tokenizer_path_);
62+
ET_CHECK_MSG(
63+
err == Error::Ok, "failed to load tokenizer %s", tokenizer_path_.c_str());
6264
eos_id_.insert(tokenizer_->encode("<|eot_id|>", 0, 0).get()[0]);
6365
bos_id_ = tokenizer_->bos_tok();
6466
eos_id_.insert(tokenizer_->eos_tok());
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "get_oss_build_kwargs", "runtime")
2+
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")
3+
4+
def define_common_targets():
5+
runtime.cxx_library(
6+
name = "runner_lib",
7+
srcs = glob(
8+
[
9+
"runner/*.cpp",
10+
],
11+
),
12+
exported_headers = glob([
13+
"runner/*.h",
14+
]),
15+
compiler_flags = [
16+
"-Wno-global-constructors",
17+
"-Wunused-command-line-argument",
18+
],
19+
deps = [
20+
"//executorch/extension/llm/runner:stats",
21+
"//executorch/extension/tensor:tensor",
22+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
23+
],
24+
exported_deps = [
25+
"//executorch/extension/module:module",
26+
"//executorch/extension/llm/sampler:sampler",
27+
"//executorch/examples/models/llama/tokenizer:tiktoken",
28+
"//executorch/extension/evalue_util:print_evalue",
29+
"//executorch/backends/qualcomm/runtime:runtime",
30+
],
31+
external_deps = [
32+
"gflags",
33+
],
34+
**get_oss_build_kwargs()
35+
)
36+
37+
runtime.cxx_binary(
38+
name = "qnn_llama3_2_runner",
39+
srcs = [
40+
"qnn_llama3_2_runner.cpp",
41+
],
42+
compiler_flags = [
43+
"-Wno-global-constructors",
44+
],
45+
deps = [
46+
":runner_lib",
47+
"//executorch/extension/threadpool:threadpool", # this depeneency shouldn't be needed. But it fails to build..
48+
],
49+
external_deps = [
50+
"gflags",
51+
],
52+
**get_oss_build_kwargs()
53+
)

0 commit comments

Comments
 (0)