Skip to content

Commit 3760458

Browse files
committed
Add Static Stories Llama CI
1 parent a5c7609 commit 3760458

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

.ci/scripts/setup-stories-llama.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -ex
9+
10+
# Download and prepare stories llama model artifacts
11+
prepare_model_artifacts() {
12+
echo "Preparing stories model artifacts"
13+
wget -O stories110M.pt "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.pt"
14+
wget -O tokenizer.model "https://raw.githubusercontent.com/karpathy/llama2.c/master/tokenizer.model"
15+
echo '{"dim": 768, "multiple_of": 32, "n_heads": 12, "n_layers": 12, "norm_eps": 1e-05, "vocab_size": 32000}' > params.json
16+
}
17+
18+
prepare_model_artifacts

.github/workflows/pull.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,31 @@ jobs:
440440
# Test llama2
441441
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh -model stories110M -build_tool "${BUILD_TOOL}" -mode "${MODE}" -dtype "${DTYPE}" -pt2e_quantize "${PT2E_QUANTIZE}"
442442
443+
test-static-llama-runner-qnn-linux:
444+
name: test-static-llama-runner-qnn-linux
445+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
446+
strategy:
447+
fail-fast: false
448+
with:
449+
runner: linux.2xlarge
450+
docker-image: executorch-ubuntu-22.04-qnn-sdk
451+
submodules: 'true'
452+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
453+
timeout: 900
454+
script: |
455+
# The generic Linux job chooses to use base env, not the one setup by the image
456+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
457+
conda activate "${CONDA_ENV}"
458+
459+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
460+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
461+
462+
# Retrieve 110M Stories Llama Artifacts
463+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-stories-llama.sh
464+
465+
# Test static llama stories110m
466+
PYTHON_EXECUTABLE=python backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_stories_single_llama --model SM8650 --build_folder build-android/ --executorch_root . --artifact_dir . --compile_only"
467+
443468
test-qnn-models-linux:
444469
name: test-qnn-models-linux
445470
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,8 +3586,6 @@ def test_stories_single_llama(self):
35863586
self.artifact_dir,
35873587
"--build_folder",
35883588
self.build_folder,
3589-
"--device",
3590-
self.device,
35913589
"--model",
35923590
self.model,
35933591
"--checkpoint",
@@ -3610,7 +3608,17 @@ def test_stories_single_llama(self):
36103608
"0",
36113609
"--llama_model",
36123610
"stories110m",
3611+
"--model_mode",
3612+
"hybrid",
3613+
"--prefill_seq_len",
3614+
"32",
3615+
"--kv_seq_len",
3616+
"128",
36133617
]
3618+
if self.compile_only:
3619+
cmds.extend(["--compile_only"])
3620+
else:
3621+
cmds.extend(["--device", self.device])
36143622
if self.host:
36153623
cmds.extend(["--host", self.host])
36163624

@@ -3623,8 +3631,11 @@ def test_stories_single_llama(self):
36233631
if "Error" in msg:
36243632
self.fail(msg["Error"])
36253633
else:
3626-
model_out = msg["result"][0]
3627-
self.assertTrue(model_out.startswith(golden_start_with))
3634+
if not self.compile_only:
3635+
model_out = msg["result"][0]
3636+
self.assertTrue(model_out.startswith(golden_start_with))
3637+
pte_size = msg["pte_size"]
3638+
self.assertLessEqual(pte_size, 130000000)
36283639

36293640
@unittest.skip("dynamic shape inputs appear in recent torch.export.export")
36303641
def test_mobilebert(self):
@@ -3853,6 +3864,8 @@ def setup_environment():
38533864
TestQNN.shared_buffer = args.shared_buffer
38543865
TestQNN.enable_x86_64 = args.enable_x86_64
38553866
TestQNN.dump_intermediate_outputs = args.dump_intermediate_outputs
3867+
TestQNN.compile_only = args.compile_only
3868+
38563869
return sys.argv[:1] + ns_args
38573870

38583871

backends/qualcomm/tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class TestQNN(unittest.TestCase):
131131
use_16a4w: str = "16a4w"
132132
shared_buffer: bool = False
133133
enable_x86_64: bool = False
134+
compile_only: bool = False
134135

135136
def _assert_outputs_equal(self, model_output, ref_output):
136137
self.assertTrue(len(ref_output) == len(model_output))

examples/qualcomm/oss_scripts/llama/llama.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,14 @@ def post_process():
804804
outputs.append(f.read())
805805

806806
adb.pull(output_path=args.artifact, callback=post_process)
807-
808807
if args.ip and args.port != -1:
808+
pte_size = os.path.getsize(pte_path)
809809
with Client((args.ip, args.port)) as conn:
810810
conn.send(
811811
json.dumps(
812812
{
813813
"result": outputs,
814+
"pte_size": pte_size,
814815
}
815816
)
816817
)
@@ -1007,6 +1008,18 @@ def main():
10071008
)
10081009
else:
10091010
logging.warning("Quant attributes of the logit is None.")
1011+
1012+
if args.ip and args.port != -1:
1013+
pte_path = f"{args.artifact}/{pte_filename}.pte"
1014+
pte_size = os.path.getsize(pte_path)
1015+
with Client((args.ip, args.port)) as conn:
1016+
conn.send(
1017+
json.dumps(
1018+
{
1019+
"pte_size": pte_size,
1020+
}
1021+
)
1022+
)
10101023
exit(f"Finish compile_only and save to {args.artifact}")
10111024

10121025
try:

0 commit comments

Comments
 (0)