Skip to content

Commit 86c3470

Browse files
authored
Revert "Qualcomm AI Engine Direct - improve llama3.2 3B TPS" (#21143)
Reverts #20903 This broke "pull / test-sqnr-static-llm-qnn-linux (smollm2_135m) / linux-job"
1 parent 53551c1 commit 86c3470

7 files changed

Lines changed: 16 additions & 33 deletions

File tree

backends/qualcomm/debugger/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
import subprocess
66
import tempfile
7+
from pathlib import Path
78
from typing import Sequence, Tuple
89

910
import executorch.backends.qualcomm.python.PyQnnManagerAdaptor as PyQnnManager
@@ -210,7 +211,7 @@ def __init__(
210211
self.adb = adb
211212
self.sample_input = sample_input
212213
self.build_folder = build_folder
213-
self.root = os.getcwd()
214+
self.root = str(Path(__file__).resolve().parents[3])
214215
self.config = {
215216
"backend_extension_config": {
216217
"backend_extensions": {

backends/qualcomm/tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ def forward(self, x):
15321532
class LargeTensorLinear(torch.nn.Module):
15331533
def __init__(self):
15341534
super().__init__()
1535-
hidden_dim = 16384
1535+
hidden_dim = 8192
15361536
self.linear1_1 = torch.nn.Linear(512, hidden_dim)
15371537
self.linear1_2 = torch.nn.Linear(512, hidden_dim)
15381538
self.linear1_3 = torch.nn.Linear(512, hidden_dim)

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10470,7 +10470,7 @@ def test_cli(self):
1047010470
cmds = [
1047110471
"python",
1047210472
"-m",
10473-
"executorch.examples.qualcomm.util_scripts.cli",
10473+
"examples.qualcomm.util_scripts.cli",
1047410474
"quantize",
1047510475
"--artifact",
1047610476
f"{tmp_dir}/relu.pt2",
@@ -10489,7 +10489,7 @@ def test_cli(self):
1048910489
cmds = [
1049010490
"python",
1049110491
"-m",
10492-
"executorch.examples.qualcomm.util_scripts.cli",
10492+
"examples.qualcomm.util_scripts.cli",
1049310493
"compile",
1049410494
"--artifact",
1049510495
f"{tmp_dir}/q_out/relu_quantized.pt2",
@@ -10507,7 +10507,7 @@ def test_cli(self):
1050710507
cmds = [
1050810508
"python",
1050910509
"-m",
10510-
"executorch.examples.qualcomm.util_scripts.cli",
10510+
"examples.qualcomm.util_scripts.cli",
1051110511
"execute",
1051210512
"--artifact",
1051310513
f"{tmp_dir}/c_out/relu_quantized.pte",
@@ -10551,7 +10551,7 @@ def test_cli_with_input_list_assignment(self):
1055110551
cmds = [
1055210552
"python",
1055310553
"-m",
10554-
"executorch.examples.qualcomm.util_scripts.cli",
10554+
"examples.qualcomm.util_scripts.cli",
1055510555
"quantize",
1055610556
"--artifact",
1055710557
f"{tmp_dir}/sub.pt2",
@@ -10570,7 +10570,7 @@ def test_cli_with_input_list_assignment(self):
1057010570
cmds = [
1057110571
"python",
1057210572
"-m",
10573-
"executorch.examples.qualcomm.util_scripts.cli",
10573+
"examples.qualcomm.util_scripts.cli",
1057410574
"compile",
1057510575
"--artifact",
1057610576
f"{tmp_dir}/q_out/sub_quantized.pt2",
@@ -10588,7 +10588,7 @@ def test_cli_with_input_list_assignment(self):
1058810588
cmds = [
1058910589
"python",
1059010590
"-m",
10591-
"executorch.examples.qualcomm.util_scripts.cli",
10591+
"examples.qualcomm.util_scripts.cli",
1059210592
"execute",
1059310593
"--artifact",
1059410594
f"{tmp_dir}/c_out/sub_quantized.pte",

examples/qualcomm/oss_scripts/llama/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class Llama3_2_3B_Instruct(LLMModelConfig):
281281
transform_weight = True
282282
# The Llama3_2 enabled should be instruct, however, Llama's tokenizer does not provide utility to apply chat template.
283283
instruct_model = False
284-
num_sharding = 3
284+
num_sharding = 4
285285
masked_softmax = False
286286
seq_mse_candidates = 0
287287
r1 = False

examples/qualcomm/oss_scripts/llama/model/static_llama.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ def forward(
730730
self.freqs_sin[input_pos][0] if self.use_kv_cache else self.freqs_sin
731731
)
732732

733-
hidden_states = self.tok_embeddings(tokens)
733+
hidden_states = self.embedding_scale_factor * self.tok_embeddings(tokens)
734734

735735
for ind, decoder_layer in enumerate(self.layers):
736736
k_caches = None
@@ -865,11 +865,7 @@ def forward(
865865
self.freqs_sin[input_pos][0] if self.use_kv_cache else self.freqs_sin
866866
)
867867

868-
hidden_states = (
869-
self.embedding_scale_factor * hidden_states
870-
if self.embedding_scale_factor != 1.0
871-
else hidden_states
872-
)
868+
hidden_states = self.embedding_scale_factor * hidden_states
873869

874870
for ind, decoder_layer in enumerate(self.layers):
875871
k_caches = None
@@ -1028,8 +1024,7 @@ def forward(
10281024
else self.local_freqs_sin
10291025
)
10301026

1031-
hidden_states = self.tok_embeddings(tokens)
1032-
1027+
hidden_states = self.embedding_scale_factor * self.tok_embeddings(tokens)
10331028
for ind, decoder_layer in enumerate(self.layers):
10341029
k_caches = None
10351030
v_caches = None

examples/qualcomm/oss_scripts/llama/wrappers/llm_wrappers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ def _prepare_model(self): # noqa: C901
241241
# Llama does x.to(float16) * w whilst Gemma3 is (x * w).to(float16)
242242
# See https://github.com/huggingface/transformers/pull/29402
243243
state_dict[k] = v.float() + torch.ones(v.shape, dtype=torch.float32)
244-
for k, v in state_dict.items():
245-
if "tok_embeddings.weight" == k:
246-
state_dict[k] = v.float() * self.model_args.embedding_scale_factor
247244
else:
248245
state_dict = torch.load(
249246
self.control_args.checkpoint,
@@ -469,7 +466,9 @@ def _tag_ios(self, node, fixed_point_type):
469466
(self.meta["get_ar_len"], self.meta["get_head_dim"] // 2),
470467
}
471468

472-
freq_op = {exir_ops.edge.aten.select.int, exir_ops.edge.aten.select_copy.int}
469+
freq_op = {
470+
exir_ops.edge.aten.select.int,
471+
}
473472
quant_io_type = None
474473

475474
if node.op == "placeholder":

examples/qualcomm/util_scripts/cli.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ def quantize(args):
166166
quant_dtype=quant_dtype,
167167
per_channel_conv=args.per_channel,
168168
per_channel_linear=args.per_row,
169-
per_channel_embedding=args.per_channel_embedding,
170-
act_symmetric=args.act_symmetric,
171169
act_observer=act_observer,
172170
backend=get_backend_type(args.backend),
173171
soc_model=args.soc_model,
@@ -501,16 +499,6 @@ def main():
501499
action="store_true",
502500
help="Use per_row encoding for operator linear.",
503501
)
504-
sub_quantize.add_argument(
505-
"--per_channel_embedding",
506-
action="store_true",
507-
help="Use per_channel encoding for operator embedding.",
508-
)
509-
sub_quantize.add_argument(
510-
"--act_symmetric",
511-
action="store_true",
512-
help="Use symmetric quantization for activations.",
513-
)
514502
sub_quantize.add_argument(
515503
"--activation_observer",
516504
type=str,

0 commit comments

Comments
 (0)